From fc6df862d75cff8d75a40f9deae17c78aad3411a Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:57:20 +0700 Subject: [PATCH 1/2] Add an option to only show dictionaries basename --- plover/config.py | 6 ++++++ plover/gui_qt/config_window.py | 2 ++ plover/gui_qt/dictionaries_widget.py | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/plover/config.py b/plover/config.py index fac9048e1..408ce17f6 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 @@ -343,6 +348,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 7cc4b6948..0dfc76f92 100644 --- a/plover/gui_qt/config_window.py +++ b/plover/gui_qt/config_window.py @@ -334,6 +334,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 043bb0e08..bec9ae20c 100644 --- a/plover/gui_qt/dictionaries_widget.py +++ b/plover/gui_qt/dictionaries_widget.py @@ -70,6 +70,10 @@ def __init__(self, row, config, loaded=None): self.short_path = config.short_path self.loaded = loaded + @property + def basename(self): + return os.path.basename(self.path) + @property def loaded(self): return self._loaded @@ -114,6 +118,7 @@ def __init__(self, engine, icons, max_undo=20): self._undo_stack = [] self._max_undo = max_undo self._icons = icons + self._show_basename_only = False with engine: config = engine.config engine.signal_connect('config_changed', self._on_config_changed) @@ -163,11 +168,13 @@ def _update_favorite(self): filter(None, (old, new)) } - def _reset_items(self, config, reverse_order=None, backup=True, publish=True): + def _reset_items(self, config, reverse_order=None, show_basename_only=None, backup=True, publish=True): if backup: self._backup_config() if reverse_order is None: reverse_order = self._reverse_order + if show_basename_only is None: + show_basename_only = self._show_basename_only self.layoutAboutToBeChanged.emit() old_persistent_indexes = self.persistentIndexList() assert all(index.isValid() for index in old_persistent_indexes) @@ -187,6 +194,7 @@ def _reset_items(self, config, reverse_order=None, backup=True, publish=True): assert d.path not in from_path from_path[d.path] = item from_row.append(item) + self._show_basename_only = show_basename_only self._reverse_order = reverse_order self._from_path = from_path self._from_row = from_row @@ -208,9 +216,12 @@ def _reset_items(self, config, reverse_order=None, backup=True, publish=True): def _on_config_changed(self, config_update): config = config_update.get('dictionaries') reverse_order = config_update.get('classic_dictionaries_display_order') + show_basename_only = config_update.get('show_dictionary_basename_only') noop = True if reverse_order is not None: noop = reverse_order == self._reverse_order + if show_basename_only is not None: + noop = show_basename_only == self._show_basename_only if config is not None: noop = noop and config == self._config if noop: @@ -221,7 +232,7 @@ def _on_config_changed(self, config_update): if self._undo_stack: self.has_undo_changed.emit(False) self._undo_stack.clear() - self._reset_items(config, reverse_order, + self._reset_items(config, reverse_order, show_basename_only=show_basename_only, backup=False, publish=False) def _on_dictionaries_loaded(self, loaded_dictionaries): @@ -363,7 +374,7 @@ def data(self, index, role): return None d = self._from_row[index.row()] if role == Qt.DisplayRole: - return d.short_path + return d.basename if self._show_basename_only else d.short_path if role == Qt.CheckStateRole: return Qt.Checked if d.enabled else Qt.Unchecked if role == Qt.AccessibleTextRole: From 619453d6015257ddea6cf5007b32bb504a7238c2 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:02:31 +0700 Subject: [PATCH 2/2] Add news fragment --- news.d/feature/1162.ui.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news.d/feature/1162.ui.md diff --git a/news.d/feature/1162.ui.md b/news.d/feature/1162.ui.md new file mode 100644 index 000000000..98ea8dec4 --- /dev/null +++ b/news.d/feature/1162.ui.md @@ -0,0 +1 @@ +Add an option to only show dictionaries basename.