Beispiel #1
0
    def __init__(config):
        super(Config, config).__init__()

        # populate values first from the default config file, then from the proper one
        config.read(util.get_default_config())
        config.load_window_layouts()

        all_commands = dict(config.items('shortcuts')).keys()

        config.read(config.path_to_config(True))
        config.upgrade()
        config.load_window_layouts()

        for command in all_commands:
            parsed = {
                Gtk.accelerator_parse(keys)
                for keys in config.get('shortcuts', command).split()
            }

            if (0, 0) in parsed:
                logger.warning('Failed parsing 1 or more shortcuts for ' +
                               command)
                parsed.remove((0, 0))

            config.shortcuts.update({s: command for s in parsed})
Beispiel #2
0
    def __init__(config):
        # Remove : from delimiters so we can use it in preferences
        super(Config, config).__init__(delimiters=('=', ))

        # populate values first from the default config file, then from the proper one
        config.read(util.get_default_config())
        config.load_window_layouts()

        all_commands = dict(config.items('shortcuts')).keys()

        config.read(config.path_to_config(True))
        config.upgrade()
        config.load_window_layouts()

        for command in all_commands:
            # NB only parsing commands from defaults
            parse_ok, action_name, target_value = Gio.Action.parse_detailed_name(
                'app.' + command)
            if not parse_ok or not Gio.action_name_is_valid(action_name):
                logger.error('Failed parsing command ' + command)
                continue

            parsed_accels = {
                keys: Gtk.accelerator_parse(keys)
                for keys in config.get('shortcuts', command).split()
            }
            failed = [
                keys for keys, parsed in parsed_accels.items()
                if parsed == (0, 0)
            ]
            if failed:
                logger.warning(
                    'Failed parsing shortcut(s) for "{}": "{}"'.format(
                        command, '", "'.join(failed)))

            keep_accels = [
                keys for keys, parsed in parsed_accels.items()
                if parsed != (0, 0)
            ]
            if keep_accels:
                config.shortcuts[command] = keep_accels