-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapstray.py
47 lines (36 loc) · 2.13 KB
/
capstray.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
import ctypes
from time import sleep
from PyQt5.QtCore import QThread
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon
def bytes_to_icon(b: bytes) -> QIcon:
p = QPixmap()
p.loadFromData(b)
return QIcon(p)
dll = ctypes.WinDLL('User32.dll')
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
icons = tuple(bytes_to_icon(b) for b in (
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00!\x00\x00\x00!\x08\x03\x00\x00\x00`:2]\x00\x00\x00\x04gAMA\x00\x00\xb1\x8f\x0b\xfca\x05\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x009PLTE\x00\x00\x00\x00\x00:\xb6\xff\xff:\x00f\xff\xff\xdb\x00:{\xff\xdb\x90\xff\xff\xff\x90\xdb\xff\xff\xb6ff\x00:\xdb\xff\xff:\x00:\xff\xff\xb6f::\xb6f\x00\x90::\x90:\x00\x00f\xb6\xdb\x99\xca\xd1\x00\x00\x00^IDAT8\xcb\xe5\xd3;\x12\xc0 \x08@A\x15Q\x14\xbf\xdc\xff\xb0a\xe2\x01\xach\x92W\xef\x0cP\xe0\xf2-\xf7M1\xe7to"b\'N\xbd\xf7Z+\x11\x19\x89R\xca\xd9\xc3{o$RJ\x00\x10B\x881\xae\xb5\x8c\x84.\x81\x88\xcc\xac\xb4\xb5f$t\xfc\xde[OU7\xc60\x12?\xf9\xa8k\x0f\xe3\xfe\x1d;+\xfa\xca\x90\x00\x00\x00\x00IEND\xaeB`\x82',
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x19\x00\x00\x00\x16\x01\x03\x00\x00\x00\x0fq\xa5\xf5\x00\x00\x00\x04gAMA\x00\x00\xb1\x8f\x0b\xfca\x05\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\x06PLTE\xed\x1c$\xff\xff\xff\x85C\xd5k\x00\x00\x00NIDAT\x08\xd75\xcc\xb1\r\x800\x14\x03Q#\n\x9aHl\x10F\xf9\xa3\xc5R\x16K\xc7\x1a\x8c\x902\x05\xc2X"\\\xf1\xca\x83\x9a\x08\xb1\xfc &\x0f\x0e\x93\xcc\x9dv\x93\xcd\xc8\x9b\t\xd3c5\xa5\x12\x17\x16\xa2}`B\xb8\xaa>95<\x95\xf8\x02Ao*\xfdt\xd8\x17\xba\x00\x00\x00\x00IEND\xaeB`\x82'))
init = dll.GetKeyState(20) % 2
tray = QSystemTrayIcon(icons[init])
class Poll(QThread):
def run(self):
while True:
flag = dll.GetKeyState(20) % 2
if flag != self.flag:
self.flag = flag
tray.setIcon(icons[flag])
sleep(.1)
poll = Poll()
poll.flag = init
poll.start()
# menu = QMenu()
# quit = menu.addAction('quit')
# quit.triggered.connect(app.quit)
# tray.setContextMenu(menu)
tray.activated.connect(app.quit)
tray.show()
if __name__ == '__main__':
app.exec_()