コード例 #1
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()
コード例 #2
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_()
コード例 #3
0
ファイル: bug_416.py プロジェクト: BadSingleton/pyside2
    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)
コード例 #4
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)
コード例 #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.assertTrue(isinstance(configuration, set))
        self.assertTrue(s1 in configuration)
コード例 #6
0
from PySide2.QtCore import QStateMachine, QState

mach = QStateMachine()
state = QState(mach)
print(state.machine())
コード例 #7
0
    def _make_good_bye(self):
        good_bye = QState(self.run)
        begin = QState(good_bye)
        finalize = QFinalState(good_bye)
        good_bye.assignProperty(
            self.label_msg, "text",
            "<html>That's all for now. Hope you liked it.</html>")
        good_bye.assignProperty(self.button_left, "visible", False)
        good_bye.assignProperty(self.button_right, "enabled", True)
        good_bye.assignProperty(self.button_right, "text", "Close")

        good_bye.setInitialState(begin)
        begin.addTransition(self.button_right.clicked, finalize)
        return good_bye
コード例 #8
0
    def _make_select_more(self):
        select_more = QState(self.run)
        begin = QState(select_more)
        simulate = QState(select_more)
        finalize = QFinalState(select_more)
        begin.assignProperty(self.parent().ui.dockWidget_object_tree,
                             "visible", True)
        sticky = self.parent().qsettings.value("appSettings/stickySelection",
                                               defaultValue="false")
        note = " (by holding down the <b>Ctrl</b> key)" if sticky == "false" else ""
        text = f"""
            <html>
            <p>Selecting multiple items{note} makes things more interesting.</p>
            <p>Press <b>Show</b> to see it in action.</p>
            </html>
        """
        begin.assignProperty(self.label_msg, "text", text)
        begin.assignProperty(self.button_right, "text", "Show")
        begin.assignProperty(self.button_right, "enabled", True)
        simulate.assignProperty(self.parent().ui.dockWidget_object_tree,
                                "visible", True)
        simulate.assignProperty(self.button_right, "enabled", False)

        select_more.setInitialState(begin)
        transition = begin.addTransition(self.button_right.clicked, simulate)
        animation = SelectionAnimation(self.parent(),
                                       command=QItemSelectionModel.Select)
        transition.addAnimation(animation)
        simulate.addTransition(animation.finished, finalize)
        return select_more
コード例 #9
0
    def _make_select_one(self):
        select_one = QState(self.run)
        begin = QState(select_one)
        simulate = QState(select_one)
        finalize = QFinalState(select_one)
        begin.assignProperty(self.parent().ui.dockWidget_object_tree,
                             "visible", True)
        text = """
            <html>
            <p>Selecting items in the object tree automatically triggers
            graph generation.</b><br />
            <p>Press <b>Show</b> to see it in action.</p>
            </html>
        """
        begin.assignProperty(self.label_msg, "text", text)
        begin.assignProperty(self.button_right, "text", "Show")
        begin.assignProperty(self.button_right, "enabled", True)
        simulate.assignProperty(self.parent().ui.dockWidget_object_tree,
                                "visible", True)
        simulate.assignProperty(self.button_right, "enabled", False)

        select_one.setInitialState(begin)
        transition = begin.addTransition(self.button_right.clicked, simulate)
        animation = SelectionAnimation(
            self.parent(), command=QItemSelectionModel.ClearAndSelect)
        transition.addAnimation(animation)
        simulate.addTransition(animation.finished, finalize)
        return select_one
コード例 #10
0
 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
コード例 #11
0
 def _make_state(self, name):
     s = QState(self.machine)
     s.assignProperty(self, "current_state", name)
     return s
コード例 #12
0
 def _make_abort(self):
     abort = QState(self.run)
     dead = QFinalState(self.machine)
     abort.addTransition(dead)
     return abort
コード例 #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()
コード例 #14
0
class HumanMatchingStateMachine(QStateMachine):
    initial_to_first_person = Signal()
    first_person_to_tracking = Signal()
    prediction_to_prediction = Signal()
    prediction_to_data_association = Signal()
    data_association_to_data_update = Signal()
    data_update_to_prediction = Signal()

    def __init__(self, parent):
        super(HumanMatchingStateMachine, self).__init__()
        self._parent = parent
        self._test_timer = QTimer()
        self._prediction_timer = QTimer()

        self._initial_state = QState()

        self._first_person_state = QState()

        self._tracking_state = QState()

        self._prediction_state = QState(self._tracking_state)
        self._data_association_state = QState(self._tracking_state)
        self._data_update_state = QState(self._tracking_state)

        self._final_state = QFinalState()

        self._tracking_state.setInitialState(self._prediction_state)

        self.addState(self._initial_state)
        self.addState(self._first_person_state)
        self.addState(self._tracking_state)
        # self.addState(self._prediction_state)
        # self.addState(self._data_association_state)
        # self.addState(self._data_update_state)
        self.setInitialState(self._initial_state)

        self._initial_state.addTransition(self.initial_to_first_person,
                                          self._first_person_state)
        self._first_person_state.addTransition(self.first_person_to_tracking,
                                               self._tracking_state)
        self._prediction_state.addTransition(self._test_timer.timeout,
                                             self._prediction_state)
        self._prediction_state.addTransition(
            self.prediction_to_data_association, self._data_association_state)
        self._data_association_state.addTransition(
            self.data_association_to_data_update, self._data_update_state)
        self._data_update_state.addTransition(self.data_update_to_prediction,
                                              self._prediction_state)

        self._initial_state.entered.connect(self._parent.initial_state_entered)
        self._first_person_state.entered.connect(
            self._parent.first_person_state_entered)
        self._prediction_state.entered.connect(
            self._parent.prediction_state_entered)
        self._data_association_state.entered.connect(
            self._parent.data_association_state_entered)
        self._data_update_state.entered.connect(
            self._parent.data_update_state_entered)

        # self._initial_state.addTransition(self, SIGNAL('new_humans_signal()'), self._first_person_state)
        # self._first_person_state.addTransition(self, SIGNAL('first_humans_updated_signal()'), self._tracking_state)
        # self._prediction_state.addTransition(self._prediction_timer, SIGNAL('timeout()'), self._prediction_state)
        # self._prediction_state.addTransition(self, SIGNAL('new_humans_signal()'), self._data_association_state)
        # self._data_association_state.addTransition(self._test_timer, SIGNAL('timeout()'), self._data_update_state)

        # self._data_association_state.addTransition(self._test_timer, SIGNAL('timeout()'), self._data_update_state)
        # self._data_update_state.addTransition(self._test_timer, SIGNAL('timeout()'), self._prediction_state)

        # self._initial_state.entered.connect(self._initial_state_method)
        # self._first_person_state.entered.connect(self._first_person_state_method)
        # self._prediction_state.entered.connect(self._prediction_state_method)
        # self._data_association_state.entered.connect(self._data_association_state_method)
        # self._data_update_state.entered.connect(self._data_update_state_method)

        self._test_timer.start(1000 / 30)