-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsystemTrayIcon.py
97 lines (68 loc) · 3.63 KB
/
systemTrayIcon.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from PySide2.QtWidgets import QMenu, QMessageBox
from PySide2 import QtWidgets, QtCore
from PySide2.QtGui import QCursor
from ContextMenu import ContextMenu
from settings.pie_themes import tray_theme
# from main import suspend_app, resume_app, APP_SUSPENDED # Just to resolve undefined vars in vscode or any editors.
# # comment out when compiling.
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, GAR, parent=None):
# Qt stuff
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
self.activated.connect(self.showMenuOnTrigger)
self.GAR = GAR
self.suspend_app = GAR(True)['suspend_app']
self.resume_app = GAR(True)['resume_app']
def make_context(self):
# menu = QtWidgets.QMenu(parent)
self.contextMenu = None
main_menu = ContextMenu(self.parent())
# ------------ Main context menu--------------------
# To quit the app
exit_app = main_menu.add_action("Exit Pie Menus", custom_css=tray_theme.danger)
exit_app.triggered.connect(self.exit)
main_menu.addSeparator()
settings = main_menu.add_action("Settings")
settings.triggered.connect(lambda: self.showDialog("The settings page will be soon available, as of now please edit JSON if you can.", "Sorryyy"))
# ------------ /Main context menu--------------------
# ------------ suspend sub context menu--------------------
suspend_menu = ContextMenu("Suspend", main_menu)
if self.GAR()['APP_SUSPENDED']:
res_app = suspend_menu.add_action("Resume Pie Menus App")
res_app.triggered.connect(self.resume_app)
else:
sus_app = suspend_menu.add_action("Suspend Pie Menus App", custom_css=tray_theme.warning)
sus_app.triggered.connect(self.suspend_app)
# sus_app.triggered.connect(lambda: self.showDialog("Still in development", "Sorry"))
sus_profile = suspend_menu.add_action("Suspend current profile")
sus_profile.triggered.connect(lambda: self.showDialog("Still in dev", "Sorry"))
main_menu.addMenu(suspend_menu)
# ------------ /suspend sub context menu--------------------
main_menu.set_stock_css(tray_theme.QMenu)
self.contextMenu = main_menu
# Don't do the following line, animation problem and one right click does not work, see comments on end of this file
# self.setContextMenu(menu)
def showMenuOnTrigger(self, reason = None):
if reason == self.Context:
self.make_context() #recreate everytime, animation flicker problem
self.contextMenu.show_menu(showAnim=True, up_left=True)
def showDialog(self, msg, title):
msgBox = QMessageBox()
msgBox.setIcon(QMessageBox.Information)
msgBox.setText(msg)
msgBox.setWindowTitle(title)
# msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msgBox.setStandardButtons(QMessageBox.Ok)
msgBox.setDefaultButton(QMessageBox.Ok)
msgBox.buttonClicked.connect(self.msgButtonClick)
returnValue = msgBox.exec()
if returnValue == QMessageBox.Ok:
print('OK clicked')
def msgButtonClick(self, event):
print("Button clicked is:", event.text())
def exit(self):
QtCore.QCoreApplication.exit()
# NOTE: do not set self.setcontextmenu(), animation just flicker
# also trigerred.connect, reason -> trigerred: exec_ has to be called twice
# don't know, clicking right clik once just dont work, I have to double right click.
# Also Context menu has to recreated from scratch, because animation flickers.