Skip to content

Commit

Permalink
Add an option to only show dictionaries basename
Browse files Browse the repository at this point in the history
  • Loading branch information
user202729 committed Jun 27, 2023
1 parent 9057504 commit fc6df86
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions plover/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import configparser
import json
import re
import os

from plover.exception import InvalidConfigurationError
from plover.machine.keymap import Keymap
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions plover/gui_qt/config_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'), (
Expand Down
17 changes: 14 additions & 3 deletions plover/gui_qt/dictionaries_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fc6df86

Please sign in to comment.