Exemplo n.º 1
0
 def test_rename_preset(self):
     create_preset('Foo Device', 'preset 1')
     create_preset('Foo Device', 'preset 2')
     create_preset('Foo Device', 'foobar')
     rename_preset('Foo Device', 'preset 1', 'foobar')
     rename_preset('Foo Device', 'preset 2', 'foobar')
     self.assertFalse(os.path.exists(f'{PRESETS}/Foo Device/preset 1.json'))
     self.assertTrue(os.path.exists(f'{PRESETS}/Foo Device/foobar.json'))
     self.assertTrue(os.path.exists(f'{PRESETS}/Foo Device/foobar 2.json'))
     self.assertTrue(os.path.exists(f'{PRESETS}/Foo Device/foobar 3.json'))
Exemplo n.º 2
0
    def on_save_preset_clicked(self, _):
        """Save changes to a preset to the file system."""
        new_name = self.get('preset_name_input').get_text()
        try:
            self.save_preset()
            if new_name not in ['', self.selected_preset]:
                rename_preset(self.selected_device, self.selected_preset,
                              new_name)
            # after saving the config, its modification date will be the
            # newest, so populate_presets will automatically select the
            # right one again.
            self.populate_presets()
            self.show_status(CTX_SAVE, f'Saved "{self.selected_preset}"')
            self.check_macro_syntax()

        except PermissionError as error:
            error = str(error)
            self.show_status(CTX_ERROR, 'Error: Permission denied!', error)
            logger.error(error)
Exemplo n.º 3
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()