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


Python config.Config类代码示例

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


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


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