|
1 | 1 | from collections import namedtuple, OrderedDict |
2 | 2 | from functools import wraps |
3 | 3 | from queue import Queue |
| 4 | +import functools |
4 | 5 | import os |
5 | 6 | import shutil |
6 | 7 | import threading |
7 | 8 |
|
8 | 9 | from plover import log, system |
9 | 10 | from plover.dictionary.loading_manager import DictionaryLoadingManager |
10 | | -from plover.exception import DictionaryLoaderException |
11 | 11 | from plover.formatting import Formatter |
12 | 12 | from plover.misc import shorten_path |
13 | 13 | from plover.registry import registry |
@@ -83,6 +83,7 @@ class StenoEngine: |
83 | 83 | output_changed |
84 | 84 | config_changed |
85 | 85 | dictionaries_loaded |
| 86 | + dictionary_state_changed |
86 | 87 | send_string |
87 | 88 | send_backspaces |
88 | 89 | send_key_combination |
@@ -116,8 +117,10 @@ def __init__(self, config, controller, keyboard_emulation): |
116 | 117 | self._translator = Translator() |
117 | 118 | self._translator.add_listener(log.translation) |
118 | 119 | self._translator.add_listener(self._formatter.format) |
119 | | - self._dictionaries = self._translator.get_dictionary() |
120 | | - self._dictionaries_manager = DictionaryLoadingManager() |
| 120 | + self._dictionaries = self._translator.get_dictionary() # type: StenoDictionaryCollection |
| 121 | + self._dictionaries_manager = DictionaryLoadingManager( |
| 122 | + functools.partial(self._trigger_hook, "dictionary_state_changed") |
| 123 | + ) |
121 | 124 | self._running_state = self._translator.get_state() |
122 | 125 | self._translator.clear_state() |
123 | 126 | self._keyboard_emulation = keyboard_emulation |
@@ -282,18 +285,15 @@ def _update(self, config_update=None, full=False, reset_machine=False): |
282 | 285 | ) |
283 | 286 | # And then (re)load all dictionaries. |
284 | 287 | dictionaries = [] |
285 | | - for result in self._dictionaries_manager.load(config_dictionaries.keys()): |
286 | | - if isinstance(result, DictionaryLoaderException): |
287 | | - d = ErroredDictionary(result.path, result.exception) |
| 288 | + for d in self._dictionaries_manager.load(config_dictionaries.keys()): |
| 289 | + if isinstance(d, ErroredDictionary): |
288 | 290 | # Only show an error if it's new. |
289 | | - if d != self._dictionaries.get(result.path): |
| 291 | + if d != self._dictionaries.get(d.path): |
290 | 292 | log.error( |
291 | 293 | "loading dictionary `%s` failed: %s", |
292 | | - shorten_path(result.path), |
293 | | - str(result.exception), |
| 294 | + shorten_path(d.path), |
| 295 | + str(d.exception), |
294 | 296 | ) |
295 | | - else: |
296 | | - d = result |
297 | 297 | d.enabled = config_dictionaries[d.path].enabled |
298 | 298 | dictionaries.append(d) |
299 | 299 | self._set_dictionaries(dictionaries) |
|
0 commit comments