Want more features on Pastebin? Sign Up, it's FREE!
Guest

PyQt signals and threads (edit)

By: reclosedev on Feb 5th, 2012  |  syntax: Python  |  size: 0.78 KB  |  views: 77  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import time
  2. from PyQt4 import QtCore
  3.  
  4.  
  5. class A(QtCore.QObject):
  6.     mySignal = QtCore.pyqtSignal(str)
  7.     def __init__(self):
  8.         QtCore.QObject.__init__(self)
  9.         self.b = B(self)
  10.         self.b.start()
  11.  
  12.     def some_action(self):
  13.         self.mySignal.emit("Hello World")
  14.        
  15. class B(QtCore.QThread):
  16.     def __init__(self, creator):
  17.         QtCore.QThread.__init__(self)
  18.         self._creator = creator
  19.         self._creator.mySignal.connect(self.mySlot)
  20.  
  21.     def mySlot(self, str):
  22.         print str
  23.  
  24.     def run(self):
  25.         while True:
  26.             print 'tick'
  27.             time.sleep(1)
  28.  
  29. def some_func():
  30.     a = A()
  31.     #a.create_b()
  32.     a.some_action()
  33.     time.sleep(2)
  34.     a.some_action()
  35.     a.some_action()
  36.  
  37. some_func()
  38. time.sleep(3)
clone this paste RAW Paste Data