sample_python_automat.py 466 B

123456789101112131415161718192021222324252627
  1. from automat import MethodicalMachine
  2. class Led(object):
  3. _machine = MethodicalMachine()
  4. @_machine.state()
  5. def led_on(self):
  6. "led is on"
  7. @_machine.state(initial=True)
  8. def led_off(self):
  9. "led is off"
  10. @_machine.input()
  11. def turn_on(self):
  12. "turn the led on"
  13. @_machine.output()
  14. def _light(self):
  15. print("light")
  16. led_off.upon(turn_on, enter=led_on, outputs=[_light])
  17. led = Led()
  18. led.turn_on()