| 58 | |
| 59 | |
| 60 | class DynamicClient(QObject): |
| 61 | # This signal is connected with server_slot() slot of the source object and |
| 62 | # echoes back the switch state received from the source. |
| 63 | echoSwitchState = pyqtSignal(bool) |
| 64 | |
| 65 | def __init__(self, replica, parent=None): |
| 66 | super().__init__(parent) |
| 67 | |
| 68 | self._replica = replica |
| 69 | self._clientSwitchState = False |
| 70 | |
| 71 | replica.initialized.connect(self.initConnection) |
| 72 | |
| 73 | @pyqtSlot(bool) |
| 74 | def recSwitchState(self, value): |
| 75 | self._clientSwitchState = self._replica.property('currState') |
| 76 | |
| 77 | print("Received source state", value, self._clientSwitchState) |
| 78 | |
| 79 | # Emit the signal to echo the received state back to the server. |
| 80 | self.echoSwitchState.emit(self._clientSwitchState) |
| 81 | |
| 82 | @pyqtSlot() |
| 83 | def initConnection(self): |
| 84 | # Connect the replica source signal currStateChanged() with the |
| 85 | # client's recSwitchState() slot to receive the source's current state. |
| 86 | self._replica.currStateChanged.connect(self.recSwitchState) |
| 87 | |
| 88 | # Connect the client's echoSwitchState() signal with replica's |
| 89 | # server_slot() to echo back the received state. |
| 90 | self.echoSwitchState.connect(self._replica.server_slot) |
| 91 | |
| 92 | |
| 93 | if __name__ == '__main__': |
no outgoing calls
no test coverage detected