![]() |
Belle II Software
release-06-00-14
|
Public Member Functions | |
def | __init__ (self, states=None, initial_state="default_initial") |
def | add_state (self, state, enter=None, exit=None) |
def | initial_state (self) |
def | initial_state (self, state) |
def | state (self) |
def | state (self, state) |
def | add_transition (self, trigger, source, dest, conditions=None, before=None, after=None) |
def | __getattr__ (self, name, **kwargs) |
def | get_transitions (self, source) |
def | get_transition_dict (self, state, transition) |
def | save_graph (self, filename, graphname) |
Static Public Member Functions | |
def | default_condition (**kwargs) |
Public Attributes | |
states | |
Valid states for this machine. | |
initial_state | |
Pointless docstring since it's a property. | |
transitions | |
Allowed transitions between states. | |
state | |
Current State of machine. | |
Private Member Functions | |
def | _trigger (self, transition_name, transition_dict, **kwargs) |
Static Private Member Functions | |
def | _callback (func, **kwargs) |
Private Attributes | |
_initial_state | |
Actual attribute holding initial state for this machine. | |
_state | |
Actual attribute holding the Current state. More... | |
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 framwork 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 138 of file state_machines.py.
def __init__ | ( | self, | |
states = None , |
|||
initial_state = "default_initial" |
|||
) |
Basic Setup of states and initial_state.
Reimplemented in AlgorithmMachine.
Definition at line 165 of file state_machines.py.
def __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 300 of file state_machines.py.
|
staticprivate |
Calls a condition/before/after.. function using arguments passed (or not).
Definition at line 336 of file state_machines.py.
|
private |
Runs the transition logic. Callbacks are evaluated in the order: conditions -> before -> <new state set here> -> after.
Definition at line 312 of file state_machines.py.
def 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 187 of file state_machines.py.
def 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 transtion 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 258 of file state_machines.py.
|
static |
Method to always return True.
Definition at line 252 of file state_machines.py.
def get_transition_dict | ( | self, | |
state, | |||
transition | |||
) |
Returns the transition dictionary for a state and transition out of it.
Definition at line 353 of file state_machines.py.
def get_transitions | ( | self, | |
source | |||
) |
Returns allowed transitions from a given state.
Definition at line 342 of file state_machines.py.
def 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 203 of file state_machines.py.
def initial_state | ( | self, | |
state | |||
) |
Definition at line 210 of file state_machines.py.
def save_graph | ( | self, | |
filename, | |||
graphname | |||
) |
Does a simple dot file creation to visualise states and transiitons.
Definition at line 364 of file state_machines.py.
def 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 221 of file state_machines.py.
def state | ( | self, | |
state | |||
) |
Definition at line 230 of file state_machines.py.
|
private |
Actual attribute holding the Current state.
Current state (private)
Definition at line 183 of file state_machines.py.