Skip to content

Commit

Permalink
Add option to retain current enabled lemmas when importing file
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Jul 29, 2022
1 parent 9b70ef7 commit a9850e0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions custom_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
QDialog,
QDialogButtonBox,
QFileDialog,
QInputDialog,
QLineEdit,
QPushButton,
QStyledItemDelegate,
Expand Down Expand Up @@ -93,6 +94,16 @@ def search_lemma(self, text):
self.lemmas_table.scrollTo(matches[0])

def select_import_file(self) -> None:
retain_lemmas, ok = QInputDialog.getItem(
self,
"Import file",
"Retain current enabled lemmas",
["True", "False"],
editable=False,
)
if not ok:
return

file_path, _ = QFileDialog.getOpenFileName(
self,
"Select file",
Expand All @@ -111,7 +122,7 @@ def select_import_file(self) -> None:
else:
return

self.lemmas_model.import_lemmas(lemmas_dict)
self.lemmas_model.import_lemmas(lemmas_dict, retain_lemmas == "True")

def reset_lemmas(self):
custom_path = custom_lemmas_dump_path(get_plugin_path())
Expand Down Expand Up @@ -188,11 +199,21 @@ def setData(self, index, value, role):
return True
return False

def import_lemmas(self, lemmas_dict: dict[str, list[int, bool]]) -> None:
def import_lemmas(
self, lemmas_dict: dict[str, list[int, bool]], retain_lemmas: bool
) -> None:
for row in range(self.rowCount(None)):
lemma = self.lemmas[row][1]
enable = Qt.CheckState.Unchecked.value
difficulty = 1
if retain_lemmas:
if self.lemmas[row][0]:
enable = Qt.CheckState.Checked.value
else:
enable = Qt.CheckState.Unchecked.value
if isinstance(self, KindleLemmasTableModel):
difficulty = self.lemmas[row][5]

data = lemmas_dict.get(lemma)
if data and data[1]:
enable = Qt.CheckState.Checked.value
Expand Down

0 comments on commit a9850e0

Please sign in to comment.