Created
August 26, 2011 14:37
-
-
Save mhubig/1173536 to your computer and use it in GitHub Desktop.
Python Thread example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Thread(QThread): | |
dataReady = Signal(object) | |
def run(self): | |
while True: | |
self.data = slowly_produce_data() | |
# this will add a ref to self.data and avoid the destruction | |
self.dataReady.emit(self.data) | |
class Widget(QWidget): | |
def __init__(self): | |
self.thread = Thread() | |
self.thread.dataReady.connect(self.get_data, Qt.QueuedConnection) | |
self.thread.start() | |
def get_data(self, data): | |
self.data = data | |
def paintEvent(self, event): | |
paint_somehow(self.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment