diff --git a/plover/config.py b/plover/config.py index 5cafcb81b..1bd7ad276 100644 --- a/plover/config.py +++ b/plover/config.py @@ -7,6 +7,7 @@ import configparser import json import re +import os from plover.exception import InvalidConfigurationError from plover.machine.keymap import Keymap @@ -42,6 +43,10 @@ def __new__(cls, path, enabled=True): def short_path(self): return shorten_path(self.path) + @property + def basename(self): + return os.path.basename(self.path) + def to_dict(self): # Note: do not use _asdict because of # https://bugs.python.org/issue24931 @@ -340,6 +345,7 @@ def _set(self, section, option, value): boolean_option('show_suggestions_display', False, 'Suggestions Display', 'show'), opacity_option('translation_frame_opacity', 'Translation Frame', 'opacity'), boolean_option('classic_dictionaries_display_order', False, 'GUI'), + boolean_option('show_dictionary_basename_only', False, 'GUI'), # Plugins. enabled_extensions_option(), # Machine. diff --git a/plover/gui_qt/config_window.py b/plover/gui_qt/config_window.py index 9ae9af38c..bf4cb8b6d 100644 --- a/plover/gui_qt/config_window.py +++ b/plover/gui_qt/config_window.py @@ -309,6 +309,8 @@ def __init__(self, engine): _('Set the display order for dictionaries:\n' '- top-down: match the search order; highest priority first\n' '- bottom-up: reverse search order; lowest priority first\n')), + ConfigOption(_('Show dictionary base name only:'), 'show_dictionary_basename_only', BooleanOption, + _('Show only the base name of the dictionaries in the dictionaries table.')), )), # i18n: Widget: “ConfigWindow”. (_('Logging'), ( diff --git a/plover/gui_qt/dictionaries_widget.py b/plover/gui_qt/dictionaries_widget.py index 4ffaf3465..a3b7ae218 100644 --- a/plover/gui_qt/dictionaries_widget.py +++ b/plover/gui_qt/dictionaries_widget.py @@ -77,6 +77,7 @@ def __init__(self, *args, **kwargs): self._reverse_order = False # The save/open/new dialogs will open on that directory. self._file_dialogs_directory = CONFIG_DIR + self._show_basename_only = False for action in ( self.action_Undo, self.action_EditDictionaries, @@ -137,6 +138,11 @@ def on_dictionaries_loaded(self, loaded_dictionaries): def on_config_changed(self, config_update): update_kwargs = {} + if 'show_dictionary_basename_only' in config_update: + update_kwargs.update( + show_basename_only=config_update['show_dictionary_basename_only'], + record=False, save=False, + ) if 'dictionaries' in config_update: update_kwargs.update( config_dictionaries=config_update['dictionaries'], @@ -152,13 +158,16 @@ def on_config_changed(self, config_update): def _update_dictionaries(self, config_dictionaries=None, loaded_dictionaries=None, reverse_order=None, record=True, save=True, - reset_undo=False, keep_selection=True): + reset_undo=False, keep_selection=True, show_basename_only=None): if reverse_order is None: reverse_order = self._reverse_order + if show_basename_only is None: + show_basename_only = self._show_basename_only if config_dictionaries is None: config_dictionaries = self._config_dictionaries if config_dictionaries == self._config_dictionaries and \ reverse_order == self._reverse_order and \ + show_basename_only == self._show_basename_only and \ loaded_dictionaries is None: return if save: @@ -177,6 +186,7 @@ def _update_dictionaries(self, config_dictionaries=None, loaded_dictionaries=Non else: self._loaded_dictionaries = loaded_dictionaries self._reverse_order = reverse_order + self._show_basename_only = show_basename_only self._updating = True self.table.setRowCount(len(config_dictionaries)) favorite_set = False @@ -184,7 +194,7 @@ def _update_dictionaries(self, config_dictionaries=None, loaded_dictionaries=Non row = n if self._reverse_order: row = len(config_dictionaries) - row - 1 - item = QTableWidgetItem(dictionary.short_path) + item = QTableWidgetItem(dictionary.basename if show_basename_only else dictionary.short_path) item.setFlags((item.flags() | Qt.ItemIsUserCheckable) & ~Qt.ItemIsEditable) item.setCheckState(Qt.Checked if dictionary.enabled else Qt.Unchecked) item.setToolTip(dictionary.path)