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 Apr 24, 2021
1 parent 6c5167f commit d4a98cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 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 @@ -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.
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 @@ -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'), (
Expand Down
14 changes: 12 additions & 2 deletions plover/gui_qt/dictionaries_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'],
Expand All @@ -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:
Expand All @@ -177,14 +186,15 @@ 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
for n, dictionary in enumerate(config_dictionaries):
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)
Expand Down

0 comments on commit d4a98cf

Please sign in to comment.