diff options
author | Friedemann Kleint <[email protected]> | 2021-01-26 08:40:30 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2021-01-26 11:20:26 +0100 |
commit | 019ab0d2388e30def0cb982c14e011af119d2409 (patch) | |
tree | cc34379c3114f67fcbe2477cb7c5294c17c6fa50 /examples | |
parent | f2e3e8d8d34c93dc8e61d0efd01a59f542abd94c (diff) |
PySide6: Re-add QStateMachine
The code was moved from QtCore into a separate library, QStateMachine,
within the qtscxml repository.
Re-add tests and fix examples.
Task-number: PYSIDE-904
Task-number: PYSIDE-1482
Change-Id: I977b4835b3345fb342c369e4fdd92646118f7fda
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/widgets/animation/animatedtiles/animatedtiles.py | 24 | ||||
-rw-r--r-- | examples/widgets/animation/appchooser/appchooser.py | 14 | ||||
-rw-r--r-- | examples/widgets/animation/states/states.py | 12 | ||||
-rw-r--r-- | examples/widgets/state-machine/eventtrans.py | 4 | ||||
-rw-r--r-- | examples/widgets/state-machine/factstates.py | 5 | ||||
-rw-r--r-- | examples/widgets/state-machine/pingpong.py | 4 | ||||
-rw-r--r-- | examples/widgets/state-machine/rogue.py | 14 | ||||
-rw-r--r-- | examples/widgets/state-machine/trafficlight.py | 4 | ||||
-rw-r--r-- | examples/widgets/state-machine/twowaybutton.py | 4 |
9 files changed, 50 insertions, 35 deletions
diff --git a/examples/widgets/animation/animatedtiles/animatedtiles.py b/examples/widgets/animation/animatedtiles/animatedtiles.py index 3ec1b475b..b5a030235 100644 --- a/examples/widgets/animation/animatedtiles/animatedtiles.py +++ b/examples/widgets/animation/animatedtiles/animatedtiles.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 Riverbank Computing Limited. -## 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,7 +40,7 @@ ## ############################################################################# -from PySide6 import QtCore, QtGui, QtWidgets +from PySide6 import QtCore, QtGui, QtStateMachine, QtWidgets import animatedtiles_rc @@ -179,14 +179,16 @@ if __name__ == '__main__': buttonParent.setZValue(65) # States. - rootState = QtCore.QState() - ellipseState = QtCore.QState(rootState) - figure8State = QtCore.QState(rootState) - randomState = QtCore.QState(rootState) - tiledState = QtCore.QState(rootState) - centeredState = QtCore.QState(rootState) + rootState = QtStateMachine.QState() + ellipseState = QtStateMachine.QState(rootState) + figure8State = QtStateMachine.QState(rootState) + randomState = QtStateMachine.QState(rootState) + tiledState = QtStateMachine.QState(rootState) + centeredState = QtStateMachine.QState(rootState) # Values. + generator = QtCore.QRandomGenerator.global_() + for i, item in enumerate(items): # Ellipse. ellipseState.assignProperty(item, 'pos', @@ -200,8 +202,8 @@ if __name__ == '__main__': # Random. randomState.assignProperty(item, 'pos', - QtCore.QPointF(-250 + QtCore.qrand() % 500, - -250 + QtCore.qrand() % 500)) + QtCore.QPointF(-250 + generator.bounded(0, 500), + -250 + generator.bounded(0, 500))) # Tiled. tiledState.assignProperty(item, 'pos', @@ -221,7 +223,7 @@ if __name__ == '__main__': QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) view.show() - states = QtCore.QStateMachine() + states = QtStateMachine.QStateMachine() states.addState(rootState) states.setInitialState(rootState) rootState.setInitialState(centeredState) diff --git a/examples/widgets/animation/appchooser/appchooser.py b/examples/widgets/animation/appchooser/appchooser.py index 55cd3c1d5..5c9e9c6c1 100644 --- a/examples/widgets/animation/appchooser/appchooser.py +++ b/examples/widgets/animation/appchooser/appchooser.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 Riverbank Computing Limited. -## 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,7 +40,7 @@ ## ############################################################################# -from PySide6 import QtCore, QtGui, QtWidgets +from PySide6 import QtCore, QtGui, QtStateMachine, QtWidgets import appchooser_rc @@ -71,7 +71,7 @@ class Pixmap(QtWidgets.QGraphicsWidget): def createStates(objects, selectedRect, parent): for obj in objects: - state = QtCore.QState(parent) + state = QtStateMachine.QState(parent) state.assignProperty(obj, 'geometry', selectedRect) parent.addTransition(obj.clicked, state) @@ -111,13 +111,13 @@ if __name__ == '__main__': window.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) window.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) - machine = QtCore.QStateMachine() - machine.setGlobalRestorePolicy(QtCore.QStateMachine.RestoreProperties) + machine = QtStateMachine.QStateMachine() + machine.setGlobalRestorePolicy(QtStateMachine.QStateMachine.RestoreProperties) - group = QtCore.QState(machine) + group = QtStateMachine.QState(machine) selectedRect = QtCore.QRect(86, 86, 128, 128) - idleState = QtCore.QState(group) + idleState = QtStateMachine.QState(group) group.setInitialState(idleState) objects = [p1, p2, p3, p4] diff --git a/examples/widgets/animation/states/states.py b/examples/widgets/animation/states/states.py index 363b5af6c..77c76bd9e 100644 --- a/examples/widgets/animation/states/states.py +++ b/examples/widgets/animation/states/states.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 Riverbank Computing Limited. -## 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,7 +40,7 @@ ## ############################################################################# -from PySide6 import QtCore, QtGui, QtWidgets +from PySide6 import QtCore, QtGui, QtStateMachine, QtWidgets import states_rc @@ -116,10 +116,10 @@ if __name__ == '__main__': scene.addItem(p5) scene.addItem(p6) - machine = QtCore.QStateMachine() - state1 = QtCore.QState(machine) - state2 = QtCore.QState(machine) - state3 = QtCore.QState(machine) + machine = QtStateMachine.QStateMachine() + state1 = QtStateMachine.QState(machine) + state2 = QtStateMachine.QState(machine) + state3 = QtStateMachine.QState(machine) machine.setInitialState(state1) # State 1. diff --git a/examples/widgets/state-machine/eventtrans.py b/examples/widgets/state-machine/eventtrans.py index 3445832a0..312b4e258 100644 --- a/examples/widgets/state-machine/eventtrans.py +++ b/examples/widgets/state-machine/eventtrans.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 velociraptor Genjix <[email protected]> -## 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. @@ -42,6 +42,8 @@ from PySide6.QtWidgets import * from PySide6.QtCore import * +from PySide6.QtStateMachine import QEventTransition, QState, QStateMachine + class MainWindow(QMainWindow): def __init__(self): diff --git a/examples/widgets/state-machine/factstates.py b/examples/widgets/state-machine/factstates.py index 64b9613ec..3608f2a49 100644 --- a/examples/widgets/state-machine/factstates.py +++ b/examples/widgets/state-machine/factstates.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 velociraptor Genjix <[email protected]> -## 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. @@ -42,6 +42,9 @@ from PySide6.QtWidgets import * from PySide6.QtCore import * +from PySide6.QtStateMachine import (QFinalState, QSignalTransition, QState, + QStateMachine) + class Factorial(QObject): xChanged = Signal(int) diff --git a/examples/widgets/state-machine/pingpong.py b/examples/widgets/state-machine/pingpong.py index 6d64bebc6..f2e1f59f7 100644 --- a/examples/widgets/state-machine/pingpong.py +++ b/examples/widgets/state-machine/pingpong.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 velociraptor Genjix <[email protected]> -## 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. @@ -42,6 +42,8 @@ from PySide6.QtWidgets import * from PySide6.QtCore import * +from PySide6.QtStateMachine import QAbstractTransition, QState, QStateMachine + class PingEvent(QEvent): def __init__(self): diff --git a/examples/widgets/state-machine/rogue.py b/examples/widgets/state-machine/rogue.py index af37b522b..b830d6023 100644 --- a/examples/widgets/state-machine/rogue.py +++ b/examples/widgets/state-machine/rogue.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 velociraptor Genjix <[email protected]> -## 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. @@ -43,6 +43,9 @@ from PySide6.QtWidgets import * from PySide6.QtGui import * from PySide6.QtCore import * +from PySide6.QtStateMachine import (QEventTransition, QFinalState, + QKeyEventTransition, QState, QStateMachine) + class MovementTransition(QEventTransition): def __init__(self, window): @@ -83,12 +86,11 @@ class MainWindow(QMainWindow): self.height = 20 self.statusStr = '' - database = QFontDatabase() font = QFont() - if 'Monospace' in database.families(): + if 'Monospace' in QFontDatabase.families(): font = QFont('Monospace', 12) else: - for family in database.families(): + for family in QFontDatabase.families(): if database.isFixedPitch(family): font = QFont(family, 12) self.setFont(font) @@ -98,12 +100,12 @@ class MainWindow(QMainWindow): self.show() def setupMap(self): self.map = [] - qsrand(QTime(0, 0, 0).secsTo(QTime.currentTime())) + generator = QRandomGenerator().global_() for x in range(self.width): column = [] for y in range(self.height): if x == 0 or x == self.width - 1 or y == 0 or \ - y == self.height - 1 or qrand() % 40 == 0: + y == self.height - 1 or generator.bounded(0, 40) == 0: column.append('#') else: column.append('.') diff --git a/examples/widgets/state-machine/trafficlight.py b/examples/widgets/state-machine/trafficlight.py index 4aa8d560e..3631fdbbb 100644 --- a/examples/widgets/state-machine/trafficlight.py +++ b/examples/widgets/state-machine/trafficlight.py @@ -43,6 +43,8 @@ from PySide6.QtWidgets import * from PySide6.QtGui import * from PySide6.QtCore import * +from PySide6.QtStateMachine import QFinalState, QState, QStateMachine + class LightWidget(QWidget): def __init__(self, color): @@ -83,7 +85,7 @@ class TrafficLightWidget(QWidget): self.greenLight = LightWidget(Qt.green) vbox.addWidget(self.greenLight) pal = QPalette() - pal.setColor(QPalette.Background, Qt.black) + pal.setColor(QPalette.Window, Qt.black) self.setPalette(pal) self.setAutoFillBackground(True) diff --git a/examples/widgets/state-machine/twowaybutton.py b/examples/widgets/state-machine/twowaybutton.py index 44a011d69..6b3c58359 100644 --- a/examples/widgets/state-machine/twowaybutton.py +++ b/examples/widgets/state-machine/twowaybutton.py @@ -2,7 +2,7 @@ ############################################################################# ## ## Copyright (C) 2010 velociraptor Genjix <[email protected]> -## 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. @@ -42,6 +42,8 @@ from PySide6.QtWidgets import * from PySide6.QtCore import * +from PySide6.QtStateMachine import QState, QStateMachine + if __name__ == '__main__': import sys |