|
| 1 | +import copy |
| 2 | +from pathlib import Path |
| 3 | +from typing import Any |
| 4 | + |
| 5 | +from PySide6.QtWidgets import ( |
| 6 | + QCheckBox, |
| 7 | + QComboBox, |
| 8 | + QHBoxLayout, |
| 9 | + QLabel, |
| 10 | + QVBoxLayout, |
| 11 | +) |
| 12 | +from src.core.settings import TSSettings |
| 13 | +from src.qt.widgets.panel import PanelWidget |
| 14 | + |
| 15 | + |
| 16 | +class SettingsModal(PanelWidget): |
| 17 | + def __init__(self, settings: TSSettings): |
| 18 | + super().__init__() |
| 19 | + self.tempSettings: TSSettings = copy.deepcopy(settings) |
| 20 | + |
| 21 | + self.main = QVBoxLayout(self) |
| 22 | + |
| 23 | + # --- |
| 24 | + self.language_Label = QLabel() |
| 25 | + self.language_Value = QComboBox() |
| 26 | + self.language_Row = QHBoxLayout() |
| 27 | + self.language_Row.addWidget(self.language_Label) |
| 28 | + self.language_Row.addWidget(self.language_Value) |
| 29 | + |
| 30 | + self.language_Label.setText("Language") |
| 31 | + translations_folder = Path("tagstudio/resources/translations") |
| 32 | + language_list = [x.stem for x in translations_folder.glob("*.json")] |
| 33 | + self.language_Value.addItems(language_list) |
| 34 | + self.language_Value.setCurrentIndex(language_list.index(self.tempSettings.language)) |
| 35 | + self.language_Value.currentTextChanged.connect( |
| 36 | + lambda text: setattr(self.tempSettings, "language", text) |
| 37 | + ) |
| 38 | + |
| 39 | + # --- |
| 40 | + self.show_library_list_Label = QLabel() |
| 41 | + self.show_library_list_Value = QCheckBox() |
| 42 | + self.show_library_list_Row = QHBoxLayout() |
| 43 | + self.show_library_list_Row.addWidget(self.show_library_list_Label) |
| 44 | + self.show_library_list_Row.addWidget(self.show_library_list_Value) |
| 45 | + self.show_library_list_Label.setText("Load library list on startup (requires restart):") |
| 46 | + self.show_library_list_Value.setChecked(self.tempSettings.show_library_list) |
| 47 | + |
| 48 | + self.show_library_list_Value.stateChanged.connect( |
| 49 | + lambda state: setattr(self.tempSettings, "show_library_list", bool(state)) |
| 50 | + ) |
| 51 | + |
| 52 | + # --- |
| 53 | + self.show_filenames_Label = QLabel() |
| 54 | + self.show_filenames_Value = QCheckBox() |
| 55 | + self.show_filenames_Row = QHBoxLayout() |
| 56 | + self.show_filenames_Row.addWidget(self.show_filenames_Label) |
| 57 | + self.show_filenames_Row.addWidget(self.show_filenames_Value) |
| 58 | + self.show_filenames_Label.setText("Show filenames in grid (requires restart)") |
| 59 | + self.show_filenames_Value.setChecked(self.tempSettings.show_filenames_in_grid) |
| 60 | + |
| 61 | + self.show_filenames_Value.stateChanged.connect( |
| 62 | + lambda state: setattr(self.tempSettings, "show_filenames_in_grid", bool(state)) |
| 63 | + ) |
| 64 | + # --- |
| 65 | + self.main.addLayout(self.language_Row) |
| 66 | + self.main.addLayout(self.show_library_list_Row) |
| 67 | + self.main.addLayout(self.show_filenames_Row) |
| 68 | + |
| 69 | + def set_property(self, prop_name: str, value: Any) -> None: |
| 70 | + setattr(self.tempSettings, prop_name, value) |
| 71 | + |
| 72 | + def get_content(self): |
| 73 | + return self.tempSettings |
0 commit comments