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


Python Fysom.resolve方法代码示例

本文整理汇总了Python中fysom.Fysom.resolve方法的典型用法代码示例。如果您正苦于以下问题:Python Fysom.resolve方法的具体用法?Python Fysom.resolve怎么用?Python Fysom.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fysom.Fysom的用法示例。


在下文中一共展示了Fysom.resolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import resolve [as 别名]
class Trail:
    IDLE = 'idle'
    REGISTERED = 'registered'
    HOLD = 'hold'
    ACTIVE = 'active'

    def __init__(self, path=None):
        self.path = path
        self.store = Store()
        self._fsm = Fysom(
                initial=Trail.IDLE,
                events=[
                    ('register', Trail.IDLE, Trail.REGISTERED),
                    ('prepare', Trail.REGISTERED, Trail.HOLD),
                    ('activate', Trail.HOLD, Trail.ACTIVE),
                    ('resolve', Trail.ACTIVE, Trail.IDLE),
                    ('resolve', Trail.HOLD, Trail.IDLE),
                    ('resolve', Trail.REGISTERED, Trail.IDLE)],
                callbacks=[
                    ('onbeforeregister', self._onbeforeregister),
                    ('onregistered', self._registered),
                    ('onidle', self._onidle)])

    @property
    def status(self):
        return self._fsm.current

    def onchangestate(self, on_change):
        self._fsm.onchangestate = on_change

    def register(self):
        self._fsm.register()

    def prepare(self):
        self._fsm.prepare()

    def activate(self):
        self._fsm.activate()

    def resolve(self):
        self._fsm.resolve()

    def _onbeforeregister(self, e):
        self.store.register(self.path)

    def _registered(self, e):
        self.prepare()

    def _onidle(self, e):
        if e.src is not "none":
            self.store.unregister(self.path)
开发者ID:stefan-walluhn,项目名称:RPi.TC,代码行数:53,代码来源:trail.py

示例2: BaseExitSection

# 需要导入模块: from fysom import Fysom [as 别名]
# 或者: from fysom.Fysom import resolve [as 别名]
class BaseExitSection(object):

    def __init__(self):
        self._can_depart = False
        self._fsm = Fysom(
            initial=Section.IDLE,
            final=Section.IDLE,
            events=[
                ('wait', Section.IDLE, Section.WAITING),
                ('depart', Section.IDLE, Section.DEPARTING),
                ('depart', Section.WAITING, Section.DEPARTING),
                ('resolve', Section.DEPARTING, Section.IDLE)],
            callbacks=[
                ('onbeforedepart', self._onbeforedepart),
                ('ondepart', self.__ondepart__)])

    @property
    def status(self):
        return self._fsm.current

    @property
    def can_depart(self):
        return self._can_depart

    def request_depart(self):
        try:
            self._fsm.depart()
        except Canceled:
            self._fsm.wait()

    def depart(self):
        self._can_depart = True
        if self.status == Section.WAITING:
            self._fsm.depart()

    def departed(self):
        self._fsm.resolve()

    def _onbeforedepart(self, e):
        return self.can_depart

    def __ondepart__(self, e):
        self._can_depart = False
        self._ondepart(e)

    def _ondepart(self, e):
        pass
开发者ID:stefan-walluhn,项目名称:RPi.TC,代码行数:49,代码来源:__init__.py


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