-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstart_quickpanel.py
More file actions
executable file
·154 lines (134 loc) · 5.57 KB
/
start_quickpanel.py
File metadata and controls
executable file
·154 lines (134 loc) · 5.57 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
import sys
import logging
import os
from PyQt5.QtCore import QObject, pyqtSignal, QStandardPaths
from PyQt5.QtGui import QFont, QIcon, QKeySequence
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QPushButton, QLabel, QDialog, QSizePolicy, \
QDialogButtonBox, QVBoxLayout, QHBoxLayout, QAction, QMessageBox
import quickpanel_rc; quickpanel_rc
from besteam.utils.settings import Settings, _Settings
from besteam.utils.globalkey import GlobalKey
from besteam.im.quick_panel import QuickPanel
from tetrix import TetrixWindow
logger = logging.getLogger("quickpanel")
class SetKeyWidget(QPushButton):
editingFinished = pyqtSignal()
def __init__(self, parent = None):
QPushButton.__init__(self, parent)
self.setCheckable(True)
def keyPressEvent(self, event):
if self.isChecked() and event.text() != "":
self.setText(QKeySequence(event.key() | int(event.modifiers())).toString(QKeySequence.NativeText))
self.setChecked(False)
self.editingFinished.emit()
else:
QPushButton.keyPressEvent(self, event)
class ConfigureDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
self.lblKey = QLabel("Global Key:")
self.btnKey = SetKeyWidget(self)
self.btnKey.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.setLayout(QVBoxLayout())
layout1 = QHBoxLayout()
layout1.addWidget(self.lblKey)
layout1.addWidget(self.btnKey)
self.layout().addLayout(layout1)
self.layout().addStretch()
self.layout().addWidget(buttonBox)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)
def setGlobalKey(self, globalKeyName):
self.btnKey.setText(globalKeyName)
def getGlobalKey(self):
return self.btnKey.text()
class Platform(QObject):
def __init__(self):
QObject.__init__(self)
documentsLocation = QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)
self.databaseFile = os.path.join(documentsLocation, "quickpanel.db")
self._settings = _Settings(self.databaseFile)
self.globalKey = GlobalKey()
self.quickPanel = QuickPanel(self)
self.actionConfigure = QAction(QIcon(":/images/configure.png"), \
self.tr("&Configure"), self)
self.actionExit = QAction(QIcon(":/images/close.png"), \
self.tr("&Exit"), self)
self.trayIcon = QSystemTrayIcon(QIcon(":/images/angelfish.png"))
self.contextMenu = QMenu()
self.contextMenu.addAction(self.actionConfigure)
self.contextMenu.addAction(self.actionExit)
self.trayIcon.setContextMenu(self.contextMenu)
self.actionConfigure.triggered.connect(self.configure)
self.actionExit.triggered.connect(self.exit)
self.trayIcon.activated.connect(self.onTrayIconActivated)
def start(self):
self.loadSettings()
self.trayIcon.show()
self.quickPanel.initWidgets()
logger.info("QuickPanel is launched.")
self.quickPanel.addQuickAccessShortcut(self.tr("Tetrix"), \
QIcon(":/images/tetrix.png"), self.startTetrix)
self.quickPanel.addQuickAccessShortcut(self.tr("Hello"), \
QIcon(":/images/hello.png"), self.sayHello)
def startTetrix(self):
if getattr(self, "tetrixWindow", None) is None:
self.tetrixWindow = TetrixWindow()
self.tetrixWindow.show()
self.tetrixWindow.activateWindow()
def sayHello(self):
QMessageBox.information(None, self.tr("Say Hello."), \
self.tr("Hello, world!"))
def loadSettings(self):
settings = self.getSettings()
keyname = settings.value("globalkey", "Alt+`")
self.keyId = self.globalKey.addHotKey("actionToggleQuickPanel", keyname)
self.globalKey.catched.connect(self.quickPanel.toggle)
def saveSettings(self):
pass
def configure(self):
d = ConfigureDialog()
settings = self.getSettings()
keyname = settings.value("globalkey", "Alt+`")
d.setGlobalKey(keyname)
self.globalKey.removeHotKey(self.keyId)
try:
result = getattr(d, "exec")()
except AttributeError:
result = getattr(d, "exec_")()
if result == QDialog.Accepted:
keyname = d.getGlobalKey()
settings.setValue("globalkey", keyname)
self.keyId = self.globalKey.addHotKey("actionToggleQuickPanel", keyname)
def exit(self):
self.quickPanel.finalize()
self.saveSettings()
self.globalKey.close()
logger.info("QuickPanel is shutting down.")
QApplication.instance().quit()
def onTrayIconActivated(self, reason):
if reason == QSystemTrayIcon.Trigger:
self.quickPanel.toggle()
def getSettings(self):
return Settings(self._settings)
def main():
app = QApplication(sys.argv)
if sys.platform == "win32":
app.setFont(QFont("Tahoma", 9))
app.setOrganizationName("Besteam")
app.setOrganizationDomain("besteam.im")
app.setApplicationName("QuickPanel")
app.setQuitOnLastWindowClosed(False)
app.setWindowIcon(QIcon(":/images/angelfish.png"))
#app.setStyle(QStyleFactory.create("qtcurve"))
platform = Platform()
platform.start()
try:
getattr(app, "exec")()
except AttributeError:
getattr(app, "exec_")()
if __name__ == "__main__":
logging.basicConfig(level = logging.DEBUG)
main()