mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-09 02:37:17 +00:00
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
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 # pylint: disable=no-member
|