Example #1
0
 def __init__(self, touchpad, parent=None):
     QStateMachine.__init__(self, parent)
     self.touchpad = touchpad
     self._touchpad_wrapper = TouchpadQtWrapper(self.touchpad, self)
     # setup monitoring objects
     self._monitors = {'mouses': MouseDevicesManager(self),
                       'keyboard': create_keyboard_monitor(self)}
     self._enabled_monitors = set()
     # setup the states:
     self.states = {}
     for name, touchpad_off in self._STATE_NAMES.iteritems():
         state = QState(self)
         state.setObjectName(name)
         state.assignProperty(self._touchpad_wrapper, 'off', touchpad_off)
         self.states[name] = state
     # setup the initial state
     self.setInitialState(self.states['on'])
     # setup the transitions
     self.transitions = defaultdict(list)
     # mouse management transitions
     for state in ('on', 'temporarily_off'):
         self._add_transition(
             state, 'off', self._monitors['mouses'].firstMousePlugged)
     self._add_transition(
         'off', 'on', self._monitors['mouses'].lastMouseUnplugged)
     # keyboard management transitions
     self._add_transition('on', 'temporarily_off',
                          self._monitors['keyboard'].typingStarted)
     self._add_transition('temporarily_off', 'on',
                          self._monitors['keyboard'].typingStopped)
     # start monitors
     self.initialState().entered.connect(self._start_stop_monitors)
     # stop monitors if the state machine is stopped
     self.stopped.connect(self._stop_all_monitors)
Example #2
0
    def _add_state(self, state_name, state_action=_action_widget_textEdit):
        """

        :param state_name:
        :param state_action:
        :return:
        """
        id_state = self._generate_id_for_state(state_name)
        state = self._states[id_state] = QState()
        state.setObjectName(id_state)
        #
        state_action(self, state_name)
        # Add State to Machine
        self._qsm.addState(state)
Example #3
0
    def __init__(self, parent=None, event_time=None):
        if parent is None:
            # grab from current exp
            parent = exp._current_parent
        # can't have children other than those we define, so must be
        # set up as ExclusiveStates
        QState.__init__(self, QState.ExclusiveStates, parent=parent)
        # set up dummy initial and final child states
        self._iState = QState(parent=self)
        self._fState = QFinalState(parent=self)
        self.setInitialState(self._iState)
        self._iState.addTransition(self._iState.finished, self._fState)

        # add to a timeline and save time
        self.parent = parent
        if event_time is None:
            event_time = self.parent.cur_event_time
        self._event_time = event_time
        parent.timeline.add_state(self, self._event_time)