本文整理匯總了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