コード例 #1
0
    def test_handler_with_settings_condition(self):
        self._called = 0
        self.machine.events.add_handler("test{settings.test == True}",
                                        self._handler)

        # invalid setting
        with self.assertRaises(AssertionError):
            self.post_event("test")
            self.assertEqual(0, self._called)

        self.machine.settings._settings = {}
        self.machine.settings.add_setting(
            SettingEntry("test", "Test", 1, "test", "a", {
                False: "A (default)",
                True: "B"
            }))

        # setting false
        self.post_event("test")
        self.assertEqual(0, self._called)

        self.machine.settings.set_setting_value("test", True)

        # settings true
        self.post_event("test")
        self.assertEqual(1, self._called)
コード例 #2
0
    def mode_init(self):
        """Initialise mode."""
        self.data_manager = self.machine.create_data_manager('earnings')
        self.earnings = self.data_manager.get_data()

        # prevent crashes because of data corruption
        if not isinstance(self.earnings, dict):
            self.earnings = {}

        self.credit_units_per_game = 0
        self.credit_unit = 0
        self.credit_units_for_pricing_tiers = 0
        self.reset_pricing_tier_count_this_game = False

        self.credits_config = self.machine.config_validator.validate_config(
            config_spec='credits',
            source=self.machine.config.get('credits', {}),
            section_name='credits')

        for event in self.credits_config['reset_earnings_events']:
            self.machine.events.add_handler(event, self._reset_earnings)

        for event in self.credits_config['reset_credits_events']:
            self.machine.events.add_handler(event, self._reset_credits)

        # add setting
        self.machine.settings.add_setting(
            SettingEntry("free_play", "Free Play", 500, "free_play",
                         self.credits_config['free_play'], {
                             True: "Free Play",
                             False: "Credit Play"
                         }, "coin"))
コード例 #3
0
ファイル: matrix_light.py プロジェクト: vgrillot/mpf
    def device_class_init(cls, machine: MachineController):
        """Initialise lights.

        Args:
            machine: MachineController object
        """
        cls.machine = machine
        cls.lights_to_fade = set()
        cls.lights_to_update = set()

        machine.validate_machine_config_section('matrix_light_settings')

        cls._updater_task = machine.clock.schedule_interval(
            cls.update_matrix_lights,
            1 / machine.config['mpf']['default_matrix_light_hw_update_hz'])

        machine.mode_controller.register_stop_method(cls.mode_stop)

        machine.settings.add_setting(
            SettingEntry("brightness", "Brightness", 100, "brightness", 1.0, {
                0.25: "25%",
                0.5: "50%",
                0.75: "75%",
                1.0: "100% (default)"
            }))
コード例 #4
0
    def initialise_light_subsystem(self):
        """Initialise the light subsystem."""
        if self._initialised:
            return
        self._initialised = True
        self.machine.validate_machine_config_section('light_settings')

        if self.machine.config['light_settings']['color_correction_profiles'] is None:
            self.machine.config['light_settings']['color_correction_profiles'] = (
                dict())

        # Create the default color correction profile and add it to the machine
        default_profile = RGBColorCorrectionProfile.default()
        self.light_color_correction_profiles['default'] = default_profile

        # Add any user-defined profiles specified in the machine config file
        for profile_name, profile_parameters in (
                self.machine.config['light_settings']
                ['color_correction_profiles'].items()):
            self.machine.config_validator.validate_config(
                'color_correction_profile',
                self.machine.config['light_settings']['color_correction_profiles']
                [profile_name], profile_parameters)

            profile = RGBColorCorrectionProfile(profile_name)
            profile.generate_from_parameters(
                gamma=profile_parameters['gamma'],
                whitepoint=profile_parameters['whitepoint'],
                linear_slope=profile_parameters['linear_slope'],
                linear_cutoff=profile_parameters['linear_cutoff'])
            self.light_color_correction_profiles[profile_name] = profile

        # add setting for brightness
        self.machine.settings.add_setting(SettingEntry("brightness", "Brightness", 100, "brightness", 1.0,
                                                       {0.25: "25%", 0.5: "50%", 0.75: "75%", 1.0: "100% (default)"}))
コード例 #5
0
ファイル: led.py プロジェクト: ngksternhagen/mpf
    def device_class_init(cls, machine: MachineController):
        """Initialise all LEDs.

        Args:
            machine: MachineController which is used
        """
        cls.machine = machine
        cls.leds_to_fade = set()
        cls.leds_to_update = set()

        machine.validate_machine_config_section('led_settings')

        if machine.config['led_settings']['color_correction_profiles'] is None:
            machine.config['led_settings']['color_correction_profiles'] = (
                dict())

        # Generate and add color correction profiles to the machine
        machine.led_color_correction_profiles = dict()

        # Create the default color correction profile and add it to the machine
        default_profile = RGBColorCorrectionProfile.default()
        machine.led_color_correction_profiles['default'] = default_profile

        # Add any user-defined profiles specified in the machine config file
        for profile_name, profile_parameters in (
                machine.config['led_settings']
            ['color_correction_profiles'].items()):

            machine.config_validator.validate_config(
                'color_correction_profile', machine.config['led_settings']
                ['color_correction_profiles'][profile_name],
                profile_parameters)

            profile = RGBColorCorrectionProfile(profile_name)
            profile.generate_from_parameters(
                gamma=profile_parameters['gamma'],
                whitepoint=profile_parameters['whitepoint'],
                linear_slope=profile_parameters['linear_slope'],
                linear_cutoff=profile_parameters['linear_cutoff'])
            machine.led_color_correction_profiles[profile_name] = profile

        # schedule the single machine-wide update to write the current led of
        # each LED to the hardware
        cls._updater_task = machine.clock.schedule_interval(
            cls.update_leds,
            1 / machine.config['mpf']['default_led_hw_update_hz'])

        machine.mode_controller.register_stop_method(cls.mode_stop)

        machine.settings.add_setting(
            SettingEntry("brightness", "Brightness", 100, "brightness", 1.0, {
                0.25: "25%",
                0.5: "50%",
                0.75: "75%",
                1.0: "100% (default)"
            }))
コード例 #6
0
ファイル: match.py プロジェクト: unRARed/mpf
 def __init__(self, machine, config, name, path):
     """Initialise match mode."""
     super().__init__(machine, config, name, path)
     # add setting
     self.machine.settings.add_setting(
         SettingEntry(
             "match_percentage", "Match percentage", 500,
             "match_percentage", 10, {
                 0: "off",
                 2: "2%",
                 5: "5%",
                 10: "10%",
                 15: "15%",
                 30: "30%",
                 50: "50%"
             }))
コード例 #7
0
 def __init__(self, *args, **kwargs):
     """Initialise match mode."""
     super().__init__(*args, **kwargs)
     # add setting
     self.machine.settings.add_setting(
         SettingEntry(
             "match_percentage", "Match percentage", 500,
             "match_percentage", 10, {
                 0: "off",
                 2: "2%",
                 5: "5%",
                 10: "10%",
                 15: "15%",
                 30: "30%",
                 50: "50%"
             }))
コード例 #8
0
ファイル: credits.py プロジェクト: wszamotula/mpf
    def mode_init(self):
        """Initialise mode."""
        self.data_manager = self.machine.create_data_manager('earnings')
        self.earnings = self.data_manager.get_data()

        self.credit_units_per_game = 0
        self.credit_unit = 0
        self.pricing_tiers = set()
        self.credit_units_for_pricing_tiers = 0
        self.reset_pricing_tier_count_this_game = False

        self.credits_config = self.machine.config_validator.validate_config(
            config_spec='credits',
            source=self.machine.config.get('credits', {}),
            section_name='credits')

        # add setting
        self.machine.settings.add_setting(SettingEntry("free_play", "Free Play", 500,
                                                       "free_play", self.credits_config['free_play'],
                                                       {True: "Free Play", False: "Credit Play"}))
コード例 #9
0
    def test_settings(self):
        self.machine.settings._settings = {}
        self.machine.settings.add_setting(SettingEntry("test1", "Test1", 1, "test1", "b",
                                                       {"a": "A", "b": "B (default)", "c": "C"}))
        self.machine.settings.add_setting(SettingEntry("test2", "Test2", 2, "test2", False,
                                                       {True: "Yes", False: "No (default)"}))
        self.mock_event("service_settings_start")
        self.mock_event("service_settings_edit")
        self.mock_event("service_settings_stop")

        self.mock_event("service_menu_selected")
        # enter menu
        self.hit_and_release_switch("s_service_enter")
        self.advance_time_and_run()

        self.assertEventCalledWith("service_menu_selected", label='Diagnostics Menu')

        # select audits menu
        self.hit_and_release_switch("s_service_up")
        self.advance_time_and_run()

        self.assertEventCalledWith("service_menu_selected", label='Audits Menu')

        # select adjustments menu
        self.hit_and_release_switch("s_service_up")
        self.advance_time_and_run()

        self.assertEventCalledWith("service_menu_selected", label='Adjustments Menu')

        # enter adjustments menu
        self.hit_and_release_switch("s_service_enter")
        self.advance_time_and_run()

        self.assertEventCalledWith("service_menu_selected", label='Standard Adjustments')

        # enter standard adjustments menu
        self.hit_and_release_switch("s_service_enter")
        self.advance_time_and_run()

        self.assertEventCalledWith("service_settings_start", settings_label='Test1', value_label="B (default)")

        self.hit_and_release_switch("s_service_up")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_start", settings_label='Test2', value_label="No (default)")

        # change setting
        self.hit_and_release_switch("s_service_enter")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_edit", settings_label='Test2', value_label="No (default)")

        self.hit_and_release_switch("s_service_up")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_edit", settings_label='Test2', value_label="Yes")

        self.hit_and_release_switch("s_service_up")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_edit", settings_label='Test2', value_label="No (default)")

        self.hit_and_release_switch("s_service_down")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_edit", settings_label='Test2', value_label="Yes")

        # exit setting change
        self.hit_and_release_switch("s_service_esc")
        self.advance_time_and_run()

        self.hit_and_release_switch("s_service_up")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_start", settings_label='Test1', value_label="B (default)")

        self.hit_and_release_switch("s_service_down")
        self.advance_time_and_run()
        self.assertEventCalledWith("service_settings_start", settings_label='Test2', value_label="Yes")

        self.assertEventNotCalled("service_settings_stop")

        # exit settings change
        self.hit_and_release_switch("s_service_esc")
        self.advance_time_and_run()

        self.assertEventCalled("service_settings_stop")
コード例 #10
0
 def add_setting(self, setting):
     """Add a setting."""
     setting = SettingEntry(*setting)
     self._settings[setting.name] = setting