9 _currently_opened_container =
None 12 super(StateMachine, self).
__init__(*args, **kwargs)
24 StateMachine._currently_opened_container = self
37 return iter(state.name
for state
in self.
_states)
42 def add(label, state, transitions, remapping=None):
43 self = StateMachine.get_opened_container()
45 raise StateMachineError(
"No container openend, activate one first by: 'with state_machine:'")
47 raise StateMachineError(
"The label %s has already been added to this state machine!" % label)
49 raise StateMachineError(
"The label %s is an outcome of this state machine!" % label)
51 self._states.append(state)
57 state.set_parent(self)
61 return StateMachine._currently_opened_container
65 def spin(self, userdata=None):
68 outcome = self.
execute(userdata)
69 if outcome
is not None:
85 self._current_state.sleep()
89 input_keys=self._current_state.input_keys, output_keys=self._current_state.output_keys
91 outcome = self._current_state.execute(userdata)
92 if outcome
is not None:
94 target = self.
_transitions[self._current_state.name][outcome]
97 raise StateError(
"Returned outcome '%s' is not registered as transition!" % str(e))
117 return self.current_state.name
128 return self.initial_state.name
133 return self._current_state.sleep_duration
141 return list(self._labels.keys()) + self.
outcomes 144 for transitions
in self._transitions.values():
145 for transition_target
in transitions.values():
_previously_opened_container
def assert_consistent_transitions(self)
def _execute_current_state(self)
def __getitem__(self, label)
def execute(self, userdata)
def initial_state_label(self)
def __contains__(self, label)
def current_state_label(self)
def add(label, state, transitions, remapping=None)
def spin(self, userdata=None)
def get_opened_container()
def __init__(self, args, kwargs)
def execute(self, userdata)