Hello. I'd like to ask you for an advice. How to connect pyqtSignal between two different objects (classes) PROPERLY? I mean best practice. Look what I have done to achieve the goal: The Thermometer class is notified when Pot increases its temperature:
from PyQt4 import QtCore
class Pot(QtCore.QObject):
temperatureRaisedSignal = QtCore.pyqtSignal()
def __init__(self, parent=None):
super(Pot, self).__init__(parent)
self.temperature = 1
def Boil(self):
self.temperature += 1
self.temperatureRaisedSignal.emit()
def RegisterSignal(self, obj):
self.temperatureRaisedSignal.connect(obj)
class Thermometer():
def __init__(self, pot):
self.pot = pot
self.pot.RegisterSignal(self.temperatureWarning)
def StartMeasure(self):
self.pot.Boil()
def temperatureWarning(self):
print("Too high temperature!")
if __name__ == '__main__':
pot = Pot()
th = Thermometer(pot)
th.StartMeasure()
Or is there any easier / better way to do it? I also insist (if possible) on using "new" style PyQt signal. I couldn't find any real example. Thank you.