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


Python Config.string_to_lowercase_list方法代码示例

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


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

示例1: __init__

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def __init__(self, machine, name, config, collection=None):
        self.log = logging.getLogger("Switch." + name)
        super(Switch, self).__init__(machine, name, config, collection, platform_section="switches")

        self.machine = machine
        self.name = name
        self.config = config
        self.deactivation_events = list()
        self.activation_events = list()
        self.state = 0
        """ The logical state of a switch. 1 = active, 0 = inactive. This takes
        into consideration the NC or NO settings for the switch."""
        self.hw_state = 0
        """ The physical hardware state of the switch. 1 = active,
        0 = inactive. This is what the actual hardware is reporting and does
        not consider whether a switch is NC or NO."""

        # todo read these in and/or change to dict
        self.type = "NO"
        """ Specifies whether the switch is normally open ('NO', default) or
        normally closed ('NC')."""
        if "type" in config and config["type"].upper() == "NC":
            self.type = "NC"

        if "debounce" not in config:
            config["debounce"] = True

        if "activation_events" in config:
            self.activation_events = Config.string_to_lowercase_list(config["activation_events"])

        if "deactivation_events" in config:
            self.deactivation_events = Config.string_to_lowercase_list(config["deactivation_events"])

        # We save out number_str since the platform driver will convert the
        # number into a hardware number, but we need the original number for
        # some things later.
        self.config["number_str"] = str(config["number"]).upper()

        self.last_changed = None
        self.hw_timestamp = None

        self.log.debug("Creating '%s' with config: %s", name, config)

        self.hw_switch, self.number, self.hw_state = self.platform.configure_switch(config)

        self.log.debug("Current hardware state of switch '%s': %s", self.name, self.hw_state)

        # If we're using physical hardware, set the initial logical switch
        # state based on the hw_state
        if self.machine.physical_hw:
            if self.type == "NC":
                self.state = self.hw_state ^ 1
            else:
                self.state = self.hw_state
开发者ID:jabdoa2,项目名称:mpf,代码行数:56,代码来源:switch.py

示例2: _initialize_switches

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def _initialize_switches(self):
        self.update_switches_from_hw()

        for switch in self.machine.switches:
            # Populate self.switches
            self.set_state(switch.name, switch.state, reset_time=True)

            # Populate self.registered_switches
            self.registered_switches[switch.name + '-0'] = list()
            self.registered_switches[switch.name + '-1'] = list()

            if self.machine.config['mpf']['auto_create_switch_events']:
                switch.activation_events.add(
                    self.machine.config['mpf']['switch_event_active'].replace(
                        '%', switch.name))

                switch.deactivation_events.add(
                    self.machine.config['mpf'][
                        'switch_event_inactive'].replace(
                        '%', switch.name))

            if 'activation_events' in switch.config:
                for event in Config.string_to_lowercase_list(
                        switch.config['activation_events']):

                    if "|" in event:
                        ev_name, ev_time = event.split("|")
                        self.add_switch_handler(
                            switch_name=switch.name,
                            callback=self.machine.events.post,
                            state=1,
                            ms=Timing.string_to_ms(ev_time),
                            callback_kwargs={'event': ev_name}
                        )
                    else:
                        switch.activation_events.add(event)

            if 'deactivation_events' in switch.config:
                for event in Config.string_to_lowercase_list(
                        switch.config['deactivation_events']):

                    if "|" in event:
                        ev_name, ev_time = event.split("|")
                        self.add_switch_handler(
                            switch_name=switch.name,
                            callback=self.machine.events.post,
                            state=0,
                            ms=Timing.string_to_ms(ev_time),
                            callback_kwargs={'event': ev_name}
                        )
                    else:
                        switch.deactivation_events.add(event)
开发者ID:jherrm,项目名称:mpf,代码行数:54,代码来源:switch_controller.py

示例3: initialize_hw_states

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def initialize_hw_states(self):
        """Reads and processes the hardware states of the physical switches.

        We can't do this in __init__() because we need the switch controller to
        be setup first before we set up the hw switches. This method is
        called via an event handler which listens for `init_phase_2`.
        """

        start_active = list()

        if not self.machine.physical_hw:

            try:
                start_active = Config.string_to_lowercase_list(
                    self.machine.config['virtual platform start active switches'])
            except KeyError:
                pass

        self.log.debug("Syncing the logical and physical switch states.")
        for switch in self.machine.switches:

            if switch.name in start_active:
                switch.state = 1

            self.set_state(switch.name, switch.state, reset_time=True)
开发者ID:town-hall-pinball,项目名称:mpf,代码行数:27,代码来源:switch_controller.py

示例4: _configure

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def _configure(self):
        self.config = self.machine.config["languages"]
        self.machine.language = self
        self.languages = Config.string_to_lowercase_list(self.machine.config["languages"])

        # Set the default language to the first entry in the list
        self.set_language(self.languages[0])
        self.default_language = self.languages[0]

        self.find_text = re.compile("(\(.*?\))")
开发者ID:jherrm,项目名称:mpf,代码行数:12,代码来源:language.py

示例5: _initialize_switches

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def _initialize_switches(self):

        # Set "start active" switches

        start_active = list()

        if not self.machine.physical_hw:

            try:
                start_active = Config.string_to_lowercase_list(
                    self.machine.config['virtual platform start active switches'])
            except KeyError:
                pass

        for switch in self.machine.switches:

            # Populate self.switches
            if switch.name in start_active:
                switch.state = 1  # set state based on physical state
            self.set_state(switch.name, switch.state, reset_time=True)

            # Populate self.registered_switches
            self.registered_switches[switch.name + '-0'] = list()
            self.registered_switches[switch.name + '-1'] = list()
开发者ID:jabdoa2,项目名称:mpf,代码行数:26,代码来源:switch_controller.py

示例6: do_load

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def do_load(self, callback, show_actions=None):

        self.show_actions = list()

        self.asset_manager.log.debug("Loading Show %s", self.file_name)

        if not show_actions:
            show_actions = self.load_show_from_disk()

        for step_num in range(len(show_actions)):
            step_actions = dict()

            step_actions['tocks'] = show_actions[step_num]['tocks']

            # look for empty steps. If we find them we'll just add their tock
            # time to the previous step.

            if len(show_actions[step_num]) == 1:  # 1 because it still has tocks

                show_actions[-1]['tocks'] += step_actions['tocks']
                continue

            # Events
            # make sure events is a list of strings
            if ('events' in show_actions[step_num] and
                    show_actions[step_num]['events']):

                event_list = (Config.string_to_lowercase_list(
                    show_actions[step_num]['events']))

                step_actions['events'] = event_list

            # slide_player
            if ('display' in show_actions[step_num] and
                    show_actions[step_num]['display']):

                step_actions['display'] = (
                    self.machine.display.slidebuilder.preprocess_settings(
                        show_actions[step_num]['display']))

            # Sounds
            if ('sounds' in show_actions[step_num] and
                    show_actions[step_num]['sounds']):

                # make sure we have a list of dicts
                if type(show_actions[step_num]['sounds']) is dict:
                    show_actions[step_num]['sounds'] = (
                        [show_actions[step_num]['sounds']])

                for entry in show_actions[step_num]['sounds']:

                    try:
                        entry['sound'] = self.machine.sounds[entry['sound']]
                    except KeyError:
                        self.asset_manager.log.critical("Invalid sound '%s' "
                                                        "found in show. ",
                                                        entry['sound'])
                        raise

                step_actions['sounds'] = show_actions[step_num]['sounds']

            self.show_actions.append(step_actions)

        # count how many total locations are in the show. We need this later
        # so we can know when we're at the end of a show
        self.total_locations = len(self.show_actions)

        self.loaded = True

        if callback:
            callback()

        self._asset_loaded()
开发者ID:jherrm,项目名称:mpf,代码行数:75,代码来源:show_controller.py

示例7: rotate

# 需要导入模块: from mpf.system.config import Config [as 别名]
# 或者: from mpf.system.config.Config import string_to_lowercase_list [as 别名]
    def rotate(self, direction=None, steps=1, states=None,
               exclude_states=None, mode=None, **kwargs):
        """Rotates (or "shifts") the state of all the shots in this group.
        This is used for things like lane change, where hitting the flipper
        button shifts all the states of the shots in the group to the left or
        right.

        This method actually transfers the current state of each shot profile
        to the left or the right, and the shot on the end rolls over to the
        taret on the other end.

        Args:
            direction: String that specifies whether the rotation direction is
                to the left or right. Values are 'right' or 'left'. Default of
                None will cause the shot group to rotate in the direction as
                specified by the rotation_pattern.
            steps: Integer of how many steps you want to rotate. Default is 1.
            states: A string of a state or a list of strings that represent the
                targets that will be selected to rotate. If None (default), then
                all targets will be included.
            exclude_states: A string of a state or a list of strings that
                controls whether any targets will *not* be rotated. (Any
                targets with an active profile in one of these states will not
                be included in the rotation. Default is None which means all
                targets will be rotated)

        Note that this shot group must, and rotation_events for this
        shot group, must both be enabled for the rotation events to work.

        """

        if not self.rotation_enabled:

            if self.debug:
                self.log.debug("Received rotation request. "
                               "Rotation Enabled: %s. Will NOT rotate",
                               self.rotation_enabled)

            return

        # if we don't have states or exclude_states, we'll see if the first shot
        # in the group has them and use those. Since all the shots should have
        # the same profile applied, it's ok to just pick from the first one.

        if states:
            states = Config.string_to_lowercase_list(states)
        else:
            states = self.shots[0].active_settings['settings']['state_names_to_rotate']

        if exclude_states:
            exclude_states = Config.string_to_lowercase_list(exclude_states)
        else:
            exclude_states = (
                self.shots[0].active_settings['settings']['state_names_to_not_rotate'])

        shot_list = list()

        # build of a list of shots we're actually going to rotate
        for shot in self.shots:

            if ((not states or
                    shot.enable_table[mode]['current_state_name'] in states)
                    and shot.enable_table[mode]['current_state_name']
                    not in exclude_states):

                shot_list.append(shot)

        shot_state_list = deque()

        for shot in shot_list:

            try:
                current_state = shot.running_light_show.current_location

            except AttributeError:
                current_state = -1

            shot_state_list.append(
                (shot.player[shot.active_settings['settings']['player_variable']],
                 current_state))

        if self.debug:
            self.log.debug('Rotating. Mode: %s, Direction: %s, Include states: '
                           '%s, Exclude states: %s, Shots to be rotated: %s',
                           mode, direction, states,
               exclude_states, [x.name for x in shot_list])

            for shot in shot_list:
                shot.log.debug("This shot is part of a rotation event. Current"
                               " state: %s",
                               shot.enable_table[mode]['current_state_name'])

        # figure out which direction we're going to rotate
        if not direction:
            direction = shot_list[0].enable_table[mode]['settings']['rotation_pattern'][0]
            shot_list[0].enable_table[mode]['settings']['rotation_pattern'].rotate(-1)

            if self.debug:
                self.log.debug("Since no direction was specified, pulling from"
                               " rotation pattern: '%s'", direction)
#.........这里部分代码省略.........
开发者ID:jherrm,项目名称:mpf,代码行数:103,代码来源:shot_group.py


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