blob: da1b18a7efa2eda745235d70dd58294ec5017c4a (
plain)
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
|
class Driver(QtCore.QObject):
update_ui = QtCore.pyqtSignal()
queue_emptied = QtCore.pyqtSignal()
initialized = Bool()
def check_busy(self):
"""
Handles writing of busy to False.
Must always write to busy.
"""
if self.is_busy():
time.sleep(0.01) # don't loop like crazy
self.busy.write(True)
elif self.enqueued.read():
time.sleep(0.1) # don't loop like crazy
self.busy.write(True)
else:
self.busy.write(False)
self.update_ui.emit()
@QtCore.pyqtSlot(str, list)
def dequeue(self, method, inputs):
"""
Slot to accept enqueued commands from main thread.
Method passed as qstring, inputs as list of [args, kwargs].
Calls own method with arguments from inputs.
"""
self.update_ui.emit()
method = str(method) # method passed as qstring
args, kwargs = inputs
if g.debug.read():
print(self.name, ' dequeue:', method, inputs, self.busy.read())
self.enqueued.pop()
getattr(self, method)(*args, **kwargs)
if not self.enqueued.read():
self.queue_emptied.emit()
self.check_busy()
def is_busy(self):
return False
|