|
@@ -64,8 +64,19 @@ class ThreadStorage(object):
|
|
|
"""
|
|
|
del self._q_thread # start over
|
|
|
self._q_thread = QtCore.QThread()
|
|
|
+ self._q_thread.started.connect(self.__start)
|
|
|
self._threaded_object = threaded_object
|
|
|
|
|
|
+ def is_registered(self):
|
|
|
+ """
|
|
|
+ Check if a class for this thread is registered.
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ return not (self._threaded_object is None)
|
|
|
+
|
|
|
+ def __start(self):
|
|
|
+ self._start_method()
|
|
|
+
|
|
|
def start(self, method_to_run_in_thread):
|
|
|
"""
|
|
|
Move the class object to a QThread, connect the QThread.started signal to the given method of the
|
|
@@ -75,9 +86,11 @@ class ThreadStorage(object):
|
|
|
"""
|
|
|
self._threaded_object.moveToThread(self._q_thread)
|
|
|
if isinstance(method_to_run_in_thread, str):
|
|
|
- self._q_thread.started.connect(getattr(self._threaded_object, method_to_run_in_thread))
|
|
|
+ self._start_method = getattr(self._threaded_object, method_to_run_in_thread)
|
|
|
+ # self._q_thread.started.connect(getattr(self._threaded_object, method_to_run_in_thread))
|
|
|
else:
|
|
|
- self._q_thread.started.connect(method_to_run_in_thread)
|
|
|
+ self._start_method = method_to_run_in_thread
|
|
|
+ # self._q_thread.started.connect(method_to_run_in_thread)
|
|
|
self._q_thread.start()
|
|
|
self.running = True
|
|
|
|
|
@@ -123,3 +136,19 @@ class ThreadStorage(object):
|
|
|
getattr(self._threaded_object, signal).connect(slot)
|
|
|
else:
|
|
|
signal.connect(slot)
|
|
|
+
|
|
|
+ def disconnect(self, *args):
|
|
|
+ """
|
|
|
+ Disconnect the given signals
|
|
|
+ :param args: the signals to disconnect
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ for signal in args:
|
|
|
+ getattr(self._threaded_object, signal).disconnect()
|
|
|
+
|
|
|
+ def init(self, *args, **kwargs):
|
|
|
+ """
|
|
|
+ call the threaded objects init method (not __init__) with the passed arguments
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ self._threaded_object.init(*args, **kwargs)
|