本文整理汇总了Python中transitions.Machine.on_enter_gas方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.on_enter_gas方法的具体用法?Python Machine.on_enter_gas怎么用?Python Machine.on_enter_gas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transitions.Machine
的用法示例。
在下文中一共展示了Machine.on_enter_gas方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Matter
# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import on_enter_gas [as 别名]
from transitions import Machine, State
# Our old Matter class, now with a couple of new methods we
# can trigger when entering or exit states.
class Matter(object):
def say_hello(self):
print("hello, new state!")
def say_goodbye(self):
print("goodbye, old state!")
lump = Matter()
# Same states as above, but now we give StateA an exit callback
states = [
State(name='solid', on_exit=['say_goodbye']),
'liquid',
#State(name='gas', on_enter=['say_hello']),
{ 'name': 'gas' }
]
machine = Machine(lump, states=states)
machine.add_transition('sublimate', 'solid', 'gas')
# Callbacks can also be added after initialization using
# the dynamically added on_enter_ and on_exit_ methods.
# Note that the initial call to add the callback is made
# on the Machine and not on the model.
machine.on_enter_gas('say_hello')
# Test out the callbacks...
machine.set_state('solid')
lump.sublimate()