diff options
author | Blaise Thompson <blaise@untzag.com> | 2018-03-27 16:06:30 -0500 |
---|---|---|
committer | Blaise Thompson <blaise@untzag.com> | 2018-03-27 16:06:30 -0500 |
commit | 093ce016b23812d0aaf58c2b05c9d4189791e2a6 (patch) | |
tree | 125fb4613ebdb38d63d5f87a6d62eb8063118495 /acquisition/driver.py | |
parent | 8c9fc50d417809d7c5ad1b512f55c83307a83364 (diff) |
2018-03-27 16:06
Diffstat (limited to 'acquisition/driver.py')
-rw-r--r-- | acquisition/driver.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/acquisition/driver.py b/acquisition/driver.py new file mode 100644 index 0000000..da1b18a --- /dev/null +++ b/acquisition/driver.py @@ -0,0 +1,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 |