Skip to content

Commit

Permalink
Remove IPA buttons
Browse files Browse the repository at this point in the history
all IPAs are added to footnotes nows
  • Loading branch information
xxyzz committed Mar 14, 2024
1 parent e94c980 commit f055722
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 76 deletions.
2 changes: 0 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
prefs.defaults["preferred_formats"] = ["KFX", "AZW3", "AZW", "MOBI", "EPUB"]
prefs.defaults["use_all_formats"] = False
prefs.defaults["minimal_x_ray_count"] = 1
prefs.defaults["en_ipa"] = "ga_ipa"
prefs.defaults["zh_ipa"] = "pinyin"
prefs.defaults["choose_format_manually"] = True
prefs.defaults["wiktionary_gloss_lang"] = "en"
prefs.defaults["kindle_gloss_lang"] = "en"
Expand Down
29 changes: 0 additions & 29 deletions custom_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
custom_lemmas_folder,
get_kindle_klld_path,
get_plugin_path,
load_languages_data,
)

load_translations() # type: ignore
Expand Down Expand Up @@ -151,29 +150,6 @@ def init_wiktionary_buttons(
) -> None:
from .config import prefs

supported_languages = load_languages_data(get_plugin_path())
if (
self.lemma_lang in ["en", "zh"]
and supported_languages[gloss_lang]["gloss_source"] == "kaikki"
):
self.ipa_button = QComboBox()
if self.lemma_lang == "en":
self.ipa_button.addItem(_("General American"), "ga_ipa")
self.ipa_button.addItem(_("Received Pronunciation"), "rp_ipa")
self.ipa_button.setCurrentText(prefs["en_ipa"])
elif self.lemma_lang == "zh":
self.ipa_button.addItem(_("Pinyin"), "pinyin")
self.ipa_button.addItem(_("Bopomofo"), "bopomofo")
self.ipa_button.setCurrentText(_(prefs["zh_ipa"]))

form_layout.addRow(
_("Phonetic transcription system")
if self.lemma_lang == "zh"
else _("International Phonetic Alphabet"),
self.ipa_button,
)
self.ipa_button.currentIndexChanged.connect(self.change_ipa)

difficulty_label = QLabel(_("Difficulty limit"))
difficulty_label.setToolTip(
_(
Expand Down Expand Up @@ -307,11 +283,6 @@ def reset_lemmas(self):
self.db_path.unlink()
self.reject()

def change_ipa(self):
from .config import prefs

prefs[f"{self.lemma_lang}_ipa"] = self.ipa_button.currentData()

def set_export_options(self):
option_dialog = ExportOptionsDialog(self)
if not option_dialog.exec():
Expand Down
59 changes: 16 additions & 43 deletions import_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,51 +132,24 @@ def export_lemmas_job(
log: Any = None,
notifications: Any = None,
) -> None:
from .config import prefs
from .utils import get_plugin_path, load_languages_data

conn = sqlite3.connect(db_path)
with open(export_path, "w", encoding="utf-8") as f:
query_sql = "SELECT lemma, pos, full_def, example"
if not is_kindle:
supported_languages = load_languages_data(get_plugin_path())
has_multiple_ipas = (
supported_languages[gloss_lang]["gloss_source"] == "kaikki"
)
if has_multiple_ipas:
if lemma_lang == "en":
query_sql = f", {prefs['en_ipa']}"
elif lemma_lang == "zh":
query_sql = f", {prefs['zh_ipa']}"
else:
query_sql = ", ipa"
query_sql += (
" FROM senses JOIN lemmas ON senses.lemma_id = lemmas.id "
"WHERE difficulty <= ?"
)

query_sql = """
SELECT lemma, pos, full_def, example
FROM senses JOIN lemmas ON senses.lemma_id = lemmas.id
WHERE difficulty <= ?
"""
if only_enabled:
query_sql += " AND enabled = 1"

if is_kindle:
for lemma, pos_type, full_def, example in conn.execute(
query_sql, (difficulty_limit,)
):
back_text = f"<p>{pos_type}</p><p>{full_def}</p>"
if example:
back_text += f"<i>{example}</i>"
f.write(f"{lemma}\t{back_text}\n")
else:
for lemma, pos_type, full_def, example, ipa in conn.execute(
query_sql, (difficulty_limit,)
):
back_text = f"<p>{pos_type}</p>"
if ipa:
ipa = escape(re.sub(r"\t|\n", " ", ipa))
back_text += f"<p>{ipa}</p>"
full_def = escape(re.sub(r"\t|\n", " ", full_def))
back_text += f"<p>{full_def}</p>"
if example:
example = escape(re.sub(r"\t|\n", " ", example))
back_text += f"<i>{example}</i>"
f.write(f"{lemma}\t{back_text}\n")
for lemma, pos_type, full_def, example in conn.execute(
query_sql, (difficulty_limit,)
):
back_text = f"<p>{pos_type}</p>"
full_def = escape(re.sub(r"\t|\n", " ", full_def))
back_text += f"<p>{full_def}</p>"
if example is not None and len(example) > 0:
example = escape(re.sub(r"\t|\n", " ", example))
back_text += f"<i>{example}</i>"
f.write(f"{lemma}\t{back_text}\n")
conn.close()
2 changes: 0 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Prefs(TypedDict):
preferred_formats: list[str]
use_all_formats: bool
mal_x_ray_count: int
en_ipa: str
zh_ipa: str
choose_format_manually: bool
wiktionary_gloss_lang: str
kindle_gloss_lang: str
Expand Down

0 comments on commit f055722

Please sign in to comment.