-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (43 loc) · 1.46 KB
/
main.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
# -*- coding: utf-8 -*-
# Time : 2021/1/24 17:53
# Author : LiaoKong
import sys
import ctypes
from functools import partial
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from quicker import Quicker
from utils import get_logger
import setting
log = get_logger(u'托盘')
def add_action(menu, name, connect_func, parent, icon=None):
if icon:
action = QAction(QIcon(icon), name, parent)
else:
action = QAction(name, parent)
action.triggered.connect(connect_func)
menu.addAction(action)
return action
def tray_clicked(tray, quicker, reason):
if reason is tray.Trigger:
quicker.set_visible()
if __name__ == '__main__':
log.info(u'=========启动Quicker=============')
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
app.setWindowIcon(QIcon('res/launch.png'))
# 属性任务栏图标
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('quicker')
tray = QSystemTrayIcon()
quicker = Quicker()
tray.setIcon(QIcon('res/launch.png'))
menu = QMenu()
tray.setContextMenu(menu)
add_action(menu, u'主界面', quicker.set_visible, app)
if setting.DEBUG:
add_action(menu, u'重载插件', quicker.reload_plugin, app)
add_action(menu, u'重载actions', quicker.reload_actions, app)
add_action(menu, u'退出', app.exit, app)
tray.activated.connect(partial(tray_clicked, tray, quicker))
tray.show()
sys.exit(app.exec_())