![]() |
Belle II Software development
|
Public Member Functions | |
| __init__ (self, states=None, initial_state="default_initial") | |
| add_state (self, state, enter=None, exit=None) | |
| initial_state (self) | |
| initial_state (self, state) | |
| state (self) | |
| state (self, state) | |
| add_transition (self, trigger, source, dest, conditions=None, before=None, after=None) | |
| __getattr__ (self, name, **kwargs) | |
| get_transitions (self, source) | |
| get_transition_dict (self, state, transition) | |
| save_graph (self, filename, graphname) | |
Static Public Member Functions | |
| default_condition (**kwargs) | |
Public Attributes | |
| dict | states = {} |
| Valid states for this machine. | |
| initial_state = initial_state | |
| Pointless docstring since it's a property. | |
| transitions = defaultdict(list) | |
| Allowed transitions between states. | |
| state = dest | |
| Current State of machine. | |
Protected Member Functions | |
| _trigger (self, transition_name, transition_dict, **kwargs) | |
Static Protected Member Functions | |
| _callback (func, **kwargs) | |
Protected Attributes | |
| dict | _initial_state = State(initial_state) |
| Actual attribute holding initial state for this machine. | |
| dict | _state = self.initial_state |
| Actual attribute holding the Current state. | |
Parameters: states (list[str]): A list of possible states of the machine. initial_state (str): Base class for a final state machine wrapper. Implements the framework that a more complex machine can inherit from. The `transitions` attribute is a dictionary of trigger name keys, each value of which is another dictionary of 'source' states, 'dest' states, and 'conditions' methods. 'conditions' should be a list of callables or a single one. A transition is valid if it goes from an allowed state to an allowed state. Conditions are optional but must be a callable that returns True or False based on some state of the machine. They cannot have input arguments currently. Every condition/before/after callback function MUST take ``**kwargs`` as the only argument (except ``self`` if it's a class method). This is because it's basically impossible to determine which arguments to pass to which functions for a transition. Therefore this machine just enforces that every function should simply take ``**kwargs`` and use the dictionary of arguments (even if it doesn't need any arguments). This also means that if you call a trigger with arguments e.g. ``machine.walk(speed=5)`` you MUST use the keyword arguments rather than positional ones. So ``machine.walk(5)`` will *not* work.
Definition at line 144 of file state_machines.py.
| __init__ | ( | self, | |
| states = None, | |||
| initial_state = "default_initial" ) |
Basic Setup of states and initial_state.
Definition at line 171 of file state_machines.py.
| __getattr__ | ( | self, | |
| name, | |||
| ** | kwargs ) |
Allows us to create a new method for each trigger on the fly. If there is no trigger name in the machine to match, then the normal AttributeError is called.
Definition at line 306 of file state_machines.py.
|
staticprotected |
Calls a condition/before/after.. function using arguments passed (or not).
Definition at line 344 of file state_machines.py.
|
protected |
Runs the transition logic. Callbacks are evaluated in the order: conditions -> before -> <new state set here> -> after.
Definition at line 320 of file state_machines.py.
| add_state | ( | self, | |
| state, | |||
| enter = None, | |||
| exit = None ) |
Adds a single state to the list of possible ones. Should be a unique string or a State object with a unique name.
Definition at line 193 of file state_machines.py.
| add_transition | ( | self, | |
| trigger, | |||
| source, | |||
| dest, | |||
| conditions = None, | |||
| before = None, | |||
| after = None ) |
Adds a single transition to the dictionary of possible ones. Trigger is the method name that begins the transition between the source state and the destination state. The condition is an optional function that returns True or False depending on the current state/input.
Definition at line 264 of file state_machines.py.
|
static |
Method to always return True.
Definition at line 258 of file state_machines.py.
| get_transition_dict | ( | self, | |
| state, | |||
| transition ) |
Returns the transition dictionary for a state and transition out of it.
Definition at line 361 of file state_machines.py.
| get_transitions | ( | self, | |
| source ) |
Returns allowed transitions from a given state.
Definition at line 350 of file state_machines.py.
| initial_state | ( | self | ) |
The initial state of the machine. Needs a special property to prevent trying to run on_enter callbacks when set.
Definition at line 209 of file state_machines.py.
| initial_state | ( | self, | |
| state ) |
Definition at line 216 of file state_machines.py.
| save_graph | ( | self, | |
| filename, | |||
| graphname ) |
Does a simple dot file creation to visualise states and transiitons.
Definition at line 372 of file state_machines.py.
| state | ( | self | ) |
The current state of the machine. Actually a `property` decorator. It will call the exit method of the
current state and enter method of the new one. To get around the behaviour e.g. for setting initial states,
either use the `initial_state` property or directly set the _state attribute itself (at your own risk!).
Definition at line 227 of file state_machines.py.
| state | ( | self, | |
| state ) |
Definition at line 236 of file state_machines.py.
|
protected |
Actual attribute holding initial state for this machine.
Definition at line 186 of file state_machines.py.
|
protected |
Actual attribute holding the Current state.
Definition at line 189 of file state_machines.py.
| initial_state = initial_state |
Pointless docstring since it's a property.
Definition at line 182 of file state_machines.py.
| state = dest |
Current State of machine.
Definition at line 336 of file state_machines.py.
| dict states = {} |
Valid states for this machine.
Definition at line 176 of file state_machines.py.
| transitions = defaultdict(list) |
Allowed transitions between states.
Definition at line 191 of file state_machines.py.