Ejemplo n.º 1
0
    'trigger': 'sublimate',
    'source': 'solid',
    'dest': 'gas',
    'unless': 'is_not_valid'
}, {
    'trigger': 'ionize',
    'source': 'gas',
    'dest': 'plasma',
    'conditions': ['is_valid', 'is_also_valid']
}]
states = [
    'solid', 'liquid', {
        'name': 'gas',
        'on_exit': ['resume', 'notify']
    }, {
        'name': 'plasma',
        'on_enter': 'alert',
        'on_exit': 'resume'
    }
]

model = Matter()
machine = GraphMachine(model=model,
                       states=states,
                       transitions=transitions,
                       show_auto_transitions=True,
                       **extra_args)
machine.add_state('aaa')
# model.machine.add_state('aaa')
model.get_graph().draw('my_state_diagram.png', prog='dot')
Ejemplo n.º 2
0
                  states=states,
                  transitions=transitions,
                  initial="first")

# method to do transition
print(life_bot.state)

life_bot.go_to_second()
life_bot.go_to_third()

print(life_bot.state)

life_bot.to_first()
print(life_bot.state)

life_bot.trigger("go_to_second")
print(life_bot.state)
life_bot.trigger("go_to_third")
print(life_bot.state)

machine.set_state("first")
print(life_bot.state)

# add state and transitions
machine.add_state("red")
machine.add_states(["green", "blue"])

# alternate machine.add_transition(trigger= ?, source=?, dest=?)
# machine.add_transition("r_to_b", "red", "blue")
machine.add_transition("other_to_r", ["blue", "green"], "red")