本文整理汇总了Python中mpf.system.tasks.DelayManager.clear方法的典型用法代码示例。如果您正苦于以下问题:Python DelayManager.clear方法的具体用法?Python DelayManager.clear怎么用?Python DelayManager.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpf.system.tasks.DelayManager
的用法示例。
在下文中一共展示了DelayManager.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mode
# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import clear [as 别名]
#.........这里部分代码省略.........
self.start_event_kwargs = dict()
if self.start_callback:
self.start_callback()
self.log.debug("Mode Start process complete.")
def stop(self, callback=None, **kwargs):
"""Stops this mode.
Args:
**kwargs: Catch-all since this mode might start from events with
who-knows-what keyword arguments.
Warning: You can safely call this method, but do not override it in your
mode code. If you want to write your own mode code by subclassing Mode,
put whatever code you want to run when this mode stops in the
mode_stop method which will be called automatically.
"""
if not self._active:
return
self.mode_stop_kwargs = kwargs
self.log.debug("Mode Stopping.")
self._remove_mode_switch_handlers()
self.stop_callback = callback
self._kill_timers()
self.delay.clear()
# self.machine.events.remove_handler(self.stop)
# todo is this ok here? Or should we only remove ones that we know this
# mode added?
self.machine.events.post_queue(event="mode_" + self.name + "_stopping", callback=self._stopped)
def _stopped(self):
self.log.debug("Mode Stopped.")
self.priority = 0
self.active = False
for item in self.stop_methods:
try:
item[0](item[1])
except TypeError:
try:
item()
except TypeError:
pass
self.stop_methods = list()
self.machine.events.post("mode_" + self.name + "_stopped", callback=self._mode_stopped_callback)
if self._mode_start_wait_queue:
self.log.debug("Clearing wait queue")
self._mode_start_wait_queue.clear()
self._mode_start_wait_queue = None
示例2: MachineMode
# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import clear [as 别名]
class MachineMode(object):
""" A machine mode represents as special modes, the idea is there's only
one at a time.
You can specify an order so that when one ends, the next one starts.
Examples:
*Attract
*Game
*Match
*Highscore Entry
*Service
The idea is the machine modes will control the buttons since they do
different things in different modes. ("Buttons" versus "Switches" in this
case. Buttons are things that players can control, like coin switches,
control panel buttons, flippers, start, plunge, etc.)
"""
def __init__(self, machine, name):
self.log = logging.getLogger(__name__)
self.machine = machine
self.task = None
self.name = name
self.delays = DelayManager()
self.registered_event_handlers = list()
self.registered_switch_handlers = list()
def start(self):
"""Starts this machine mode. """
self.log.debug("Mode started")
self.active = True
self.task = Task.Create(self.tick, sleep=0)
self.machine.events.post('machineflow_' + self.name + '_start')
def stop(self):
"""Stops this machine mode. """
self.log.debug("Stopping...")
self.ative = False
# clear delays
self.log.debug("Removing scheduled delays")
self.delays.clear()
# deregister event handlers
self.log.debug("Removing event handlers")
self.machine.events.remove_handlers_by_keys(self.registered_event_handlers)
self.registered_event_handlers = list()
# deregister switch handlers
self.log.debug("Removing switch handlers")
for handler in self.registered_switch_handlers:
self.machine.switch_controller.remove_switch_handler(
switch_name=handler['switch_name'],
callback=handler['callback'],
state=handler['state'],
ms=handler['ms'])
self.registered_switch_handlers = list()
self.log.debug("Stopped")
self.machine.events.post('machineflow_' + self.name + '_stop')
def tick(self):
"""Most likely you'll just copy this entire method to your mode
subclass. No need for super().
"""
while self.active:
# do something here
yield