当前位置: 首页>>代码示例>>Python>>正文


Python Machine.on_enter_gas方法代码示例

本文整理汇总了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()
开发者ID:jaquinonesg,项目名称:SMA_exp,代码行数:33,代码来源:callbacks.py


注:本文中的transitions.Machine.on_enter_gas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。