The trick is to use another object as the mediator for emitting signals, and then using Python properties to hide the fact that a mediator is being used. Consider the example below:
class Mediator(QObject):Using this approach any classes working with Task instances can connect directly to the mySignal signal as if it was bound directly to the Task class. So the property hides the fact that a mediator is in use.
mySignal = pyqtSignal(int)
def __init__(self):
super(Mediator, self).__init__()
class Task(QRunnable):
def __init__(self):
super(Task, self).__init__()
self._mediator = Mediator()
def mySignal():
def fget(self):
return self._mediator.mySignal
return locals()
mySignal = property(**mySignal())
No comments:
Post a Comment