12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- from PyQt5.QtCore import pyqtSignal, QThread, QObject
- class ThreadManagerProto(QObject):
- threadStarted = pyqtSignal()
- threadFinished = pyqtSignal()
- def __init__(self, parent=None):
- QObject.__init__(self, parent=parent)
- self._thread = None
- self._threadQueue = []
- def cancelAll(self):
- self._threadQueue.clear()
- self._thread.wait()
- def currentJobStr(self):
- return ""
- def queueCount(self):
- return len(self._threadQueue)
- def hasActiveJobs(self):
- return bool(
- self._thread or self._threadQueue
- )
- class Thread(QThread):
- finished = pyqtSignal()
- def __init__(self, func, args=None, kwargs=None, parent=None):
- QThread.__init__(self, parent=parent)
- self._func = func
- self._args = args
- self._kwargs = kwargs
- self._result = None
- def result(self): return self._result
- def run(self):
- if self._args and self._kwargs:
- self._result = self._func(*self._args, **self._kwargs)
- elif self._args:
- self._result = self._func(*self._args)
- elif self._kwargs:
- self._result = self._func(**self._kwargs)
- else:
- self._result = self._func()
- self.finished.emit()
|