forked from getavalon/setup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys-tray_test.py
121 lines (107 loc) · 4.83 KB
/
sys-tray_test.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
import sys
import textwrap
from PyQt5 import QtCore, QtGui, QtWidgets
menu_layout_dict = {'Install avalon plugins': "action",
'Plugins': {
'Avalon Core': [
'Config core',
'Create new project',
None,
'Save database',
],
'&Avalon Users': [
'Config User',
'Cre&ate new user',
],
'Avalon Workfiles': [
'Config Workfiles',
],
'Pyblish': [
'Config Pyblish',
'Create new micro-plugin',
None,
'Micro-plugins manager'
],
'Pipeline': [
'Config pipeline',
'Create new template',
None,
'Templates manager'
],
'CG-wire': [
'Config CG-wire',
None,
'Pull database',
'Push database'
]
},
'Minimalize': "action",
#'Close': "action"
}
# print(menu_layout_dict)
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
tray = QtWidgets.QSystemTrayIcon( icon, parent)
# print(tray)
tray.setToolTip("Avalon Launcher")
menu = QtWidgets.QMenu(parent)
menu.setProperty('menu', 'on')
menu.setStyleSheet(textwrap.dedent('''
QWidget[submenu=on] {
background-color: #a6ceff;
}
QWidget[menu=on] {
background-color: #84bbdc;
}
'''
)
)
for key, value in menu_layout_dict.items():
if value == 'action':
print(key, value)
menu.addSeparator()
insAvPl_Action = menu.addAction(key)
else:
avalon_plugins = menu.addMenu(key)
avalon_plugins.setProperty('submenu', 'on')
self.eventFilter(avalon_plugins, QtCore.QEvent.HoverMove)
for skey, svalue in value.items():
avalon_plugin = avalon_plugins.addMenu(skey)
avalon_plugin.setProperty('submenu', 'on')
print(skey, svalue)
# plugins_Menu = avalon_plugin.addMenu(skey)
for action in svalue:
if action == None:
avalon_plugin.addSeparator()
else:
plugins_Action = avalon_plugin.addAction(action)
exitAction = menu.addAction("Exit")
self.eventFilter(exitAction, QtCore.QEvent.HoverMove)
self.setContextMenu(menu)
menu.triggered.connect(self.exit)
def eventFilter(self, object, event):
print(self, object, event)
# if event.type() == QtCore.QEvent.MouseButtonPress:
# print("You pressed the button")
# return True
# #
if event == QtCore.QEvent.HoverMove:
print("C'mon! CLick-meeee!!!")
return True
def exit(self):
QtCore.QCoreApplication.exit()
def _sys_tray(image):
# code source: https://stackoverflow.com/questions/893984/pyqt-show-menu-in-a-system-tray-application - add answer PyQt5
#PyQt4 to PyQt5 version: https://stackoverflow.com/questions/20749819/pyqt5-failing-import-of-qtgui
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
trayIcon = SystemTrayIcon(QtGui.QIcon(image), w)
# menu =
trayIcon.show()
sys.exit(app.exec_())
if __name__ == '__main__':
avalon_core_icon = os.path.join(os.environ['AVALON_LAUNCHER'], "launcher", "res", "icon", "main.png")
print(avalon_core_icon)
_sys_tray(avalon_core_icon)