|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from aqt import mw |
| 4 | +from aqt.qt import QByteArray, QSettings # pylint:disable=no-name-in-module |
| 5 | + |
| 6 | +from ..ui.generator_output_dialog_ui import Ui_GeneratorOutputDialog |
| 7 | +from ..ui.generators_window_ui import Ui_GeneratorsWindow |
| 8 | +from ..ui.known_morphs_exporter_dialog_ui import Ui_KnownMorphsExporterDialog |
| 9 | +from ..ui.progression_window_ui import Ui_ProgressionWindow |
| 10 | +from . import extra_settings_keys as keys # pylint:disable=no-name-in-module |
| 11 | +from .extra_settings_keys import ( |
| 12 | + FileFormatsKeys, |
| 13 | + GeneratorsOutputKeys, |
| 14 | + GeneratorsWindowKeys, |
| 15 | + KnownMorphsExporterKeys, |
| 16 | + PreprocessKeys, |
| 17 | + ProgressionWindowKeys, |
| 18 | +) |
| 19 | + |
| 20 | + |
| 21 | +class AnkiMorphsExtraSettings(QSettings): |
| 22 | + def __init__(self) -> None: |
| 23 | + assert mw is not None |
| 24 | + extra_settings_path = Path( |
| 25 | + mw.pm.profileFolder(), "ankimorphs_extra_settings.ini" |
| 26 | + ) |
| 27 | + super().__init__(str(extra_settings_path), QSettings.Format.IniFormat) |
| 28 | + |
| 29 | + def save_generators_window_settings( |
| 30 | + self, ui: Ui_GeneratorsWindow, geometry: QByteArray |
| 31 | + ) -> None: |
| 32 | + # fmt: off |
| 33 | + self.beginGroup(keys.Dialogs.GENERATORS_WINDOW) |
| 34 | + self.setValue(GeneratorsWindowKeys.WINDOW_GEOMETRY, geometry) |
| 35 | + self.setValue(GeneratorsWindowKeys.MORPHEMIZER, ui.morphemizerComboBox.currentText()) |
| 36 | + self.setValue(GeneratorsWindowKeys.INPUT_DIR, ui.inputDirLineEdit.text()) |
| 37 | + |
| 38 | + self.beginGroup(GeneratorsWindowKeys.FILE_FORMATS) |
| 39 | + self.setValue(FileFormatsKeys.TXT, ui.txtFilesCheckBox.isChecked()) |
| 40 | + self.setValue(FileFormatsKeys.SRT, ui.srtFilesCheckBox.isChecked()) |
| 41 | + self.setValue(FileFormatsKeys.VTT, ui.vttFilesCheckBox.isChecked()) |
| 42 | + self.setValue(FileFormatsKeys.MD, ui.mdFilesCheckBox.isChecked()) |
| 43 | + self.endGroup() # file format group |
| 44 | + |
| 45 | + self.beginGroup(GeneratorsWindowKeys.PREPROCESS) |
| 46 | + self.setValue(PreprocessKeys.IGNORE_SQUARE_BRACKETS, ui.squareBracketsCheckBox.isChecked()) |
| 47 | + self.setValue(PreprocessKeys.IGNORE_ROUND_BRACKETS, ui.roundBracketsCheckBox.isChecked()) |
| 48 | + self.setValue(PreprocessKeys.IGNORE_SLIM_ROUND_BRACKETS, ui.slimRoundBracketsCheckBox.isChecked()) |
| 49 | + self.setValue(PreprocessKeys.IGNORE_NAMES_MORPHEMIZER, ui.namesMorphemizerCheckBox.isChecked()) |
| 50 | + self.setValue(PreprocessKeys.IGNORE_NAMES_IN_FILE, ui.namesFileCheckBox.isChecked()) |
| 51 | + self.setValue(PreprocessKeys.IGNORE_NUMBERS, ui.numbersCheckBox.isChecked()) |
| 52 | + self.endGroup() # preprocess group |
| 53 | + self.endGroup() # generators window group |
| 54 | + # fmt: on |
| 55 | + |
| 56 | + def save_known_morphs_exporter_settings( |
| 57 | + self, ui: Ui_KnownMorphsExporterDialog, geometry: QByteArray |
| 58 | + ) -> None: |
| 59 | + # fmt: off |
| 60 | + self.beginGroup(keys.Dialogs.KNOWN_MORPHS_EXPORTER) |
| 61 | + self.setValue(KnownMorphsExporterKeys.WINDOW_GEOMETRY, geometry) |
| 62 | + self.setValue(KnownMorphsExporterKeys.OUTPUT_DIR, ui.outputLineEdit.text()) |
| 63 | + self.setValue(KnownMorphsExporterKeys.LEMMA, ui.storeOnlyMorphLemmaRadioButton.isChecked()) |
| 64 | + self.setValue(KnownMorphsExporterKeys.INFLECTION, ui.storeMorphLemmaAndInflectionRadioButton.isChecked()) |
| 65 | + self.setValue(KnownMorphsExporterKeys.INTERVAL, ui.knownIntervalSpinBox.value()) |
| 66 | + self.setValue(KnownMorphsExporterKeys.OCCURRENCES, ui.addOccurrencesColumnCheckBox.isChecked()) |
| 67 | + self.endGroup() |
| 68 | + # fmt: on |
| 69 | + |
| 70 | + def save_progression_window_settings( |
| 71 | + self, ui: Ui_ProgressionWindow, geometry: QByteArray |
| 72 | + ) -> None: |
| 73 | + # fmt: off |
| 74 | + self.beginGroup(keys.Dialogs.PROGRESSION_WINDOW) |
| 75 | + self.setValue(KnownMorphsExporterKeys.WINDOW_GEOMETRY, geometry) |
| 76 | + self.setValue(ProgressionWindowKeys.PRIORITY_FILE, ui.morphPriorityCBox.currentText()) |
| 77 | + self.setValue(ProgressionWindowKeys.LEMMA_EVALUATION, ui.lemmaRadioButton.isChecked()) |
| 78 | + self.setValue(ProgressionWindowKeys.INFLECTION_EVALUATION, ui.inflectionRadioButton.isChecked()) |
| 79 | + self.setValue(ProgressionWindowKeys.PRIORITY_RANGE_START, ui.minPrioritySpinBox.value()) |
| 80 | + self.setValue(ProgressionWindowKeys.PRIORITY_RANGE_END, ui.maxPrioritySpinBox.value()) |
| 81 | + self.setValue(ProgressionWindowKeys.BIN_SIZE, ui.binSizeSpinBox.value()) |
| 82 | + self.setValue(ProgressionWindowKeys.BIN_TYPE_NORMAL, ui.normalRadioButton.isChecked()) |
| 83 | + self.setValue(ProgressionWindowKeys.BIN_TYPE_CUMULATIVE, ui.cumulativeRadioButton.isChecked()) |
| 84 | + self.endGroup() |
| 85 | + # fmt: on |
| 86 | + |
| 87 | + def save_generator_priority_file_settings( |
| 88 | + self, ui: Ui_GeneratorOutputDialog, geometry: QByteArray |
| 89 | + ) -> None: |
| 90 | + # fmt: off |
| 91 | + self.beginGroup(keys.Dialogs.GENERATOR_OUTPUT_PRIORITY_FILE) |
| 92 | + self.setValue(GeneratorsOutputKeys.WINDOW_GEOMETRY, geometry) |
| 93 | + self.setValue(GeneratorsOutputKeys.OUTPUT_FILE_PATH, ui.outputLineEdit.text()) |
| 94 | + self.setValue(GeneratorsOutputKeys.LEMMA_FORMAT, ui.storeOnlyMorphLemmaRadioButton.isChecked()) |
| 95 | + self.setValue(GeneratorsOutputKeys.INFLECTION_FORMAT, ui.storeMorphLemmaAndInflectionRadioButton.isChecked()) |
| 96 | + self.setValue(GeneratorsOutputKeys.MIN_OCCURRENCE_SELECTED, ui.minOccurrenceRadioButton.isChecked()) |
| 97 | + self.setValue(GeneratorsOutputKeys.MIN_OCCURRENCE_CUTOFF, ui.minOccurrenceSpinBox.value()) |
| 98 | + self.setValue(GeneratorsOutputKeys.COMPREHENSION_SELECTED, ui.comprehensionRadioButton.isChecked()) |
| 99 | + self.setValue(GeneratorsOutputKeys.COMPREHENSION_CUTOFF, ui.comprehensionSpinBox.value()) |
| 100 | + self.setValue(GeneratorsOutputKeys.OCCURRENCES_COLUMN_SELECTED, ui.addOccurrencesColumnCheckBox.isChecked()) |
| 101 | + self.endGroup() |
| 102 | + # fmt: on |
| 103 | + |
| 104 | + def save_generator_study_plan_settings( |
| 105 | + self, ui: Ui_GeneratorOutputDialog, geometry: QByteArray |
| 106 | + ) -> None: |
| 107 | + # fmt: off |
| 108 | + self.beginGroup(keys.Dialogs.GENERATOR_OUTPUT_STUDY_PLAN) |
| 109 | + self.setValue(GeneratorsOutputKeys.WINDOW_GEOMETRY, geometry) |
| 110 | + self.setValue(GeneratorsOutputKeys.OUTPUT_FILE_PATH, ui.outputLineEdit.text()) |
| 111 | + self.setValue(GeneratorsOutputKeys.LEMMA_FORMAT, ui.storeOnlyMorphLemmaRadioButton.isChecked()) |
| 112 | + self.setValue(GeneratorsOutputKeys.INFLECTION_FORMAT, ui.storeMorphLemmaAndInflectionRadioButton.isChecked()) |
| 113 | + self.setValue(GeneratorsOutputKeys.MIN_OCCURRENCE_SELECTED, ui.minOccurrenceRadioButton.isChecked()) |
| 114 | + self.setValue(GeneratorsOutputKeys.MIN_OCCURRENCE_CUTOFF, ui.minOccurrenceSpinBox.value()) |
| 115 | + self.setValue(GeneratorsOutputKeys.COMPREHENSION_SELECTED, ui.comprehensionRadioButton.isChecked()) |
| 116 | + self.setValue(GeneratorsOutputKeys.COMPREHENSION_CUTOFF, ui.comprehensionSpinBox.value()) |
| 117 | + self.setValue(GeneratorsOutputKeys.OCCURRENCES_COLUMN_SELECTED, ui.addOccurrencesColumnCheckBox.isChecked()) |
| 118 | + self.endGroup() |
| 119 | + # fmt: on |
0 commit comments