Source code for cgl.ui.background
from PySide6 import QtCore
BACKGROUND_THREADS = []
THREAD_MANAGER = None
[docs]
class BackGroundResult(object):
def __init__(self, data):
self.data = data
[docs]
class BackgroundThread(QtCore.QThread):
result_complete = QtCore.Signal(object)
delete_able = QtCore.Signal(object)
def __init__(self, p, *args, **kwargs):
QtCore.QThread.__init__(self)
self.process = p
self.args = args
self.kwargs = kwargs
BACKGROUND_THREADS.append(self) # protect against the GC
self.finished.connect(self.cleanup)
[docs]
def cleanup(self):
BACKGROUND_THREADS.remove(self) # im done I can die now
self.deleteLater()
[docs]
def run(self):
data = self.process(*self.args, **self.kwargs)
self.result_complete.emit(BackGroundResult(data))
[docs]
def process(notify, method, *args, **kwargs):
bg = BackgroundThread(method, *args, **kwargs)
if notify:
bg.result_complete.connect(notify)
bg.start()