diff options
Diffstat (limited to 'examples/remoteobjects/pyside/simple.py')
-rw-r--r-- | examples/remoteobjects/pyside/simple.py | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/examples/remoteobjects/pyside/simple.py b/examples/remoteobjects/pyside/simple.py new file mode 100644 index 0000000..bd56f7c --- /dev/null +++ b/examples/remoteobjects/pyside/simple.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python3 +############################################################################# +## +## Copyright (C) 2021 Ford Motor Company +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the QtRemoteObjects module of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## BSD License Usage +## Alternatively, you may use this file under the terms of the BSD license +## as follows: +## +## "Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are +## met: +## * Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## * Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in +## the documentation and/or other materials provided with the +## distribution. +## * Neither the name of The Qt Company Ltd nor the names of its +## contributors may be used to endorse or promote products derived +## from this software without specific prior written permission. +## +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +## (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$ +## +############################################################################# + +''' +TODO: Remove before merging. This is an example generated by the updated + repc to show what the generated code would look like and simplify + trying the examples. +''' + +from abc import abstractmethod, ABC, ABCMeta +from typing import TypeVar, Generic, Iterator +from PySide6.QtCore import (ClassInfo, Property, QMetaObject, + QObject, Signal, Slot) +from PySide6.QtRemoteObjects import QRemoteObjectReplica + +QObjectType = type(QObject) +T = TypeVar('T') + +class QABCMeta(QObjectType, ABCMeta): + pass + +@ClassInfo({'RemoteObject Type':'Simple', 'RemoteObject Signature':'c6f33edb0554ba4241aad1286a47c8189d65c845'}) +class SimpleSource(QObject, Generic[T], metaclass=QABCMeta): + iChanged = Signal(int) + fChanged = Signal(float) + random = Signal(int) + + def __init__(self, parent=None): + super().__init__(parent) + + def _getI(self): + return self.getI() + + @abstractmethod + def getI(self): + pass + + def _setI(self, i): + return self.setI(i) + + @abstractmethod + def setI(self, i): + pass + + @abstractmethod + def pushI(self, i): + pass + + @Slot(int, name='pushI') + def _pushI(self, i): + return self.pushI(i) + + i = Property(int, _getI, _setI, notify = iChanged) + + def _getF(self): + return self.getF() + + @abstractmethod + def getF(self): + pass + + def _setF(self, f): + return self.setF(f) + + @abstractmethod + def setF(self, f): + pass + + f = Property(float, _getF, _setF, notify = fChanged) + + + @abstractmethod + def reset(self): + pass + + @Slot(name='reset') + def _reset(self): + return self.reset() + +class SimpleSimpleSource(SimpleSource): + + def __init__(self, parent=None): + super().__init__(parent) + self._i = int(2) + self._f = float(-1.) + + def getI(self): + return self._i + + def pushI(self, i): + self.setI(i) + + def setI(self, i): + if i != self._i: + self._i = i + self.iChanged.emit(i) + + def getF(self): + return self._f + + def setF(self, f): + if f != self._f: + self._f = f + self.fChanged.emit(f) + +@ClassInfo({'RemoteObject Type':'Simple', 'RemoteObject Signature':'c6f33edb0554ba4241aad1286a47c8189d65c845'}) +class SimpleReplica(QRemoteObjectReplica): + iChanged = Signal(int) + fChanged = Signal(float) + random = Signal(int) + pushI_index = -1 + setF_index = -1 + reset_index = -1 + + def __init__(self, node=None, name=None): + super().__init__() + self.initialize() + if SimpleReplica.pushI_index == -1: + SimpleReplica.pushI_index = self.metaObject().indexOfSlot('pushI(int)') + SimpleReplica.setF_index = self.metaObject().indexOfProperty('f') + SimpleReplica.reset_index = self.metaObject().indexOfSlot('reset()') + if node: + self.initializeNode(node, name) + + def initialize(self): + self.setProperties([int(2), float(-1.)]) + + def getI(self): + return self.propAsVariant(0) + + @Slot(int) + def pushI(self, i): + self.send(QMetaObject.InvokeMetaMethod, SimpleReplica.pushI_index, [i]) + + i = Property(int, getI, notify = iChanged) + + def getF(self): + return self.propAsVariant(1) + + def setF(self, f): + self.send(QMetaObject.WriteProperty, SimpleReplica.setF_index, [f]) + + f = Property(float, getF, setF, notify = fChanged) + + @Slot() + def reset(self): + self.send(QMetaObject.InvokeMetaMethod, SimpleReplica.reset_index, []) + |