From 7ecfbeea84f529dbd11029ab35fbca771d34516a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Fri, 24 Sep 2021 23:58:47 +0200 Subject: doc: fix warnings from rst files Change-Id: I97166f7e89c0365f425d1f8b0b840b7ef066d0d7 Reviewed-by: Friedemann Kleint --- .../widgets/state-machine/ping_pong/ping_pong.py | 108 +++++++++++++++++++++ .../state-machine/ping_pong/ping_pong.pyproject | 3 + .../widgets/state-machine/pingpong/pingpong.py | 108 --------------------- .../state-machine/pingpong/pingpong.pyproject | 3 - examples/widgets/thread_signals/thread_signals.py | 100 +++++++++++++++++++ .../thread_signals/thread_signals.pyproject | 3 + examples/widgets/threads/thread_signals.py | 100 ------------------- examples/widgets/threads/thread_signals.pyproject | 3 - 8 files changed, 214 insertions(+), 214 deletions(-) create mode 100644 examples/widgets/state-machine/ping_pong/ping_pong.py create mode 100644 examples/widgets/state-machine/ping_pong/ping_pong.pyproject delete mode 100644 examples/widgets/state-machine/pingpong/pingpong.py delete mode 100644 examples/widgets/state-machine/pingpong/pingpong.pyproject create mode 100644 examples/widgets/thread_signals/thread_signals.py create mode 100644 examples/widgets/thread_signals/thread_signals.pyproject delete mode 100644 examples/widgets/threads/thread_signals.py delete mode 100644 examples/widgets/threads/thread_signals.pyproject (limited to 'examples') diff --git a/examples/widgets/state-machine/ping_pong/ping_pong.py b/examples/widgets/state-machine/ping_pong/ping_pong.py new file mode 100644 index 000000000..cd047a29d --- /dev/null +++ b/examples/widgets/state-machine/ping_pong/ping_pong.py @@ -0,0 +1,108 @@ + +############################################################################# +## +## Copyright (C) 2010 velociraptor Genjix +## Copyright (C) 2021 The Qt Company Ltd. +## Contact: http://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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$ +## +############################################################################# + +from PySide6.QtWidgets import * +from PySide6.QtCore import * +from PySide6.QtStateMachine import QAbstractTransition, QState, QStateMachine + + +class PingEvent(QEvent): + def __init__(self): + super().__init__(QEvent.Type(QEvent.User + 2)) + + +class PongEvent(QEvent): + def __init__(self): + super().__init__(QEvent.Type(QEvent.User + 3)) + + +class Pinger(QState): + def __init__(self, parent): + super().__init__(parent) + + def onEntry(self, e): + self.p = PingEvent() + self.machine().postEvent(self.p) + print('ping?') + + +class PongTransition(QAbstractTransition): + def eventTest(self, e): + return e.type() == QEvent.User + 3 + + def onTransition(self, e): + self.p = PingEvent() + machine.postDelayedEvent(self.p, 500) + print('ping?') + + +class PingTransition(QAbstractTransition): + def eventTest(self, e): + return e.type() == QEvent.User + 2 + + def onTransition(self, e): + self.p = PongEvent() + machine.postDelayedEvent(self.p, 500) + print('pong!') + + +if __name__ == '__main__': + import sys + app = QCoreApplication(sys.argv) + + machine = QStateMachine() + group = QState(QState.ParallelStates) + group.setObjectName('group') + + pinger = Pinger(group) + pinger.setObjectName('pinger') + pinger.addTransition(PongTransition()) + + ponger = QState(group) + ponger.setObjectName('ponger') + ponger.addTransition(PingTransition()) + + machine.addState(group) + machine.setInitialState(group) + machine.start() + + sys.exit(app.exec()) diff --git a/examples/widgets/state-machine/ping_pong/ping_pong.pyproject b/examples/widgets/state-machine/ping_pong/ping_pong.pyproject new file mode 100644 index 000000000..7fb430352 --- /dev/null +++ b/examples/widgets/state-machine/ping_pong/ping_pong.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["ping_pong.py"] +} diff --git a/examples/widgets/state-machine/pingpong/pingpong.py b/examples/widgets/state-machine/pingpong/pingpong.py deleted file mode 100644 index cd047a29d..000000000 --- a/examples/widgets/state-machine/pingpong/pingpong.py +++ /dev/null @@ -1,108 +0,0 @@ - -############################################################################# -## -## Copyright (C) 2010 velociraptor Genjix -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: http://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## 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$ -## -############################################################################# - -from PySide6.QtWidgets import * -from PySide6.QtCore import * -from PySide6.QtStateMachine import QAbstractTransition, QState, QStateMachine - - -class PingEvent(QEvent): - def __init__(self): - super().__init__(QEvent.Type(QEvent.User + 2)) - - -class PongEvent(QEvent): - def __init__(self): - super().__init__(QEvent.Type(QEvent.User + 3)) - - -class Pinger(QState): - def __init__(self, parent): - super().__init__(parent) - - def onEntry(self, e): - self.p = PingEvent() - self.machine().postEvent(self.p) - print('ping?') - - -class PongTransition(QAbstractTransition): - def eventTest(self, e): - return e.type() == QEvent.User + 3 - - def onTransition(self, e): - self.p = PingEvent() - machine.postDelayedEvent(self.p, 500) - print('ping?') - - -class PingTransition(QAbstractTransition): - def eventTest(self, e): - return e.type() == QEvent.User + 2 - - def onTransition(self, e): - self.p = PongEvent() - machine.postDelayedEvent(self.p, 500) - print('pong!') - - -if __name__ == '__main__': - import sys - app = QCoreApplication(sys.argv) - - machine = QStateMachine() - group = QState(QState.ParallelStates) - group.setObjectName('group') - - pinger = Pinger(group) - pinger.setObjectName('pinger') - pinger.addTransition(PongTransition()) - - ponger = QState(group) - ponger.setObjectName('ponger') - ponger.addTransition(PingTransition()) - - machine.addState(group) - machine.setInitialState(group) - machine.start() - - sys.exit(app.exec()) diff --git a/examples/widgets/state-machine/pingpong/pingpong.pyproject b/examples/widgets/state-machine/pingpong/pingpong.pyproject deleted file mode 100644 index 67b48e5ab..000000000 --- a/examples/widgets/state-machine/pingpong/pingpong.pyproject +++ /dev/null @@ -1,3 +0,0 @@ -{ - "files": ["pingpong.py"] -} diff --git a/examples/widgets/thread_signals/thread_signals.py b/examples/widgets/thread_signals/thread_signals.py new file mode 100644 index 000000000..43c79f4b7 --- /dev/null +++ b/examples/widgets/thread_signals/thread_signals.py @@ -0,0 +1,100 @@ + +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the Qt for Python examples of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:BSD$ +## 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$ +## +############################################################################# + +import sys +from PySide6.QtCore import QObject, QThread, Signal, Slot +from PySide6.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget + + +# Create a basic window with a layout and a button +class MainForm(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("My Form") + self.layout = QVBoxLayout() + self.button = QPushButton("Click me!") + self.button.clicked.connect(self.start_thread) + self.layout.addWidget(self.button) + self.setLayout(self.layout) + + # Instantiate and start a new thread + def start_thread(self): + instanced_thread = WorkerThread(self) + instanced_thread.start() + + # Create the Slots that will receive signals + @Slot(str) + def update_str_field(self, message): + print(message) + + @Slot(int) + def update_int_field(self, value): + print(value) + + +# Signals must inherit QObject +class MySignals(QObject): + signal_str = Signal(str) + signal_int = Signal(int) + + +# Create the Worker Thread +class WorkerThread(QThread): + def __init__(self, parent=None): + QThread.__init__(self, parent) + # Instantiate signals and connect signals to the slots + self.signals = MySignals() + self.signals.signal_str.connect(parent.update_str_field) + self.signals.signal_int.connect(parent.update_int_field) + + def run(self): + # Do something on the worker thread + a = 1 + 1 + # Emit signals whenever you want + self.signals.signal_int.emit(a) + self.signals.signal_str.emit("This text comes to Main thread from our Worker thread.") + + +if __name__ == "__main__": + app = QApplication(sys.argv) + window = MainForm() + window.show() + sys.exit(app.exec()) diff --git a/examples/widgets/thread_signals/thread_signals.pyproject b/examples/widgets/thread_signals/thread_signals.pyproject new file mode 100644 index 000000000..e36f7633c --- /dev/null +++ b/examples/widgets/thread_signals/thread_signals.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["thread_signals.py"] +} diff --git a/examples/widgets/threads/thread_signals.py b/examples/widgets/threads/thread_signals.py deleted file mode 100644 index 43c79f4b7..000000000 --- a/examples/widgets/threads/thread_signals.py +++ /dev/null @@ -1,100 +0,0 @@ - -############################################################################# -## -## Copyright (C) 2020 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the Qt for Python examples of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:BSD$ -## 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$ -## -############################################################################# - -import sys -from PySide6.QtCore import QObject, QThread, Signal, Slot -from PySide6.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget - - -# Create a basic window with a layout and a button -class MainForm(QWidget): - def __init__(self): - super().__init__() - self.setWindowTitle("My Form") - self.layout = QVBoxLayout() - self.button = QPushButton("Click me!") - self.button.clicked.connect(self.start_thread) - self.layout.addWidget(self.button) - self.setLayout(self.layout) - - # Instantiate and start a new thread - def start_thread(self): - instanced_thread = WorkerThread(self) - instanced_thread.start() - - # Create the Slots that will receive signals - @Slot(str) - def update_str_field(self, message): - print(message) - - @Slot(int) - def update_int_field(self, value): - print(value) - - -# Signals must inherit QObject -class MySignals(QObject): - signal_str = Signal(str) - signal_int = Signal(int) - - -# Create the Worker Thread -class WorkerThread(QThread): - def __init__(self, parent=None): - QThread.__init__(self, parent) - # Instantiate signals and connect signals to the slots - self.signals = MySignals() - self.signals.signal_str.connect(parent.update_str_field) - self.signals.signal_int.connect(parent.update_int_field) - - def run(self): - # Do something on the worker thread - a = 1 + 1 - # Emit signals whenever you want - self.signals.signal_int.emit(a) - self.signals.signal_str.emit("This text comes to Main thread from our Worker thread.") - - -if __name__ == "__main__": - app = QApplication(sys.argv) - window = MainForm() - window.show() - sys.exit(app.exec()) diff --git a/examples/widgets/threads/thread_signals.pyproject b/examples/widgets/threads/thread_signals.pyproject deleted file mode 100644 index e36f7633c..000000000 --- a/examples/widgets/threads/thread_signals.pyproject +++ /dev/null @@ -1,3 +0,0 @@ -{ - "files": ["thread_signals.py"] -} -- cgit v1.2.3