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


Python Clock.stop方法代码示例

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


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

示例1: __repr__

# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import stop [as 别名]
class Mode:
    """ 
    A mode has its own clock, event manager, and components.
    A mode is a state activated and deactivated by the mode state machine.
    """

    def __repr__(self):
        return self.__class__.__name__
    def __str__(self):
        return self.__repr__()


    def __init__(self):
        """ When a mode is created, it only creates an event manager.
        The mode's components and clock are instantiated 
        when the mode is activated.
        The mode manager/MSM has to register for transition or quit callbacks 
        through set_X_callback.
        """

        # hold instances of the mode's components when the mode is activated
        self.active_components = []
        self.clock = None # instantiated by MSM
        self.em = EventManager() # each mode has its own EM


    def set_transition_callback(self, trans_evt_classes, msm_transition_cb):
        """ Set the callback to the mode state machine
        when transition events are fired by the current mode.
        """
        for ev_class in trans_evt_classes:
            self.em.subscribe(ev_class, msm_transition_cb)

    def set_quit_callback(self, msm_quit_cb):
        """ Set the MSM callback to call when the mode fires a QuitEvent. """
        self.em.subscribe(QuitEvent, msm_quit_cb)


    def activate(self, ev):
        """ Instantiate the components and clock for the mode. 
        The event passed in argument contains data sent by the previous mode.
        For example, the LevelTransitionMode sends a GameStart event
        containing the next level number to the GameMode. This way, the GameMode
        knows which level to instantiate. The GameMode sends a GameWon event
        containing the score to the LevelTransitionMode so that it can be 
        displayed.
        Small drawback: to keep the code generic, ALL the components are given 
        in argument the mode's EM and the event. Some components may not need 
        the event, but we can't know in advance, so we pass it anyway.
        """
        em = self.em
        self.active_components = [comp(em, ev) for comp in self.components]
        self.clock = Clock(em)
        self.clock.start() # returns when the clock is turned off, ie transition or quit 

        self.em.clear() # this removes the clock and MSM from the EM subscribers
        self.active_components = [] # last ref to component instances is lost
        self.clock = None


    def deactivate(self):
        """ Tell the clock to stop. 
        The mode's components will be garbage collected
        when the clock returns the hand back to the MSM. 
        """
        self.clock.stop()
开发者ID:gentimouton,项目名称:smofac,代码行数:68,代码来源:mode.py


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