-
Notifications
You must be signed in to change notification settings - Fork 1
/
key_notifier.py
43 lines (33 loc) · 1.02 KB
/
key_notifier.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
from PyQt5.QtCore import QThread, QObject, pyqtSignal, pyqtSlot
import time
class KeyNotifier(QObject):
key_signal = pyqtSignal(int)
def __init__(self):
super().__init__()
self.keys = []
self.is_done = False
self.thread = QThread()
self.thread.daemon = True
# move the Worker object to the Thread object
# "push" self from the current thread to this thread
self.moveToThread(self.thread)
# Connect Thread started signal to Worker operational slot method
self.thread.started.connect(self.__work__)
def start(self):
"""
Start notifications.
"""
self.thread.start()
def add_key(self, key):
self.keys.append(key)
def rem_key(self, key):
self.keys.remove(key)
@pyqtSlot()
def __work__(self):
"""
A slot with no params.
"""
while not self.is_done:
for k in self.keys:
self.key_signal.emit(k)
time.sleep(0.05)