Exemplo n.º 1
0
 def set_up_machine(self):
     self.machine = QStateMachine(self)
     self.welcome = self._make_welcome()
     self.machine.setInitialState(self.welcome)
     dead = QFinalState(self.machine)
     death = QEventTransition(self, QEvent.Close)
     death.setTargetState(dead)
     self.machine.addTransition(death)
Exemplo n.º 2
0
 def setup(self):
     self.machine = QStateMachine(self)
     self.run = QState(self.machine)
     abort = self._make_abort()
     transition = QEventTransition(self, QEvent.Close)
     transition.setTargetState(abort)
     self.run.addTransition(transition)
     welcome = self._make_welcome()
     welcome.entered.connect(self._handle_welcome_entered)
     self.machine.setInitialState(self.run)
     self.run.setInitialState(welcome)
     self.machine.start()
Exemplo n.º 3
0
    def testBasic(self):
        '''QStateMachine.configuration converting QSet to python set'''
        machine = QStateMachine()
        s1 = QState()
        machine.addState(s1)
        machine.setInitialState(s1)
        machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()

        configuration = machine.configuration()

        self.assertTrue(isinstance(configuration, set))
        self.assertTrue(s1 in configuration)
Exemplo n.º 4
0
    def testBasic(self):
        self.machine = QStateMachine()
        s1 = QState()
        s2 = QState()
        s3 = QFinalState()

        QObject.connect(self.machine, SIGNAL("started()"), self.cb)

        self.anim = QParallelAnimationGroup()

        self.machine.addState(s1)
        self.machine.addState(s2)
        self.machine.addState(s3)
        self.machine.setInitialState(s1)
        self.machine.addDefaultAnimation(self.anim)
        self.machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()
Exemplo n.º 5
0
    def testBasic(self):
        '''QStateMachine.configuration converting QSet to python set'''
        machine = QStateMachine()
        s1 = QState()
        machine.addState(s1)
        machine.setInitialState(s1)
        machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()

        configuration = machine.configuration()

        self.assert_(isinstance(configuration, set))
        self.assert_(s1 in configuration)
Exemplo n.º 6
0
class QStateMachineTest(UsesQCoreApplication):
    def cb(self, *args):
        self.assertEqual(self.machine.defaultAnimations(), [self.anim])

    def testBasic(self):
        self.machine = QStateMachine()
        s1 = QState()
        s2 = QState()
        s3 = QFinalState()

        QObject.connect(self.machine, SIGNAL("started()"), self.cb)

        self.anim = QParallelAnimationGroup()

        self.machine.addState(s1)
        self.machine.addState(s2)
        self.machine.addState(s3)
        self.machine.setInitialState(s1)
        self.machine.addDefaultAnimation(self.anim)
        self.machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()
Exemplo n.º 7
0
class QStateMachineTest(UsesQCoreApplication):

    def cb(self, *args):
        self.assertEqual(self.machine.defaultAnimations(), [self.anim])

    def testBasic(self):
        self.machine = QStateMachine()
        s1 = QState()
        s2 = QState()
        s3 = QFinalState()

        QObject.connect(self.machine, SIGNAL("started()"), self.cb)

        self.anim = QParallelAnimationGroup()

        self.machine.addState(s1)
        self.machine.addState(s2)
        self.machine.addState(s3)
        self.machine.setInitialState(s1)
        self.machine.addDefaultAnimation(self.anim)
        self.machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()
Exemplo n.º 8
0
    def testBasic(self):
        self.machine = QStateMachine()
        s1 = QState()
        s2 = QState()
        s3 = QFinalState()

        QObject.connect(self.machine, SIGNAL("started()"), self.cb)

        self.anim = QParallelAnimationGroup()

        self.machine.addState(s1)
        self.machine.addState(s2)
        self.machine.addState(s3)
        self.machine.setInitialState(s1)
        self.machine.addDefaultAnimation(self.anim)
        self.machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()
Exemplo n.º 9
0
    def testCase(self):
        check = QCheckBox()
        check.setTristate(True)

        s1 = QState()
        s2 = QState()

        t1 = CheckedTransition(check)
        t1.setTargetState(s2)
        s1.addTransition(t1)

        machine = QStateMachine()
        machine.addState(s1)
        machine.addState(s2)
        machine.setInitialState(s1)
        machine.start()

        check.stateChanged[int].emit(1)
        check.show()
        self.app.exec_()
        self.assertTrue(t1.eventTested)
Exemplo n.º 10
0
    def testCase(self):
        check = QCheckBox()
        check.setTristate(True)

        s1 = QState()
        s2 = QState()

        t1 = CheckedTransition(check)
        t1.setTargetState(s2)
        s1.addTransition(t1)

        machine = QStateMachine()
        machine.addState(s1)
        machine.addState(s2)
        machine.setInitialState(s1)
        machine.start()

        check.stateChanged[int].emit(1)
        check.show()
        self.app.exec_()
        self.assert_(t1.eventTested)
Exemplo n.º 11
0
from PySide2.QtCore import QStateMachine, QState

mach = QStateMachine()
state = QState(mach)
print(state.machine())
Exemplo n.º 12
0
class StateMachineWidget(QDockWidget):
    """A widget with a state machine."""

    def __init__(self, window_title, parent):
        """Initializes class.

        Args:
            window_title (str)
            parent (QMainWindow)
        """
        super().__init__(window_title, parent)
        self.setObjectName(window_title)
        self.label_msg = QLabel(self)
        self.label_msg.setFont(QFont("arial,helvetica", 12))
        self.label_msg.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.label_msg.setWordWrap(True)
        self.button_left = QPushButton(self)
        self.button_right = QPushButton(self)
        self.label_loader = QLabel(self)
        self.label_loader.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        movie = QMovie(":/animated_gifs/ajax-loader.gif")
        movie.start()
        self.label_loader.setMovie(movie)
        button_container = QWidget(self)
        button_layout = QHBoxLayout(button_container)
        button_layout.addStretch()
        button_layout.addWidget(self.button_left)
        button_layout.addWidget(self.button_right)
        button_layout.addStretch()
        widget = QWidget(self)
        layout = QVBoxLayout(widget)
        layout.addStretch()
        layout.addWidget(self.label_msg)
        layout.addStretch()
        layout.addWidget(self.label_loader)
        layout.addStretch()
        layout.addWidget(button_container)
        self.setWidget(widget)
        self.machine = None
        self.welcome = None
        self._welcome_text = "<html><p>Welcome!</p></html>"
        self._current_state = None
        self.setAttribute(Qt.WA_DeleteOnClose)

    def is_running(self):
        return self.machine and self.machine.isRunning()

    def show(self):
        self.setFloating(False)
        self.parent().addDockWidget(Qt.TopDockWidgetArea, self)
        if not self.isVisible():
            self.set_up_machine()
            self.machine.start()
        super().show()

    def _make_state(self, name):
        s = QState(self.machine)
        s.assignProperty(self, "current_state", name)
        return s

    def _make_welcome(self):
        welcome = self._make_state("welcome")
        begin = QState(welcome)
        finalize = QFinalState(welcome)
        welcome.setInitialState(begin)
        begin.assignProperty(self.label_msg, "text", self._welcome_text)
        begin.assignProperty(self.button_right, "text", "Start")
        begin.assignProperty(self.button_right, "visible", True)
        begin.assignProperty(self.label_loader, "visible", False)
        begin.assignProperty(self.button_left, "visible", False)
        begin.addTransition(self.button_right.clicked, finalize)
        return welcome

    def set_up_machine(self):
        self.machine = QStateMachine(self)
        self.welcome = self._make_welcome()
        self.machine.setInitialState(self.welcome)
        dead = QFinalState(self.machine)
        death = QEventTransition(self, QEvent.Close)
        death.setTargetState(dead)
        self.machine.addTransition(death)

    def get_current_state(self):
        return self._current_state

    def set_current_state(self, state):
        self._current_state = state

    current_state = Property(str, get_current_state, set_current_state)
Exemplo n.º 13
0
class LiveDemo(QDockWidget):
    """A widget for showing live demonstrations."""

    _overlay_color = QColor(255, 140, 0, 128)
    _tutorial_data_path = os.path.join(APPLICATION_PATH, "../tutorial")

    def __init__(self, window_title, parent):
        """Initializes class.

        Args:
            window_title (str)
            parent (QMainWindow)
        """
        super().__init__(window_title, parent)
        self.setObjectName(window_title)
        self.label_msg = QLabel(self)
        self.label_msg.setFont(QFont("arial,helvetica", 12))
        self.label_msg.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.label_msg.setWordWrap(True)
        self.button_left = QPushButton(self)
        self.button_right = QPushButton(self)
        button_container = QWidget(self)
        button_layout = QHBoxLayout(button_container)
        button_layout.addStretch()
        button_layout.addWidget(self.button_left)
        button_layout.addWidget(self.button_right)
        button_layout.addStretch()
        widget = QWidget(self)
        layout = QVBoxLayout(widget)
        layout.addStretch()
        layout.addWidget(self.label_msg)
        layout.addStretch()
        layout.addWidget(button_container)
        self.setWidget(widget)
        self.hide()
        self.machine = None
        self.run = None

    def is_running(self):
        return self.machine and self.machine.isRunning()

    def show(self):
        self.setFloating(False)
        self.parent().addDockWidget(Qt.TopDockWidgetArea, self)
        self.setup()
        super().show()

    def _make_welcome(self):
        welcome = QState(self.run)
        begin = QState(welcome)
        finalize = QFinalState(welcome)
        welcome.setInitialState(begin)
        begin.assignProperty(self.label_msg, "text", "Welcome!")
        begin.assignProperty(self.button_right, "text", "Start")
        begin.assignProperty(self.button_right, "visible", True)
        begin.assignProperty(self.button_left, "visible", False)
        begin.addTransition(self.button_right.clicked, finalize)
        return welcome

    def _make_abort(self):
        abort = QState(self.run)
        dead = QFinalState(self.machine)
        abort.addTransition(dead)
        return abort

    def setup(self):
        self.machine = QStateMachine(self)
        self.run = QState(self.machine)
        abort = self._make_abort()
        transition = QEventTransition(self, QEvent.Close)
        transition.setTargetState(abort)
        self.run.addTransition(transition)
        welcome = self._make_welcome()
        welcome.entered.connect(self._handle_welcome_entered)
        self.machine.setInitialState(self.run)
        self.run.setInitialState(welcome)
        self.machine.start()

    def _handle_welcome_entered(self):
        raise NotImplementedError()