Example #1
0
    def test_autoload(self):
        self.window.on_autoload_switch(None, False)
        self.assertFalse(
            config.is_autoloaded(self.window.selected_device,
                                 self.window.selected_preset))

        self.window.on_select_device(FakeDropdown('device 1'))
        gtk_iteration()
        self.assertFalse(
            self.window.get('preset_autoload_switch').get_active())

        # select a preset for the first device
        self.window.get('preset_autoload_switch').set_active(True)
        gtk_iteration()
        self.assertTrue(self.window.get('preset_autoload_switch').get_active())
        self.assertTrue(config.is_autoloaded('device 1', 'new preset'))
        self.assertFalse(config.is_autoloaded('device 2', 'new preset'))
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('device 1', 'new preset')])

        # switch the preset, the switch should be correct and the config
        # not changed.
        self.window.on_create_preset_clicked(None)
        gtk_iteration()
        self.assertEqual(self.window.selected_preset, 'new preset 2')
        self.assertFalse(
            self.window.get('preset_autoload_switch').get_active())
        self.assertTrue(config.is_autoloaded('device 1', 'new preset'))

        # select a preset for the second device
        self.window.on_select_device(FakeDropdown('device 2'))
        self.window.get('preset_autoload_switch').set_active(True)
        gtk_iteration()
        self.assertTrue(config.is_autoloaded('device 1', 'new preset'))
        self.assertTrue(config.is_autoloaded('device 2', 'new preset'))
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('device 1', 'new preset'),
                              ('device 2', 'new preset')])

        # disable autoloading for the second device
        self.window.get('preset_autoload_switch').set_active(False)
        gtk_iteration()
        self.assertTrue(config.is_autoloaded('device 1', 'new preset'))
        self.assertFalse(config.is_autoloaded('device 2', 'new preset'))
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('device 1', 'new preset')])
Example #2
0
    def on_rename_button_clicked(self, _):
        """Rename the preset based on the contents of the name input."""
        new_name = self.get('preset_name_input').get_text()

        if new_name in ['', self.preset_name]:
            return

        self.save_preset()

        new_name = rename_preset(self.group.name, self.preset_name, new_name)

        # if the old preset was being autoloaded, change the
        # name there as well
        is_autoloaded = config.is_autoloaded(self.group.key, self.preset_name)
        if is_autoloaded:
            config.set_autoload_preset(self.group.key, new_name)

        self.get('preset_name_input').set_text('')
        self.populate_presets()
Example #3
0
    def on_select_preset(self, dropdown):
        """Show the mappings of the preset."""
        # beware in tests that this function won't be called at all if the
        # active_id stays the same
        self.save_preset()

        if dropdown.get_active_id() == self.selected_preset:
            return

        self.clear_mapping_table()

        preset = dropdown.get_active_text()
        if preset is None:
            return

        logger.debug('Selecting preset "%s"', preset)
        self.selected_preset = preset

        custom_mapping.load(get_preset_path(self.selected_device, preset))

        key_list = self.get('key_list')
        for key, output in custom_mapping:
            single_key_mapping = Row(window=self,
                                     delete_callback=self.on_row_removed,
                                     key=key,
                                     character=output)
            key_list.insert(single_key_mapping, -1)

        autoload_switch = self.get('preset_autoload_switch')

        with HandlerDisabled(autoload_switch, self.on_autoload_switch):
            autoload_switch.set_active(
                config.is_autoloaded(self.selected_device,
                                     self.selected_preset))

        self.get('preset_name_input').set_text('')
        self.add_empty()

        self.initialize_gamepad_config()

        custom_mapping.changed = False
Example #4
0
    def on_select_preset(self, dropdown):
        """Show the mappings of the preset."""
        if dropdown.get_active_id() == self.selected_preset:
            return

        if custom_mapping.changed and unsaved_changes_dialog() == GO_BACK:
            dropdown.set_active_id(self.selected_preset)
            return

        self.clear_mapping_table()

        preset = dropdown.get_active_text()
        logger.debug('Selecting preset "%s"', preset)

        self.selected_preset = preset
        custom_mapping.load(
            get_preset_path(self.selected_device, self.selected_preset))

        key_list = self.get('key_list')
        for key, output in custom_mapping:
            single_key_mapping = Row(window=self,
                                     delete_callback=self.on_row_removed,
                                     key=key,
                                     character=output)
            key_list.insert(single_key_mapping, -1)

        autoload_switch = self.get('preset_autoload_switch')

        with HandlerDisabled(autoload_switch, self.on_autoload_switch):
            autoload_switch.set_active(
                config.is_autoloaded(self.selected_device,
                                     self.selected_preset))

        self.get('preset_name_input').set_text('')
        self.add_empty()

        self.initialize_gamepad_config()

        custom_mapping.changed = False
Example #5
0
    def test_autoload(self):
        self.assertEqual(len(config.iterate_autoload_presets()), 0)
        self.assertFalse(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2', 'b'))

        config.set_autoload_preset('d1', 'a')
        self.assertEqual(len(config.iterate_autoload_presets()), 1)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2', 'b'))

        config.set_autoload_preset('d2', 'b')
        self.assertEqual(len(config.iterate_autoload_presets()), 2)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertTrue(config.is_autoloaded('d2', 'b'))

        config.set_autoload_preset('d2', 'c')
        self.assertEqual(len(config.iterate_autoload_presets()), 2)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2', 'b'))
        self.assertTrue(config.is_autoloaded('d2', 'c'))
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('d1', 'a'), ('d2', 'c')])

        config.set_autoload_preset('d2', None)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2', 'b'))
        self.assertFalse(config.is_autoloaded('d2', 'c'))
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('d1', 'a')])
Example #6
0
    def test_autoload(self):
        self.assertEqual(len(config.iterate_autoload_presets()), 0)
        self.assertFalse(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2.foo', 'b'))
        self.assertEqual(config.get(['autoload', 'd1']), None)
        self.assertEqual(config.get(['autoload', 'd2.foo']), None)

        config.set_autoload_preset('d1', 'a')
        self.assertEqual(len(config.iterate_autoload_presets()), 1)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2.foo', 'b'))

        config.set_autoload_preset('d2.foo', 'b')
        self.assertEqual(len(config.iterate_autoload_presets()), 2)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertTrue(config.is_autoloaded('d2.foo', 'b'))
        self.assertEqual(config.get(['autoload', 'd1']), 'a')
        self.assertEqual(config.get('autoload.d1'), 'a')
        self.assertEqual(config.get(['autoload', 'd2.foo']), 'b')

        config.set_autoload_preset('d2.foo', 'c')
        self.assertEqual(len(config.iterate_autoload_presets()), 2)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2.foo', 'b'))
        self.assertTrue(config.is_autoloaded('d2.foo', 'c'))
        self.assertEqual(config._config['autoload']['d2.foo'], 'c')
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('d1', 'a'), ('d2.foo', 'c')])

        config.set_autoload_preset('d2.foo', None)
        self.assertTrue(config.is_autoloaded('d1', 'a'))
        self.assertFalse(config.is_autoloaded('d2.foo', 'b'))
        self.assertFalse(config.is_autoloaded('d2.foo', 'c'))
        self.assertListEqual(list(config.iterate_autoload_presets()),
                             [('d1', 'a')])
        self.assertEqual(config.get(['autoload', 'd1']), 'a')