From 0fbe15b84c25b52495edf6748856c2874fb8f0db Mon Sep 17 00:00:00 2001 From: xxyzz Date: Sun, 26 May 2024 17:39:10 +0800 Subject: [PATCH] Show a dialog to remind Kindle users to change Word Wise language --- config.py | 19 +++++++++---------- error_dialogs.py | 16 ++++++++++++++++ utils.py | 1 + 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index 64882ea..32c8a41 100644 --- a/config.py +++ b/config.py @@ -30,7 +30,7 @@ from .custom_lemmas import CustomLemmasDialog from .deps import download_word_wise_file, install_deps, which_python from .dump_lemmas import dump_spacy_docs -from .error_dialogs import GITHUB_URL, job_failed +from .error_dialogs import GITHUB_URL, change_kindle_ww_lang_dialog, job_failed from .import_lemmas import apply_imported_lemmas_data, export_lemmas_job from .utils import ( donate, @@ -62,6 +62,7 @@ prefs.defaults["use_wiktionary_for_kindle"] = False prefs.defaults["remove_link_styles"] = False prefs.defaults["python_path"] = "" +prefs.defaults["show_change_kindle_ww_lang_warning"] = True for code in load_plugin_json(get_plugin_path(), "data/languages.json").keys(): prefs.defaults[f"{code}_wiktionary_difficulty_limit"] = 5 @@ -504,17 +505,13 @@ def __init__(self, parent: QObject, is_kindle: bool): if is_kindle: self.use_wiktionary_box = QCheckBox("") - self.kindle_lang_changed() + self.kindle_lang_changed(True) self.lemma_lang_box.currentIndexChanged.connect(self.kindle_lang_changed) self.gloss_lang_box.currentIndexChanged.connect(self.kindle_lang_changed) - wiktionary_gloss_label = QLabel(_("Use Wiktionary definition 🛈")) - wiktionary_gloss_label.setToolTip( - _( - "Change Word Wise language to Chinese on your Kindle device to " - "view definition from Wiktionary" - ) + self.use_wiktionary_box.toggled.connect( + partial(change_kindle_ww_lang_dialog, parent=self, prefs=prefs) ) - form_layout.addRow(wiktionary_gloss_label, self.use_wiktionary_box) + form_layout.addRow(_("Use Wiktionary definition"), self.use_wiktionary_box) confirm_button_box = QDialogButtonBox( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel @@ -527,7 +524,7 @@ def __init__(self, parent: QObject, is_kindle: bool): vl.addWidget(confirm_button_box) self.setLayout(vl) - def kindle_lang_changed(self) -> None: + def kindle_lang_changed(self, first_call: bool = False) -> None: if ( self.lemma_lang_box.currentData() == "en" and self.gloss_lang_box.currentData() in ["en", "zh", "zh_cn"] @@ -537,6 +534,8 @@ def kindle_lang_changed(self) -> None: else: self.use_wiktionary_box.setChecked(True) self.use_wiktionary_box.setDisabled(True) + if not first_call: + change_kindle_ww_lang_dialog(True, self, prefs) def gloss_lang_changed(self, lang_dict) -> None: gloss_lang = self.gloss_lang_box.currentData() diff --git a/error_dialogs.py b/error_dialogs.py index c6dabc4..cef5e66 100644 --- a/error_dialogs.py +++ b/error_dialogs.py @@ -212,3 +212,19 @@ def unsupported_ww_lang_dialog() -> None: _("Unsupported language"), _("Book language is not supported for the selected Word Wise gloss language."), ) + + +def change_kindle_ww_lang_dialog( + checked: bool, parent: Any = None, prefs: Any = None +) -> None: + if checked and prefs["show_change_kindle_ww_lang_warning"]: + warning_dialog( + "", + _( + "Word Wise language must be set to Chinese on Kindle to display the " + 'correct definitions when the "Use Wiktionary definition" option is ' + "enabled." + ), + parent, + ) + prefs["show_change_kindle_ww_lang_warning"] = False diff --git a/utils.py b/utils.py index 8e1b953..c8dec37 100644 --- a/utils.py +++ b/utils.py @@ -35,6 +35,7 @@ class Prefs(TypedDict): last_opened_wiktionary_lemmas_language: str use_wiktionary_for_kindle: bool python_path: str + show_change_kindle_ww_lang_warning: bool def load_plugin_json(plugin_path: Path, filepath: str) -> Any: