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
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
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 _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_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
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_()
def _make_abort(self): abort = QState(self.run) dead = QFinalState(self.machine) abort.addTransition(dead) return abort
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)