I am trying to run the PyQT GUI on my python application and I tried to split it into 2 threads so that the GUI was responsive while my main loop was running, but I couldn’t get it going. Perhaps I do not understand. Here is what I tried:
My Window and Worker thread is defined as follows:
class Window(QWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) self.thread = Worker() start = QPushButton("Start", self) QObject.connect(start, SIGNAL("clicked()"), MAIN_WORLD.begin) hbox = QVBoxLayout(self) hbox.addStretch(4) class Worker(QThread): def __init__(self, parent = None): QThread.__init__(self, parent) if __name__ == '__main__': MAIN_WORLD = World() app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())
which seems to be very close to online examples. My World class starts a loop that is endless as soon as the user clicks the Start button until he clicks again. Here is part of his definition.
class World(QThread): def __init__(self, parent = None): QThread.__init__(self, parent) self.currentlyRunning = False //snip def begin(self): if self.currentlyRunning: self.currentlyRunning = False else: self.currentlyRunning = True self.MethodThatDoesUsefulStuff()
edit: I noticed that I am not using my workflow. How to create my thread as a workflow?
source share