• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python config.Config类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

    def __init__(self, machine, name, player, config):

        self.machine = machine
        self.name = name
        self.player = player
        self.handler_keys = set()

        self.enabled = False

        config_spec = """
                    enable_events: list|None
                    disable_events: list|None
                    reset_events: list|None
                    restart_on_complete: boolean|False
                    disable_on_complete: boolean|True
                    """

        self.config = Config.process_config(config_spec=config_spec, source=config)

        if "events_when_complete" not in config:
            self.config["events_when_complete"] = ["logicblock_" + self.name + "_complete"]
        else:
            self.config["events_when_complete"] = Config.string_to_list(config["events_when_complete"])

        if "reset_each_ball" in config and config["reset_each_ball"]:
            if "ball_starting" not in self.config["reset_events"]:
                self.config["reset_events"].append("ball_starting")
开发者ID:jabdoa2,项目名称:mpf,代码行数:27,代码来源:logic_blocks.py


示例2: configure_mode_settings

    def configure_mode_settings(self, config):
        """Processes this mode's configuration settings from a config
        dictionary.
        """

        if not ('priority' in config and type(config['priority']) is int):
            config['priority'] = 0

        if 'start_events' in config:
            config['start_events'] = Config.string_to_list(
                config['start_events'])
        else:
            config['start_events'] = list()

        if 'stop_events' in config:
            config['stop_events'] = Config.string_to_list(
                config['stop_events'])
        else:
            config['stop_events'] = list()

        # register mode start events
        if 'start_events' in config:
            for event in config['start_events']:
                self.machine.events.add_handler(event, self.start)

        self.config['mode'] = config
开发者ID:jabdoa2,项目名称:mpf,代码行数:26,代码来源:modes.py


示例3: __init__

    def __init__(self,  slide, machine, dmd_object=None, x=None, y=None, h_pos=None,
                 v_pos=None, layer=0, **kwargs):

        super(VirtualDMD, self).__init__(slide, x, y, h_pos, v_pos, layer)

        if not dmd_object:
            self.dmd_object = machine.display.displays['dmd']
        else:
            self.dmd_object = dmd_object

        self.config = kwargs

        self.name = 'VirtualDMD'

        if self.dmd_object.depth == 8:

            if 'pixel_color' not in kwargs:
                self.config['pixel_color'] = 'ff5500'

            if 'dark_color' not in self.config:
                self.config['dark_color'] = '221100'

            if 'pixel_spacing' not in self.config:
                self.config['pixel_spacing'] = 2

            # convert hex colors to list of ints
            self.config['pixel_color'] = Config.hexstring_to_list(
                self.config['pixel_color'])
            self.config['dark_color'] = Config.hexstring_to_list(
                self.config['dark_color'])

            # This needs to match the source DMD or it could get weird
            self.config['shades'] = self.dmd_object.config['shades']

            self.palette = mpf.media_controller.display_modules.dmd.create_palette(
                bright_color=self.config['pixel_color'],
                dark_color=self.config['dark_color'],
                steps=self.config['shades'])

        if ('width' in self.config and
                'height' not in self.config):
            self.config['height'] = self.config['width'] / 4
        elif ('height' in self.config and
                'width' not in self.config):
            self.config['width'] = self.config['height'] * 4
        elif ('width' not in self.config and
                'height' not in self.config):
            self.config['width'] = 512
            self.config['height'] = 128

        # Create a Pygame surface for the on screen DMD
        self.element_surface = pygame.Surface((self.config['width'],
                                      self.config['height']),
                                      depth=self.dmd_object.depth)

        if self.dmd_object.depth == 8:
            self.element_surface.set_palette(self.palette)

        self.layer = layer
        self.set_position(x, y, h_pos, v_pos)
开发者ID:jherrm,项目名称:mpf,代码行数:60,代码来源:virtualdmd.py


示例4: configure_led

    def configure_led(self, config):

        if not self.rgb_connection:
            self.log.critical("A request was made to configure a FAST LED, "
                              "but no connection to an LED processor is "
                              "available")
            sys.exit()

        if not self.flag_led_tick_registered:
            self.machine.events.add_handler('timer_tick', self.update_leds)
            self.flag_led_tick_registered = True

        # if the LED number is in <channel> - <led> format, convert it to a
        # FAST hardware number
        if '-' in config['number_str']:
            num = config['number_str'].split('-')
            config['number'] = int((num[0] * 64) + num[1])
            self.config['config_number_format'] = 'int'
        else:
            config['number'] = str(config['number'])

        if self.config['config_number_format'] == 'int':
            config['number'] = Config.int_to_hex_string(config['number'])
        else:
            config['number'] = Config.normalize_hex_string(config['number'])

        this_fast_led = FASTDirectLED(config['number'])
        self.fast_leds.add(this_fast_led)

        return this_fast_led
开发者ID:jherrm,项目名称:mpf,代码行数:30,代码来源:fast.py


示例5: __init__

    def __init__(self, machine, name, player, config):

        self.machine = machine
        self.name = name
        self.player = player
        self.handler_keys = set()

        self.enabled = False

        config_spec = '''
                    enable_events: list|None
                    disable_events: list|None
                    reset_events: list|None
                    restart_events: list|None
                    restart_on_complete: boolean|False
                    disable_on_complete: boolean|True
                    '''

        self.config = Config.process_config(config_spec=config_spec,
                                            source=config)

        if 'events_when_complete' not in config:
            self.config['events_when_complete'] = ([
                'logicblock_' + self.name + '_complete'])
        else:
            self.config['events_when_complete'] = Config.string_to_list(
                config['events_when_complete'])

        if 'reset_each_ball' in config and config['reset_each_ball']:
            if 'ball_starting' not in self.config['reset_events']:
                self.config['reset_events'].append('ball_starting')
开发者ID:jherrm,项目名称:mpf,代码行数:31,代码来源:logic_blocks.py


示例6: receive_sa

    def receive_sa(self, msg):

        self.log.debug("Received SA: %s", msg)

        hw_states = dict()

        num_local, local_states, num_nw, nw_states = msg.split(',')

        for offset, byte in enumerate(bytearray.fromhex(nw_states)):
            for i in range(8):
                num = Config.int_to_hex_string((offset * 8) + i)
                if byte & (2**i):
                    hw_states[(num, 1)] = 1
                else:
                    hw_states[(num, 1)] = 0

        for offset, byte in enumerate(bytearray.fromhex(local_states)):
            for i in range(8):

                num = Config.int_to_hex_string((offset * 8) + i)

                if byte & (2**i):
                    hw_states[(num, 0)] = 1
                else:
                    hw_states[(num, 0)] = 0

        self.hw_switch_data = hw_states
开发者ID:jherrm,项目名称:mpf,代码行数:27,代码来源:fast.py


示例7: __init__

    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,代码行数:54,代码来源:switch.py


示例8: _initialize_switches

    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,代码行数:52,代码来源:switch_controller.py


示例9: _load_mode

    def _load_mode(self, mode_string):
        """Loads a mode, reads in its config, and creates the Mode object.

        Args:
            mode: String name of the mode you're loading. This is the name of
                the mode's folder in your game's machine_files/modes folder.

        """
        self.log.debug('Processing mode: %s', mode_string)

        config = dict()

        # find the folder for this mode:
        mode_path = os.path.join(self.machine.machine_path,
            self.machine.config['media_controller']['paths']['modes'], mode_string)

        if not os.path.exists(mode_path):
            mode_path = os.path.abspath(os.path.join('mpf', self.machine.config['media_controller']['paths']['modes'], mode_string))

        # Is there an MPF default config for this mode? If so, load it first
        mpf_mode_config = os.path.join(
            'mpf',
            self.machine.config['media_controller']['paths']['modes'],
            mode_string,
            'config',
            mode_string + '.yaml')

        if os.path.isfile(mpf_mode_config):
            config = Config.load_config_file(mpf_mode_config)

        # Now figure out if there's a machine-specific config for this mode, and
        # if so, merge it into the config

        mode_config_folder = os.path.join(self.machine.machine_path,
            self.machine.config['media_controller']['paths']['modes'], mode_string, 'config')

        found_file = False
        for path, _, files in os.walk(mode_config_folder):
            for file in files:
                file_root, file_ext = os.path.splitext(file)

                if file_root == mode_string:
                    config = Util.dict_merge(config,
                        Config.load_config_file(os.path.join(path, file)))
                    found_file = True
                    break

            if found_file:
                break

        return Mode(self.machine, config, mode_string, mode_path)
开发者ID:HarryXS,项目名称:mpf,代码行数:51,代码来源:mode_controller.py


示例10: _load_config

    def _load_config(self):
        # creates the main config dictionary from the YAML machine config files.

        self.config = dict()

        # load the MPF config & machine defaults
        self.config = Config.load_config_yaml(config=self.config,
            yaml_file=self.options['mpfconfigfile'])

        # Find the machine_files location. If it starts with a forward or
        # backward slash, then we assume it's from the mpf root. Otherwise we
        # assume it's from the subfolder location specified in the
        # mpfconfigfile location

        if (self.options['machinepath'].startswith('/') or
                self.options['machinepath'].startswith('\\')):
            machine_path = self.options['machinepath']
        else:
            machine_path = os.path.join(self.config['mpf']['paths']
                                        ['machine_files'],
                                        self.options['machinepath'])

        self.machine_path = os.path.abspath(machine_path)

        # Add the machine folder to our path so we can import modules from it
        sys.path.append(self.machine_path)

        self.log.info("Machine folder: %s", machine_path)

        # Now find the config file location. Same as machine_file with the
        # slash uses to specify an absolute path

        if (self.options['configfile'].startswith('/') or
                self.options['configfile'].startswith('\\')):
            config_file = self.options['configfile']
        else:

            if not self.options['configfile'].endswith('.yaml'):
                self.options['configfile'] += '.yaml'

            config_file = os.path.join(machine_path,
                                       self.config['mpf']['paths']['config'],
                                       self.options['configfile'])

        self.log.info("Base machine config file: %s", config_file)

        # Load the machine-specific config
        self.config = Config.load_config_yaml(config=self.config,
                                            yaml_file=config_file)
开发者ID:jabdoa2,项目名称:mpf,代码行数:49,代码来源:machine.py


示例11: set_brightness_compensation

    def set_brightness_compensation(self, value):
        """Sets the brightness compensation for this LED.

        args:
            value: Str or list (of 1-to-3 items) of the new brightness
                compensation value to set. List items are floats. 1.0 is
                standard full brightness. 0.0 is off. 2.0 is 200% brightness
                (which only comes into play if the LED is not at full
                brightness). If the value is a string, it's converted to a list,
                broken by commas.

        The brightness compensation list is three items long, one for each RGB
        element. If the LED has less than three elements, additional values are
        ignored.

        If the value list is only one item, that value is used for all three
        elements.

        If the value list is two items, a value of 1.0 is used for the third
        item.

        """
        if type(value) is not list:
            value = Config.string_to_list(value)

        value = [float(x) for x in value]

        if len(value) == 1:
            value.extend([value[0], value[0]])
        elif len(value) == 2:
            value.append(1.0)

        self.config["brightness_compensation"] = value
开发者ID:jherrm,项目名称:mpf,代码行数:33,代码来源:led.py


示例12: __init__

    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()
开发者ID:jabdoa2,项目名称:mpf,代码行数:33,代码来源:shots.py


示例13: disable

    def disable(self):
        """Disables the shot."""
        super(StandardShot, self).disable()

        for switch in Config.string_to_list(self.config['switch']):
            self.machine.switch_controller.remove_switch_handler(
                switch, self._switch_handler)
开发者ID:jabdoa2,项目名称:mpf,代码行数:7,代码来源:shots.py


示例14: enable

    def enable(self):
        """Enables the shot."""
        super(StandardShot, self).enable()

        for switch in Config.string_to_list(self.config['switch']):
            self.machine.switch_controller.add_switch_handler(
                switch, self._switch_handler, return_info=True)
开发者ID:jabdoa2,项目名称:mpf,代码行数:7,代码来源:shots.py


示例15: initialize_hw_states

    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,代码行数:25,代码来源:switch_controller.py


示例16: __init__

    def __init__(self, machine, config):

        super(FadeCandyOPClient, self).__init__(machine, config)

        self.log = logging.getLogger('FadeCandyClient')

        self.update_every_tick = True

        self.gamma = self.machine.config['ledsettings']['gamma']
        self.whitepoint = Config.string_to_list(
            self.machine.config['ledsettings']['whitepoint'])

        self.whitepoint[0] = float(self.whitepoint[0])
        self.whitepoint[1] = float(self.whitepoint[1])
        self.whitepoint[2] = float(self.whitepoint[2])

        self.linear_slope = (
            self.machine.config['ledsettings']['linear_slope'])
        self.linear_cutoff = (
            self.machine.config['ledsettings']['linear_cutoff'])
        self.keyframe_interpolation = (
            self.machine.config['ledsettings']['keyframe_interpolation'])
        self.dithering = self.machine.config['ledsettings']['dithering']

        if not self.dithering:
            self.disable_dithering()

        if not self.keyframe_interpolation:
            self.update_every_tick = False

        self.set_global_color_correction()
        self.write_firmware_options()
开发者ID:jabdoa2,项目名称:mpf,代码行数:32,代码来源:fadecandy.py


示例17: __init__

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

        self.shots = list()  # list of strings

        for shot in Config.string_to_list(config['shots']):
            self.shots.append(machine.shots[shot])

        # If this device is setup in a machine-wide config, make sure it has
        # a default enable event.

        # TODO add a mode parameter to the device constructor and do the logic
        # there.
        if not machine.modes:

            if 'enable_events' not in config:
                config['enable_events'] = 'ball_starting'
            if 'disable_events' not in config:
                config['disable_events'] = 'ball_ended'
            if 'reset_events' not in config:
                config['reset_events'] = 'ball_ended'

            if 'profile' in config:
                for shot in self.shots:
                    shot.update_enable_table(profile=config['profile'],
                                      mode=None)

        super(ShotGroup, self).__init__(machine, name, config, collection,
                                        validate=validate)

        self.rotation_enabled = True

        if self.debug:
            self._enable_related_device_debugging()
开发者ID:jherrm,项目名称:mpf,代码行数:33,代码来源:shot_group.py


示例18: __init__

    def __init__(self, machine):
        self.log = logging.getLogger('switchplayer')

        if 'switchplayer' not in machine.config:
            machine.log.debug('"switchplayer:" section not found in '
                                   'machine configuration, so the Switch Player'
                                   'plugin will not be used.')
            return

        self.machine = machine
        self.delay = DelayManager()
        self.current_step = 0

        config_spec = '''
                        start_event: string|machine_reset_phase_3
                        start_delay: secs|0
                        '''

        self.config = Config.process_config(config_spec,
                                            self.machine.config['switchplayer'])

        self.machine.events.add_handler(self.config['start_event'],
                                        self._start_event_callback)

        self.step_list = self.config['steps']
        self.start_delay = self.config['start_delay']
开发者ID:jabdoa2,项目名称:mpf,代码行数:26,代码来源:switch_player.py


示例19: _load_mode

    def _load_mode(self, mode_string):
        """Loads a mode, reads in its config, and creates the Mode object.

        Args:
            mode: String name of the mode you're loading. This is the name of
                the mode's folder in your game's machine_files/modes folder.
        """
        self.log.info('Processing mode: %s', mode_string)

        mode_path = os.path.join(self.machine.machine_path,
            self.machine.config['mediacontroller']['paths']['modes'], mode_string)
        mode_config_file = os.path.join(self.machine.machine_path,
            self.machine.config['mediacontroller']['paths']['modes'],
            mode_string, 'config', mode_string + '.yaml')
        config = Config.load_config_yaml(yaml_file=mode_config_file)

        if 'code' in config['mode']:

            import_str = ('modes.' + mode_string + '.code.' +
                          config['mode']['code'].split('.')[0])
            i = __import__(import_str, fromlist=[''])
            mode_object = getattr(i, config['mode']['code'].split('.')[1])(
                self.machine, config, mode_string, mode_path)

        else:
            mode_object = Mode(self.machine, config, mode_string, mode_path)

        return mode_object
开发者ID:jabdoa2,项目名称:mpf,代码行数:28,代码来源:modes.py


示例20: __init__

    def __init__(self, machine):
        self.log = logging.getLogger("switch_player")

        if "switch_player" not in machine.config:
            machine.log.debug(
                '"switch_player:" section not found in '
                "machine configuration, so the Switch Player"
                "plugin will not be used."
            )
            return

        self.machine = machine
        self.delay = DelayManager()
        self.current_step = 0

        config_spec = """
                        start_event: string|machine_reset_phase_3
                        start_delay: secs|0
                        """

        self.config = Config.process_config(config_spec, self.machine.config["switch_player"])

        self.machine.events.add_handler(self.config["start_event"], self._start_event_callback)

        self.step_list = self.config["steps"]
        self.start_delay = self.config["start_delay"]
开发者ID:mini338,项目名称:mpf,代码行数:26,代码来源:switch_player.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tasks.DelayManager类代码示例发布时间:2022-05-27
下一篇:
Python mpdhelper.get函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap