Example #1
0
 def __init__(self, *args, **kwargs):
     super(WindowSlave, self).__init__(*args, **kwargs)
     # 监听剪切板
     clipboard = QApplication.clipboard()
     clipboard.dataChanged.connect(self.on_data_changed)
     # 加入Master节点
     node = QRemoteObjectNode(parent=self)
     node.connectToNode(QUrl('tcp://{}:{}'.format(sys.argv[1],
                                                  sys.argv[2])))
     # 获取WindowMaster对象
     self.windowMaster = node.acquireDynamic('WindowMaster')
     # 初始化成功后才能去绑定信号等
     self.windowMaster.initialized.connect(self.onInitialized)
     # 状态改变 https://doc.qt.io/qt-5/qremoteobjectreplica.html#State-enum
     self.windowMaster.stateChanged.connect(self.onStateChanged)
Example #2
0
 def on_buttonConnect_clicked(self):
     # 连接
     url = self.editAddress.text().strip()
     if not url or not url.startswith('tcp://'):
         return
     self.editAddress.setEnabled(False)
     self.buttonConnect.setEnabled(False)
     # 加入Master节点
     node = QRemoteObjectNode(parent=self)
     node.connectToNode(QUrl(url))
     # 获取远程对象
     self._socket = node.acquireDynamic('QtDesignerPluginWebSocket')
     if not self._socket:
         self.onDisconnected()
         self.textBrowserApi.append('<font color=red>{0}</font>'.format(
             self.tr('无法连接: %s' % url)))
         return
     # 状态改变 https://doc.qt.io/qt-5/qremoteobjectreplica.html#State-enum
     self._socket.stateChanged.connect(self.onStateChanged)
     # 初始化成功后才能去绑定信号等
     self._socket.initialized.connect(self.onInitialized)
Example #3
0
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
## $QT_END_LICENSE$
#############################################################################

import sys

from PyQt5.QtCore import QLoggingCategory, QUrl
from PyQt5.QtRemoteObjects import QRemoteObjectNode
from PyQt5.QtWidgets import QApplication, QTreeView

QLoggingCategory.setFilterRules("qt.remoteobjects.debug=false\n"
                                "qt.remoteobjects.warning=false\n"
                                "qt.remoteobjects.models.debug=false\n"
                                "qt.remoteobjects.models.debug=false")

app = QApplication(sys.argv)

node = QRemoteObjectNode(QUrl("local:registry"))
node.setHeartbeatInterval(1000)

view = QTreeView()
view.setWindowTitle("RemoteView")
view.resize(640, 480)

model = node.acquireModel("RemoteModel")
view.setModel(model)
view.show()

sys.exit(app.exec_())
Example #4
0
        print("Received source state", value, self._clientSwitchState)

        # Emit the signal to echo the received state back to the server.
        self.echoSwitchState.emit(self._clientSwitchState)

    @pyqtSlot()
    def initConnection(self):
        # Connect the replica source signal currStateChanged() with the
        # client's recSwitchState() slot to receive the source's current state.
        self._replica.currStateChanged.connect(self.recSwitchState)

        # Connect the client's echoSwitchState() signal with replica's
        # server_slot() to echo back the received state.
        self.echoSwitchState.connect(self._replica.server_slot)


if __name__ == '__main__':

    app = QCoreApplication(sys.argv)

    # Create the remote object node.
    repNode = QRemoteObjectNode(QUrl('local:registry'))

    # Acquire a replica of the source from the host node.
    replica = repNode.acquireDynamic('SimpleSwitch')

    # Create the client switch object and pass the replica to it.
    rswitch = DynamicClient(replica)

    sys.exit(app.exec_())
        print("Received source state", value, self._clientSwitchState)

        # Emit the signal to echo the received state back to the server.
        self.echoSwitchState.emit(self._clientSwitchState)

    @pyqtSlot()
    def initConnection(self):
        # Connect the replica source signal currStateChanged() with the
        # client's recSwitchState() slot to receive the source's current state.
        self._replica.currStateChanged.connect(self.recSwitchState)

        # Connect the client's echoSwitchState() signal with replica's
        # server_slot() to echo back the received state.
        self.echoSwitchState.connect(self._replica.server_slot)


if __name__ == "__main__":

    app = QCoreApplication(sys.argv)

    # Create the remote object node.
    repNode = QRemoteObjectNode(QUrl("local:registry"))

    # Acquire a replica of the source from the host node.
    replica = repNode.acquireDynamic("SimpleSwitch")

    # Create the client switch object and pass the replica to it.
    rswitch = DynamicClient(replica)

    sys.exit(app.exec_())
Example #6
0
        # Emit the signal to echo the received state back to the server.
        self.echoSwitchState.emit(self._clientSwitchState)

    @pyqtSlot()
    def initConnection(self):
        # Connect the replica source signal currStateChanged() with the
        # client's recSwitchState() slot to receive the source's current state.
        self._replica.currStateChanged.connect(self.recSwitchState)

        # Connect the client's echoSwitchState() signal with replica's
        # server_slot() to echo back the received state.
        self.echoSwitchState.connect(self._replica.server_slot)


if __name__ == '__main__':

    app = QCoreApplication(sys.argv)

    # Create the remote object node.
    repNode = QRemoteObjectNode()

    # Connect with the remote host node.
    repNode.connectToNode(QUrl('local:replica'))

    # Acquire a replica of the source from the host node.
    replica = repNode.acquireDynamic('SimpleSwitch')

    # Create the client switch object and pass the replica to it.
    rswitch = DynamicClient(replica)

    sys.exit(app.exec_())
        self.echoSwitchState.emit(self._clientSwitchState)

    @pyqtSlot()
    def initConnection(self):
        # Connect the replica source signal currStateChanged() with the
        # client's recSwitchState() slot to receive the source's current state.
        self._replica.currStateChanged.connect(self.recSwitchState)

        # Connect the client's echoSwitchState() signal with replica's
        # server_slot() to echo back the received state.
        self.echoSwitchState.connect(self._replica.server_slot)


if __name__ == "__main__":

    app = QCoreApplication(sys.argv)

    # Create the remote object node.
    repNode = QRemoteObjectNode()

    # Connect with the remote host node.
    repNode.connectToNode(QUrl("local:replica"))

    # Acquire a replica of the source from the host node.
    replica = repNode.acquireDynamic("SimpleSwitch")

    # Create the client switch object and pass the replica to it.
    rswitch = DynamicClient(replica)

    sys.exit(app.exec_())