Esempio n. 1
0
        if i == 0:
            firstItem.appendRow(addChild(2, 2))

        secondItem = QStandardItem("FancyRow2TextNumber {}".format(i))
        if i % 2 == 0:
            firstItem.setBackground(Qt.red)

        sourceModel.invisibleRootItem().appendRow([firstItem, secondItem])

    # Needed by QMLModelViewClient.
    roleNames = {Qt.DisplayRole: b'_text', Qt.BackgroundRole: b'_color'}
    sourceModel.setItemRoleNames(roleNames)

    roles = [Qt.DisplayRole, Qt.BackgroundRole]

    node = QRemoteObjectRegistryHost(QUrl('local:registry'))

    node2 = QRemoteObjectHost(QUrl('local:replica'), QUrl('local:registry'))
    node2.enableRemoting(sourceModel, 'RemoteModel', roles)

    view = QTreeView()
    view.setWindowTitle("SourceView")
    view.setModel(sourceModel)
    view.show()

    handler = TimerHandler(sourceModel)
    QTimer.singleShot(5000, handler.changeData)
    QTimer.singleShot(10000, handler.insertData)
    QTimer.singleShot(11000, handler.changeFlags)
    QTimer.singleShot(12000, handler.removeData)
    QTimer.singleShot(13000, handler.moveData)
Esempio n. 2
0
        # The switch state echoed back by the client.
        print("Replica state is", clientState)

    def _timeout(self):
        # Note that we don't decorate this callable so that it doesn't get
        # exposed in a replica.
        self.currState = not self.currState

        print("Source state is", self.currState)


if __name__ == "__main__":

    app = QCoreApplication(sys.argv)

    # Create the simple switch.
    srcSwitch = SimpleSwitch()

    # Create the node that hosts the registry.  This could be in a separate
    # process.
    regNode = QRemoteObjectRegistryHost(QUrl("local:registry"))

    # Create the host object node.  This will connect to the registry node
    # rather than to a client.
    srcNode = QRemoteObjectHost(QUrl("local:replica"), QUrl("local:registry"))

    # Enable remoting.
    srcNode.enableRemoting(srcSwitch, "SimpleSwitch")

    sys.exit(app.exec_())