Skip to content

Commit 640c962

Browse files
committed
feat: finish basic settings menu
1 parent e3d90a7 commit 640c962

File tree

8 files changed

+31
-41
lines changed

8 files changed

+31
-41
lines changed

tagstudio/src/core/settings/tssettings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from pathlib import Path
2+
from typing import Any
23

34
import toml
45
from pydantic import BaseModel, Field
5-
from typing import Any
66

77

88
# NOTE: pydantic also has a BaseSettings class (from pydantic-settings) that allows any settings
99
# properties to be overwritten with environment variables. as tagstudio is not currently using
1010
# environment variables, i did not base it on that, but that may be useful in the future.
1111
class TSSettings(BaseModel):
1212
dark_mode: bool = Field(default=False)
13-
language: str = Field(default="en-US")
13+
language: str = Field(default="en")
1414

1515
# settings from the old SettingItem enum
1616
open_last_loaded_on_startup: bool = Field(default=False)

tagstudio/src/core/tscacheddata.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class TSCachedData(BaseModel):
2323
@staticmethod
2424
def open(path: str | None = None) -> "TSCachedData":
2525
file: str | None = None
26-
2726
if path is None:
2827
if not Path(cache_dir).exists():
2928
logger.info("Cache directory does not exist - creating", path=cache_dir)
@@ -33,7 +32,10 @@ def open(path: str | None = None) -> "TSCachedData":
3332
open(cache_location, "w").close()
3433
file = str(cache_location)
3534
else:
36-
file = path
35+
if not Path(path).exists():
36+
logger.info("Cache file does not exist - creating", path=path)
37+
open(path, "w").close()
38+
file = str(path)
3739

3840
data = toml.load(file)
3941
data["path"] = str(path) if path is not None else str(cache_location)

tagstudio/src/qt/modals/settings_modal.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import copy
2+
from pathlib import Path
3+
from typing import Any
24

35
from PySide6.QtWidgets import (
46
QCheckBox,
@@ -7,9 +9,8 @@
79
QLabel,
810
QVBoxLayout,
911
)
10-
from src.core.settings import TSSettings
12+
from src.core.settings import TSSettings
1113
from src.qt.widgets.panel import PanelWidget
12-
from typing import Any
1314

1415

1516
class SettingsModal(PanelWidget):
@@ -19,20 +20,6 @@ def __init__(self, settings: TSSettings):
1920

2021
self.main = QVBoxLayout(self)
2122

22-
# ---
23-
self.darkMode_Label = QLabel()
24-
self.darkMode_Value = QCheckBox()
25-
self.darkMode_Row = QHBoxLayout()
26-
self.darkMode_Row.addWidget(self.darkMode_Label)
27-
self.darkMode_Row.addWidget(self.darkMode_Value)
28-
29-
self.darkMode_Label.setText("Dark Mode")
30-
self.darkMode_Value.setChecked(self.tempSettings.dark_mode)
31-
32-
self.darkMode_Value.stateChanged.connect(
33-
lambda state: setattr(self.tempSettings, "dark_mode", bool(state))
34-
)
35-
3623
# ---
3724
self.language_Label = QLabel()
3825
self.language_Value = QComboBox()
@@ -41,12 +28,8 @@ def __init__(self, settings: TSSettings):
4128
self.language_Row.addWidget(self.language_Value)
4229

4330
self.language_Label.setText("Language")
44-
language_list = [ # TODO: put this somewhere else
45-
"en-US",
46-
"en-GB",
47-
"es-MX",
48-
# etc...
49-
]
31+
translations_folder = Path("tagstudio/resources/translations")
32+
language_list = [x.stem for x in translations_folder.glob("*.json")]
5033
self.language_Value.addItems(language_list)
5134
self.language_Value.setCurrentIndex(language_list.index(self.tempSettings.language))
5235
self.language_Value.currentTextChanged.connect(
@@ -59,7 +42,7 @@ def __init__(self, settings: TSSettings):
5942
self.show_library_list_Row = QHBoxLayout()
6043
self.show_library_list_Row.addWidget(self.show_library_list_Label)
6144
self.show_library_list_Row.addWidget(self.show_library_list_Value)
62-
self.show_library_list_Label.setText("Load library list on startup:")
45+
self.show_library_list_Label.setText("Load library list on startup (requires restart):")
6346
self.show_library_list_Value.setChecked(self.tempSettings.show_library_list)
6447

6548
self.show_library_list_Value.stateChanged.connect(

tagstudio/src/qt/translations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def value(self) -> str:
3030

3131
@value.setter
3232
def value(self, value: str):
33-
if self.__value != value:
33+
if self.__value != value and value is not None:
3434
self.__value = value
3535
self.changed.emit(self.__value)
3636

tagstudio/src/qt/ts_qt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,9 @@ def __init__(self, backend, args):
183183

184184
self.settings = TSSettings.read_settings(path)
185185
logger.info(
186-
"Config File not specified, using default one",
187-
filename=self.settings.filename,
186+
"Config File not specified, using default one", filename=self.settings.filename
188187
)
189-
188+
Translations.change_language(self.settings.language)
190189
self.cache = TSCachedData.open()
191190

192191
def init_workers(self):
@@ -706,6 +705,7 @@ def open_settings_menu(self):
706705
def update_settings(self, settings: TSSettings):
707706
self.settings = settings
708707
self.settings.save(self.settings.filename)
708+
Translations.change_language(self.settings.language)
709709

710710
def select_all_action_callback(self):
711711
self.selected = list(range(0, len(self.frame_content)))
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
dark_mode = true
2-
language = "es-MX"
1+
language = "en"
2+
open_last_loaded_on_startup = false
3+
show_filenames_in_grid = true
4+
autoplay = false

tagstudio/tests/test_driver.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, settings, cache: TSCachedData | None = None):
1818

1919
def test_evaluate_path_empty():
2020
# Given
21-
settings = TSSettings(**dict())
21+
settings = TSSettings(**dict(filename=""))
2222
driver = TestDriver(settings)
2323

2424
# When
@@ -30,7 +30,7 @@ def test_evaluate_path_empty():
3030

3131
def test_evaluate_path_missing():
3232
# Given
33-
settings = TSSettings(**dict())
33+
settings = TSSettings(**dict(filename=""))
3434
driver = TestDriver(settings)
3535

3636
# When
@@ -42,8 +42,8 @@ def test_evaluate_path_missing():
4242

4343
def test_evaluate_path_last_lib_not_exists():
4444
# Given
45-
settings = TSSettings(**dict())
46-
cache = TSCachedData()
45+
settings = TSSettings(**dict(filename=""))
46+
cache = TSCachedData.open()
4747
cache.last_library = "/0/4/5/1/"
4848
driver = TestDriver(settings, cache)
4949

@@ -63,10 +63,11 @@ def test_evaluate_path_last_lib_present():
6363
cache.save()
6464

6565
makedirs(Path(tmpdir) / TS_FOLDER_NAME)
66-
driver = TestDriver(TSSettings(**dict()), cache)
66+
driver = TestDriver(
67+
TSSettings(**dict(filename="", open_last_loaded_on_startup=True)), cache
68+
)
6769

6870
# When
6971
result = driver.evaluate_path(None)
70-
7172
# Then
7273
assert result == LibraryStatus(success=True, library_path=Path(tmpdir))

tagstudio/tests/test_settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77

88
def test_read_settings():
99
settings = TSSettings.read_settings(CWD.parent / "example_settings.toml")
10-
assert settings.dark_mode
11-
assert settings.language == "es-MX"
10+
assert settings.language == "en"
11+
assert not settings.open_last_loaded_on_startup
12+
assert settings.show_filenames_in_grid
13+
assert not settings.autoplay

0 commit comments

Comments
 (0)