-
Notifications
You must be signed in to change notification settings - Fork 4
/
autochannelchattab.py
75 lines (62 loc) · 2.39 KB
/
autochannelchattab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from ts3plugin import ts3plugin
import ts3defines
from PythonQt.QtGui import *
from PythonQt.QtCore import *
class autoChannelChatTab(ts3plugin):
name = "AutoChannelChatTab"
apiVersion = 21
requestAutoload = True
version = "1.0.1"
author = "Thomas \"PLuS\" Pathmann"
description = "Automatically activates the channel chat (tabindex 1, so if you change order, it won't work as expected) tab when the server connection tab is changed"
offersConfigure = False
commandKeyword = ""
infoTitle = None
menuItems = []
hotkeys = []
debug = False
toggle = True
def __init__(self):
self.chattab = None
self.retrieveWidgets()
def retrieveWidgets(self):
process = False
if not hasattr(self, "main"):
qapp = QApplication.instance()
for w in qapp.topLevelWidgets():
if "MainWindow" in str(type(w)):
self.main = w
process = True
else:
process = True
if process and not hasattr(self, "splitter"):
process = False
for c in self.main.children():
if type(c) is QSplitter:
self.splitter = c
process = True
break
if process and (not hasattr(self, "chat")):
process = False
for c in self.splitter.children():
if c.objectName == "MainWindowChatWidget":
self.chat = c
process = True
if process and not self.chattab:
for c in self.chat.children():
if c.objectName == "ChatTabWidget":
self.chattab = c
return
if not process:
#it's possible that this plugin is started before the client's UI is loaded
QTimer.singleShot(300, self.retrieveWidgets)
def activateChannelChat(self):
if self.chattab:
if self.chattab.count < 2:
#it's a new schid, so in most cases chattabs not yet available
QTimer.singleShot(300, lambda: self.onConnectStatusChangeEvent(schid))
else:
self.chattab.setCurrentIndex(1)
def onConnectStatusChangeEvent(self, schid, newStatus, errorNumber):
if newStatus == ts3defines.ConnectStatus.STATUS_CONNECTION_ESTABLISHED:
self.activateChannelChat()