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


Python DelayManager.remove方法代码示例

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


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

示例1: BallSave

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]
class BallSave(Device):

    config_section = "ball_saves"
    collection = "ball_saves"
    class_label = "ball_save"

    def __init__(self, machine, name, config, collection=None, validate=True):
        super(BallSave, self).__init__(machine, name, config, collection, validate=validate)

        self.delay = DelayManager()

        self.source_playfield = self.config["source_playfield"]

    def enable(self, **kwargs):
        self.log.debug("Enabling...")

        # Enable shoot again
        self.machine.events.add_handler("ball_drain", self._ball_drain_shoot_again, priority=1000)

        if self.config["auto_disable_time"] > 0:
            self.delay.add("disable_shoot_again", self.config["auto_disable_time"], self.disable)

        self.machine.events.post("ball_save_" + self.name + "_enabled")

    def disable(self, **kwargs):
        self.log.debug("Disabling...")
        self.machine.events.remove_handler(self._ball_drain_shoot_again)
        self.delay.remove("disable_shoot_again")

        self.machine.events.post("ball_save_" + self.name + "_disabled")

    def _ball_drain_shoot_again(self, balls, **kwargs):
        if balls <= 0:
            return {"balls": balls}

        self.machine.events.post("ball_save_" + self.name + "_shoot_again", balls=balls)

        self.log.debug("Ball drained during ball save. Requesting a new one.")
        self.source_playfield.add_ball(balls=balls)
        return {"balls": 0}
开发者ID:jherrm,项目名称:mpf,代码行数:42,代码来源:ball_save.py

示例2: Playfield

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]
class Playfield(BallDevice):

    config_section = 'playfields'
    collection = 'playfields'
    class_label = 'playfield'

    # noinspection PyMissingConstructor
    def __init__(self, machine, name, config, collection=None, validate=True):
        self.log = logging.getLogger('playfield')

        self.machine = machine
        self.name = name.lower()
        self.tags = list()
        self.label = None
        self.debug = False
        self.config = dict()

        if validate:
            self.config = self.machine.config_processor.process_config2(
                self.config_section, config, self.name)
        else:
            self.config = config

        if self.config['debug']:
            self.debug = True
            self.log.debug("Enabling debug logging for this device")
            self.log.debug("Configuring device with settings: '%s'", config)

        self.tags = self.config['tags']
        self.label = self.config['label']

        self.delay = DelayManager()

        self.machine.ball_devices[name] = self

        if 'default' in self.config['tags']:
            self.machine.playfield = self

        # Attributes
        self._balls = 0
        self.num_balls_requested = 0
        self.queued_balls = list()
        self._playfield = True

        # Set up event handlers

        # Watch for balls added to the playfield
        for device in self.machine.ball_devices:
            for target in device.config['eject_targets']:
                if target == self.name:
                    self.machine.events.add_handler(
                        event='balldevice_' + device.name +
                        '_ball_eject_success',
                        handler=self._source_device_eject_success)
                    self.machine.events.add_handler(
                        event='balldevice_' + device.name +
                        '_ball_eject_failed',
                        handler=self._source_device_eject_failed)
                    self.machine.events.add_handler(
                        event='balldevice_' + device.name +
                        '_ball_eject_attempt',
                        handler=self._source_device_eject_attempt)
                    break

        # Watch for balls removed from the playfield
        self.machine.events.add_handler('balldevice_captured_from_' + self.name,
                                        self._ball_removed_handler)

        # Watch for any switch hit which indicates a ball on the playfield
        self.machine.events.add_handler('sw_' + self.name + '_active',
                                        self.playfield_switch_hit)

        self.machine.events.add_handler('init_phase_2',
                                        self._initialize)

    def _initialize(self):
        self.ball_controller = self.machine.ball_controller

        for device in self.machine.playfield_transfers:
            if device.config['eject_target'] == self.name:
                self.machine.events.add_handler(
                    event='balldevice_' + device.name +
                    '_ball_eject_success',
                    handler=self._source_device_eject_success)
                self.machine.events.add_handler(
                    event='balldevice_' + device.name +
                    '_ball_eject_attempt',
                    handler=self._source_device_eject_attempt)

    @property
    def balls(self):
        return self._balls

    @balls.setter
    def balls(self, balls):

        prior_balls = self._balls
        ball_change = balls - prior_balls

        if ball_change:
#.........这里部分代码省略.........
开发者ID:qcapen,项目名称:mpf,代码行数:103,代码来源:playfield.py

示例3: BallDevice

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]

#.........这里部分代码省略.........
        return self.balls

        # todo look at upstream devices

    def configure_eject_targets(self, config=None):
        new_list = list()

        for target in self.config['eject_targets']:
            new_list.append(self.machine.ball_devices[target])

        self.config['eject_targets'] = new_list

    def _source_device_eject_attempt(self, balls, target, **kwargs):
        # A source device is attempting to eject a ball.
        if target == self:
            if self.debug:
                self.log.debug("Waiting for %s balls", balls)
            self.num_balls_in_transit += balls

            if self.num_balls_requested:
                # set event handler to watch for receiving a ball
                self.machine.events.add_handler('balldevice_' + self.name +
                                                '_ball_enter',
                                                self._requested_ball_received,
                                                priority=1000)

    def _source_device_eject_failed(self, balls, target, **kwargs):
        # A source device failed to eject a ball.
        if target == self:
            self.num_balls_in_transit -= balls

            if self.num_balls_in_transit <= 0:
                self.num_balls_in_transit = 0
                self.machine.events.remove_handler(self._requested_ball_received)

    def _initialize(self):
        # convert names to objects

        # make sure the eject timeouts list matches the length of the eject targets
        if (len(self.config['eject_timeouts']) <
                len(self.config['eject_targets'])):
            self.config['eject_timeouts'] += [None] * (
                len(self.config['eject_targets']) -
                len(self.config['eject_timeouts']))

        timeouts_list = self.config['eject_timeouts']
        self.config['eject_timeouts'] = dict()

        for i in range(len(self.config['eject_targets'])):
            self.config['eject_timeouts'][self.config['eject_targets'][i]] = (
                Timing.string_to_ms(timeouts_list[i]))
        # End code to create timeouts list -------------------------------------

        # Register switch handlers with delays for entrance & exit counts
        for switch in self.config['ball_switches']:
            self.machine.switch_controller.add_switch_handler(
                switch_name=switch.name, state=1,
                ms=self.config['entrance_count_delay'],
                callback=self.count_balls)
        for switch in self.config['ball_switches']:
            self.machine.switch_controller.add_switch_handler(
                switch_name=switch.name, state=0,
                ms=self.config['exit_count_delay'],
                callback=self.count_balls)
        for switch in self.config['ball_switches']:
            self.machine.switch_controller.add_switch_handler(
开发者ID:jherrm,项目名称:mpf,代码行数:70,代码来源:ball_device.py

示例4: ModeTimer

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]

#.........这里部分代码省略.........
            elif entry["action"] == "jump":
                handler = self.set_current_time
                kwargs = {"timer_value": entry["value"]}

            elif entry["action"] == "start":
                handler = self.start

            elif entry["action"] == "stop":
                handler = self.stop

            elif entry["action"] == "reset":
                handler = self.reset

            elif entry["action"] == "restart":
                handler = self.restart

            elif entry["action"] == "pause":
                handler = self.pause
                kwargs = {"timer_value": entry["value"]}

            elif entry["action"] == "set_tick_interval":
                handler = self.set_tick_interval
                kwargs = {"timer_value": entry["value"]}

            elif entry["action"] == "change_tick_interval":
                handler = self.change_tick_interval
                kwargs = {"change": entry["value"]}

            if kwargs:
                self.event_keys.add(self.machine.events.add_handler(entry["event"], handler, **kwargs))
            else:
                self.event_keys.add(self.machine.events.add_handler(entry["event"], handler))

    def _remove_control_events(self):

        if self.debug:
            self.log.debug("Removing control events")

        for key in self.event_keys:
            self.machine.events.remove_handler_by_key(key)

    def reset(self, **kwargs):
        """Resets this timer based to the starting value that's already been
        configured. Does not start or stop the timer.

        Args:
            **kwargs: Not used in this method. Only exists since this method is
                often registered as an event handler which may contain
                additional keyword arguments.
        """

        if self.debug:
            self.log.debug("Resetting timer. New value: %s", self.start_value)

        self.set_current_time(self.start_value)

    def start(self, **kwargs):
        """Starts this timer based on the starting value that's already been
        configured. Use set_current_time() if you want to set the starting time
        value.

        Args:
            **kwargs: Not used in this method. Only exists since this method is
                often registered as an event handler which may contain
                additional keyword arguments.
        """
开发者ID:qcapen,项目名称:mpf,代码行数:70,代码来源:mode.py

示例5: ModeTimer

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]

#.........这里部分代码省略.........
            elif entry['action'] == 'subtract':
                handler = self.subtract_time
                kwargs = {'timer_value': entry['value']}

            elif entry['action'] == 'jump':
                handler = self.set_current_time
                kwargs = {'timer_value': entry['value']}

            elif entry['action'] == 'start':
                handler = self.start

            elif entry['action'] == 'stop':
                handler = self.stop

            elif entry['action'] == 'pause':
                handler = self.pause
                kwargs = {'timer_value': entry['value']}

            elif entry['action'] == 'set_tick_interval':
                handler = self.set_tick_interval
                kwargs = {'timer_value': entry['value']}

            elif entry['action'] == 'change_tick_interval':
                handler = self.change_tick_interval
                kwargs = {'change': entry['value']}

            if kwargs:
                self.event_keys.add(self.machine.events.add_handler(
                                    entry['event'], handler, **kwargs))
            else:
                self.event_keys.add(self.machine.events.add_handler(
                                    entry['event'], handler))

    def _remove_control_events(self):
        for key in self.event_keys:
            self.machine.events.remove_handler_by_key(key)

    def reset(self):
        self._ticks = self.start_value

    def start(self, **kwargs):
        """Starts this timer based on the starting value that's already been
        configured. Use set_current_time() if you want to set the starting time
        value.

        Args:
            **kwargs: Not used in this method. Only exists since this method is
                often registered as an event handler which may contain
                additional keyword arguments.
        """

        self.running = True

        self.delay.remove('pause')
        self._create_system_timer()

        self.machine.events.post('timer_' + self.name + '_started',
                                 ticks=self.mode.player[self.tick_var])

        if self.bcp:
            self.machine.bcp.send('timer', name=self.name, action='started',
                                  ticks=self.mode.player[self.tick_var])

    def stop(self, **kwargs):
        """Stops the timer and posts the 'timer_<name>_stopped' event.
开发者ID:jabdoa2,项目名称:mpf,代码行数:69,代码来源:modes.py

示例6: BallSave

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]
class BallSave(Device):

    config_section = "ball_saves"
    collection = "ball_saves"
    class_label = "ball_save"

    def __init__(self, machine, name, config, collection=None, validate=True):
        super(BallSave, self).__init__(machine, name, config, collection, validate=validate)

        self.delay = DelayManager()
        self.enabled = False
        self.saves_remaining = 0

        if self.config["balls_to_save"] == -1:
            self.unlimited_saves = True
        else:
            self.unlimited_saves = False

        self.source_playfield = self.config["source_playfield"]

        # todo change the delays to timers so we can add pause and extension
        # events, but that will require moving timers out of mode conde

    def enable(self, **kwargs):
        if self.enabled:
            return

        self.saves_remaining = self.config["balls_to_save"]
        self.enabled = True
        self.log.debug(
            "Enabling. Auto launch: %s, Balls to save: %s", self.config["auto_launch"], self.config["balls_to_save"]
        )

        # Enable shoot again
        self.machine.events.add_handler("ball_drain", self._ball_drain_while_active, priority=1000)

        if self.config["active_time"] > 0 and not self.config["timer_start_events"]:
            self.timer_start()

        self.machine.events.post("ball_save_{}_enabled".format(self.name))

    def disable(self, **kwargs):
        if not self.enabled:
            return

        self.enabled = False
        self.log.debug("Disabling...")
        self.machine.events.remove_handler(self._ball_drain_while_active)
        self.delay.remove("disable")
        self.delay.remove("hurry_up")
        self.delay.remove("grace_period")

        self.machine.events.post("ball_save_{}_disabled".format(self.name))

    def timer_start(self, **kwargs):
        if self.config["active_time"] > 0:
            if self.debug:
                self.log.debug("Starting ball save timer: %ss", self.config["active_time"] / 1000.0)

            self.delay.add(
                name="disable", ms=(self.config["active_time"] + self.config["grace_period"]), callback=self.disable
            )
            self.delay.add(name="grace_period", ms=self.config["active_time"], callback=self._grace_period)
            self.delay.add(
                name="hurry_up", ms=(self.config["active_time"] - self.config["hurry_up_time"]), callback=self._hurry_up
            )

    def _hurry_up(self):
        if self.debug:
            self.log.debug("Starting Hurry Up")

        self.machine.events.post("ball_save_{}_hurry_up".format(self.name))

    def _grace_period(self):
        if self.debug:
            self.log.debug("Starting Grace Period")

        self.machine.events.post("ball_save_{}_grace_period".format(self.name))

    def _ball_drain_while_active(self, balls, **kwargs):
        if balls <= 0:
            return {"balls": balls}

        no_balls_in_play = False

        try:
            if not self.machine.game.balls_in_play:
                no_balls_in_play = True
        except AttributeError:
            no_balls_in_play = True

        if no_balls_in_play:
            self.log.debug("Received request to save ball, but no balls are in" " play. Discarding request.")
            return {"balls": balls}

        self.log.debug(
            "Ball(s) drained while active. Requesting new one(s). " "Autolaunch: %s", self.config["auto_launch"]
        )

        self.machine.events.post("ball_save_{}_saving_ball".format(self.name), balls=balls)
#.........这里部分代码省略.........
开发者ID:mini338,项目名称:mpf,代码行数:103,代码来源:ball_save.py

示例7: Playfield

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]
class Playfield(BallDevice):

    def __init__(self, machine, name, collection):
        self.log = logging.getLogger('Playfield')

        self.machine = machine
        self.name = name
        self.tags = list()
        self.config = defaultdict(lambda: None)
        self.config['eject_targets'] = list()

        self.ball_controller = self.machine.ball_controller

        self.delay = DelayManager()

        # Add the playfield ball device to the existing device collection
        collection_object = getattr(self.machine, collection)[name] = self

        # Attributes
        self._balls = 0
        self.num_balls_requested = 0
        self.player_controlled_eject_in_progress = None
        self.queued_balls = list()

        # Set up event handlers

        # Watch for balls added to the playfield
        for device in self.machine.balldevices:
            for target in device.config['eject_targets']:
                if target == self.name:
                    self.machine.events.add_handler(
                        event='balldevice_' + device.name +
                        '_ball_eject_success',
                        handler=self._source_device_eject_success)
                    self.machine.events.add_handler(
                        event='balldevice_' + device.name +
                        '_ball_eject_attempt',
                        handler=self._source_device_eject_attempt)
                break

        # Watch for balls removed from the playfield
        self.machine.events.add_handler('balldevice_captured_from_playfield',
                                        self._ball_removed_handler)

        # Watch for any switch hit which indicates a ball on the playfield
        self.machine.events.add_handler('sw_playfield_active',
                                        self.playfield_switch_hit)

    @property
    def balls(self):
        return self._balls

    @balls.setter
    def balls(self, balls):

        prior_balls = self._balls
        ball_change = balls - prior_balls

        if ball_change:
            self.log.debug("Ball count change. Prior: %s, Current: %s, Change: "
                           "%s", prior_balls, balls, ball_change)

        if balls > 0:
            self._balls = balls
            #self.ball_search_schedule()
        elif balls == 0:
            self._balls = 0
            #self.ball_search_disable()
        else:
            self.log.warning("Playfield balls went to %s. Resetting to 0, but "
                             "FYI that something's weird", balls)
            self._balls = 0
            #self.ball_search_disable()

        self.log.debug("New Ball Count: %s. (Prior count: %s)",
                       self._balls, prior_balls)

        if ball_change > 0:
            self.machine.events.post_relay('balldevice_' + self.name +
                                           '_ball_enter', balls=ball_change)

        if ball_change:
            self.machine.events.post('playfield_ball_count_change',
                                     balls=balls, change=ball_change)

    def count_balls(self, **kwargs):
        """Used to count the number of balls that are contained in a ball
        device. Since this is the playfield device, this method always returns
        zero.

        Returns: 0
        """
        return 0

    def get_additional_ball_capacity(self):
        """Used to find out how many more balls this device can hold. Since this
        is the playfield device, this method always returns 999.

        Returns: 999
        """
#.........这里部分代码省略.........
开发者ID:jabdoa2,项目名称:mpf,代码行数:103,代码来源:playfield.py

示例8: SequenceShot

# 需要导入模块: from mpf.system.tasks import DelayManager [as 别名]
# 或者: from mpf.system.tasks.DelayManager import remove [as 别名]
class SequenceShot(Shot):

    def __init__(self, machine, name, config, priority):
        """SequenceShot is where you need certain switches to be hit in the
        right order, possibly within a time limit.

        Subclass of `Shot`

        Args:
            machine: The MachineController object
            name: String name of this shot.
            config: Dictionary that holds the configuration for this shot.

        """
        super(SequenceShot, self).__init__(machine, name, config, priority)

        self.delay = DelayManager()

        self.progress_index = 0
        """Tracks how far along through this sequence the current shot is."""

        # convert our switches config to a list
        if 'switches' in self.config:
            self.config['switches'] = \
                Config.string_to_list(self.config['switches'])

        # convert our timout to ms
        if 'time' in self.config:
            self.config['time'] = Timing.string_to_ms(self.config['time'])
        else:
            self.config['time'] = 0

        self.active_delay = False

        self.enable()

    def enable(self):
        """Enables the shot. If it's not enabled, the switch handlers aren't
        active and the shot event will not be posted."""

        super(SequenceShot, self).enable()

        # create the switch handlers
        for switch in self.config['switches']:
            self.machine.switch_controller.add_switch_handler(
                switch, self._switch_handler, return_info=True)
        self.progress_index = 0

    def disable(self):
        """Disables the shot. If it's disabled, the switch handlers aren't
        active and the shot event will not be posted."""

        super(SequenceShot, self).disable()

        for switch in self.config['switches']:
            self.machine.switch_controller.remove_switch_handler(
                switch, self.switch_handler)
        self.progress_index = 0

    def _switch_handler(self, switch_name, state, ms):
        # does this current switch meet the next switch in the progress index?
        if switch_name == self.config['switches'][self.progress_index]:

            # are we at the end?
            if self.progress_index == len(self.config['switches']) - 1:
                self.confirm_shot()
            else:
                # does this shot specific a time limit?
                if self.config['time']:
                    # do we need to set a delay?
                    if not self.active_delay:
                        self.delay.reset(name='shot_timer',
                                         ms=self.config['time'],
                                         callback=self.reset)
                        self.active_delay = True

                # advance the progress index
                self.progress_index += 1

    def confirm_shot(self):
        """Called when the shot is complete to confirm and reset it."""
        # kill the delay
        self.delay.remove('shot_timer')
        # reset our shot
        self.reset()

        self.shot_made()

    def reset(self):
        """Resets the progress without disabling the shot."""
        self.log.debug("Resetting this shot")
        self.progress_index = 0
        self.active_delay = False
开发者ID:jabdoa2,项目名称:mpf,代码行数:95,代码来源:shots.py


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