Skip to content

Commit

Permalink
Show a dialog to remind Kindle users to change Word Wise language
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed May 26, 2024
1 parent 722ba52 commit 0fbe15b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
19 changes: 9 additions & 10 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions error_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0fbe15b

Please sign in to comment.