mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 16:21:20 +00:00
25 lines
898 B
Python
25 lines
898 B
Python
from transitions import Machine
|
|
|
|
|
|
class Buttons:
|
|
states = ['ayy', 'bee', 'cee']
|
|
transitions = [
|
|
{'trigger': 'anchor_a', 'source': 'ayy', 'dest': 'bee'},
|
|
{'trigger': 'anchor_b', 'source': 'bee', 'dest': 'cee'},
|
|
{'trigger': 'anchor_c', 'source': 'cee', 'dest': 'ayy'},
|
|
]
|
|
|
|
def __init__(self, handler=None):
|
|
self.handler = handler
|
|
self.machine = Machine(model=self,
|
|
states=Buttons.states,
|
|
transitions=Buttons.transitions,
|
|
initial='ayy',
|
|
send_event=True,
|
|
ignore_invalid_triggers=True,
|
|
after_state_change='forward_message')
|
|
|
|
def forward_message(self, event_data):
|
|
message = event_data.kwargs.get('message')
|
|
self.handler.send_message(message)
|