浏览代码

update thread handling

Patrick Schreiber 8 年之前
父节点
当前提交
b59514092a
共有 3 个文件被更改,包括 33 次插入4 次删除
  1. 1 1
      KCG/VERSION
  2. 31 2
      KCG/base/storage.py
  3. 1 1
      setup.py

+ 1 - 1
KCG/VERSION

@@ -1 +1 @@
-0.3.2.174.0407-beta
+0.3.2.175.0408-beta

+ 31 - 2
KCG/base/storage.py

@@ -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)

+ 1 - 1
setup.py

@@ -5,7 +5,7 @@ DESCRIPTION = "KCG KAPTURE Control Gui"
 
 setup(
     name='KCG',
-    version='0.3.2.174.0407-beta',
+    version='0.3.2.175.0408-beta',
     author='Patrick Schreiber',
     author_email='uldfk@student.kit.edu',
 #    license='GPL',