diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-12 10:42:19 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-11-13 22:57:16 +0000 |
commit | f8d9c3e234417e817b33976dd874e0c6e001e36d (patch) | |
tree | 8857fffadf8cdb2f269f26ddae774ae924f88649 /examples | |
parent | c2eb6d2e7540401503198fafc0235d8e2aa337fd (diff) |
Examples: Polish the statemachine examples
- Remove * imports
- Pass signals instead of strings (SIGNAL)
- Break lines
Change-Id: I566f69210821f73dd22d351926a27638e1fc5671
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit f160c0f1f2053029c118eb5818074f875a3776b4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
6 files changed, 37 insertions, 31 deletions
diff --git a/examples/widgets/state-machine/eventtrans/eventtrans.py b/examples/widgets/state-machine/eventtrans/eventtrans.py index 44aca37f8..f137d25b7 100644 --- a/examples/widgets/state-machine/eventtrans/eventtrans.py +++ b/examples/widgets/state-machine/eventtrans/eventtrans.py @@ -40,8 +40,10 @@ ## ############################################################################# -from PySide6.QtWidgets import * -from PySide6.QtCore import * +import sys + +from PySide6.QtCore import QEvent, QRect, Qt +from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton from PySide6.QtStateMachine import QEventTransition, QState, QStateMachine @@ -88,8 +90,6 @@ class MainWindow(QMainWindow): if __name__ == '__main__': - import sys - app = QApplication(sys.argv) main_win = MainWindow() sys.exit(app.exec()) diff --git a/examples/widgets/state-machine/factstates/factstates.py b/examples/widgets/state-machine/factstates/factstates.py index e8ca0ef43..72e5471c2 100644 --- a/examples/widgets/state-machine/factstates/factstates.py +++ b/examples/widgets/state-machine/factstates/factstates.py @@ -40,8 +40,9 @@ ## ############################################################################# -from PySide6.QtWidgets import * -from PySide6.QtCore import * +import sys + +from PySide6.QtCore import QCoreApplication, QObject, Qt, Property, Signal from PySide6.QtStateMachine import (QFinalState, QSignalTransition, QState, QStateMachine) @@ -75,7 +76,7 @@ class Factorial(QObject): class FactorialLoopTransition(QSignalTransition): def __init__(self, fact): - super().__init__(fact, SIGNAL('x_changed(int)')) + super().__init__(fact.x_changed) self.fact = fact def eventTest(self, e): @@ -92,7 +93,7 @@ class FactorialLoopTransition(QSignalTransition): class FactorialDoneTransition(QSignalTransition): def __init__(self, fact): - super().__init__(fact, SIGNAL('x_changed(int)')) + super().__init__(fact.x_changed) self.fact = fact def eventTest(self, e): @@ -105,7 +106,6 @@ class FactorialDoneTransition(QSignalTransition): if __name__ == '__main__': - import sys app = QCoreApplication(sys.argv) factorial = Factorial() machine = QStateMachine() diff --git a/examples/widgets/state-machine/ping_pong/ping_pong.py b/examples/widgets/state-machine/ping_pong/ping_pong.py index cd047a29d..74907dcf6 100644 --- a/examples/widgets/state-machine/ping_pong/ping_pong.py +++ b/examples/widgets/state-machine/ping_pong/ping_pong.py @@ -40,8 +40,9 @@ ## ############################################################################# -from PySide6.QtWidgets import * -from PySide6.QtCore import * +import sys + +from PySide6.QtCore import QCoreApplication, QEvent from PySide6.QtStateMachine import QAbstractTransition, QState, QStateMachine @@ -86,7 +87,6 @@ class PingTransition(QAbstractTransition): if __name__ == '__main__': - import sys app = QCoreApplication(sys.argv) machine = QStateMachine() diff --git a/examples/widgets/state-machine/rogue/rogue.py b/examples/widgets/state-machine/rogue/rogue.py index 1234bea0b..e3d0923bc 100644 --- a/examples/widgets/state-machine/rogue/rogue.py +++ b/examples/widgets/state-machine/rogue/rogue.py @@ -40,9 +40,12 @@ ## ############################################################################# -from PySide6.QtWidgets import * -from PySide6.QtGui import * -from PySide6.QtCore import * +import sys + +from PySide6.QtCore import (QEvent, QPoint, QRandomGenerator, QSize, Qt, + Property) +from PySide6.QtGui import QFont, QFontMetrics, QFontDatabase, QPainter +from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtStateMachine import (QEventTransition, QFinalState, QKeyEventTransition, QState, QStateMachine) @@ -209,7 +212,6 @@ class MainWindow(QMainWindow): if __name__ == '__main__': - import sys app = QApplication(sys.argv) main_win = MainWindow() sys.exit(app.exec()) diff --git a/examples/widgets/state-machine/trafficlight/trafficlight.py b/examples/widgets/state-machine/trafficlight/trafficlight.py index 4fbd5e4e8..0d7fcd15c 100644 --- a/examples/widgets/state-machine/trafficlight/trafficlight.py +++ b/examples/widgets/state-machine/trafficlight/trafficlight.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 velociraptor Genjix <aphidia@hotmail.com> -## Copyright (C) 2016 The Qt Company Ltd. +## 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. @@ -40,9 +40,11 @@ ## ############################################################################# -from PySide6.QtWidgets import * -from PySide6.QtGui import * -from PySide6.QtCore import * +import sys + +from PySide6.QtCore import QTimer, Qt, Property, Slot +from PySide6.QtGui import QPainter, QPalette +from PySide6.QtWidgets import QApplication, QVBoxLayout, QWidget from PySide6.QtStateMachine import QFinalState, QState, QStateMachine @@ -106,7 +108,7 @@ def create_light_state(light, duration, parent=None): timing.entered.connect(timer.start) timing.exited.connect(light.turn_off) done = QFinalState(light_state) - timing.addTransition(timer, SIGNAL('timeout()'), done) + timing.addTransition(timer.timeout, done) light_state.setInitialState(timing) return light_state @@ -124,14 +126,18 @@ class TrafficLight(QWidget): red_going_yellow.setObjectName('redGoingYellow') yellow_going_green = create_light_state(widget._red_light, 1000) yellow_going_green.setObjectName('yellowGoingGreen') - red_going_yellow.addTransition(red_going_yellow, SIGNAL('finished()'), yellow_going_green) + red_going_yellow.addTransition(red_going_yellow.finished, + yellow_going_green) green_going_yellow = create_light_state(widget._yellow_light, 3000) green_going_yellow.setObjectName('greenGoingYellow') - yellow_going_green.addTransition(yellow_going_green, SIGNAL('finished()'), green_going_yellow) + yellow_going_green.addTransition(yellow_going_green.finished, + green_going_yellow) yellow_going_red = create_light_state(widget._green_light, 1000) yellow_going_red.setObjectName('yellowGoingRed') - green_going_yellow.addTransition(green_going_yellow, SIGNAL('finished()'), yellow_going_red) - yellow_going_red.addTransition(yellow_going_red, SIGNAL('finished()'), red_going_yellow) + green_going_yellow.addTransition(green_going_yellow.finished, + yellow_going_red) + yellow_going_red.addTransition(yellow_going_red.finished, + red_going_yellow) machine.addState(red_going_yellow) machine.addState(yellow_going_green) @@ -142,7 +148,6 @@ class TrafficLight(QWidget): if __name__ == '__main__': - import sys app = QApplication(sys.argv) widget = TrafficLight() widget.resize(110, 300) diff --git a/examples/widgets/state-machine/twowaybutton/twowaybutton.py b/examples/widgets/state-machine/twowaybutton/twowaybutton.py index d519c4f2a..c75436f09 100644 --- a/examples/widgets/state-machine/twowaybutton/twowaybutton.py +++ b/examples/widgets/state-machine/twowaybutton/twowaybutton.py @@ -40,13 +40,13 @@ ## ############################################################################# -from PySide6.QtWidgets import * -from PySide6.QtCore import * +import sys + +from PySide6.QtWidgets import QApplication, QPushButton from PySide6.QtStateMachine import QState, QStateMachine if __name__ == '__main__': - import sys app = QApplication(sys.argv) button = QPushButton() machine = QStateMachine() @@ -59,8 +59,7 @@ if __name__ == '__main__': on.setObjectName('on') on.assignProperty(button, 'text', 'On') - off.addTransition(button, SIGNAL('clicked()'), on) - # Let's use the new style signals just for the kicks. + off.addTransition(button.clicked, on) on.addTransition(button.clicked, off) machine.addState(off) |