Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- from PySide.QtCore import *
- from PySide.QtGui import *
- import sys
- import time
- class PrintSignal(QObject):
- printer = Signal(str)
- class OtherProcess(QThread):
- signal = PrintSignal()
- def __init__(self):
- super(OtherProcess, self).__init__()
- def run(self):
- v = 0
- while True:
- time.sleep(1)
- v += 1
- self.signal.printer.emit("Hello %d from thread !" % v)
- if v > 9:
- break
- self.signal.printer.emit("Bye")
- class UI(QWidget):
- def __init__(self):
- super(UI, self).__init__()
- vl = QVBoxLayout()
- self.console = QTextBrowser()
- vl.addWidget(self.console)
- self.setLayout(vl)
- self.otherProcess = OtherProcess()
- self.otherProcess.signal.printer.connect(self.console.append)
- self.otherProcess.start()
- def closeEvent(self, *args, **kwargs):
- # Wainitng for thread to commplete his work
- self.otherProcess.wait()
- app = QApplication(sys.argv)
- ui = UI()
- ui.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement