예제 #1
0
    def test_get_presets(self):
        os.makedirs(os.path.join(PRESETS, '1234'))

        os.mknod(os.path.join(PRESETS, '1234', 'picture.png'))
        self.assertEqual(len(get_presets('1234')), 0)

        os.mknod(os.path.join(PRESETS, '1234', 'foo bar 1.json'))
        time.sleep(0.01)
        os.mknod(os.path.join(PRESETS, '1234', 'foo bar 2.json'))
        # the newest to the front
        self.assertListEqual(get_presets('1234'), ['foo bar 2', 'foo bar 1'])
예제 #2
0
    def populate_presets(self):
        """Show the available presets for the selected device.

        This will destroy unsaved changes in the custom_mapping.
        """
        device = self.selected_device
        presets = get_presets(device)

        if len(presets) == 0:
            new_preset = get_available_preset_name(self.selected_device)
            custom_mapping.empty()
            path = get_preset_path(self.selected_device, new_preset)
            custom_mapping.save(path)
            presets = [new_preset]
        else:
            logger.debug('"%s" presets: "%s"', device, '", "'.join(presets))

        preset_selection = self.get('preset_selection')

        with HandlerDisabled(preset_selection, self.on_select_preset):
            # otherwise the handler is called with None for each preset
            preset_selection.remove_all()

        for preset in presets:
            preset_selection.append(preset, preset)
        # and select the newest one (on the top). triggers on_select_preset
        preset_selection.set_active(0)