mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 16:31:21 +00:00
27 lines
946 B
Python
27 lines
946 B
Python
from typing import List
|
|
|
|
from transitions import Machine
|
|
|
|
from tfw.components.mixins.callback_mixin import CallbackMixin
|
|
|
|
|
|
class FSMBase(CallbackMixin):
|
|
states, transitions = [], []
|
|
|
|
def __init__(self, initial: str = None, accepted_states: List[str] = None):
|
|
CallbackMixin.__init__(self)
|
|
self.accepted_states = accepted_states or [self.states[-1]]
|
|
self.machine = Machine(model=self,
|
|
states=self.states,
|
|
transitions=self.transitions,
|
|
initial=initial or self.states[0],
|
|
send_event=True,
|
|
ignore_invalid_triggers=True,
|
|
after_state_change='execute_callbacks')
|
|
|
|
def execute_callbacks(self, event_data):
|
|
self._execute_callbacks(event_data.kwargs)
|
|
|
|
def is_solved(self):
|
|
return self.state in self.accepted_states
|