-
-
Notifications
You must be signed in to change notification settings - Fork 431
feat: settings menu #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CyanVoxel
merged 35 commits into
TagStudioDev:main
from
Computerdores:feat/settings_menu
Mar 25, 2025
Merged
feat: settings menu #859
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
5b3ad20
feat: add tab widget
Computerdores 0c942e2
refactor: move languages dict to translations.py
Computerdores 2403529
refactor: move build of Settings Modal to SettingsPanel class
Computerdores 7968cff
feat: hide title label
Computerdores c65eec6
feat: global settings class
Computerdores fad74a0
fix: initialise settings
Computerdores a56d70c
fix: properly store grid files changes
Computerdores 84384f4
fix: placeholder text for library settings
Computerdores 2593b59
feat: add ui elements for remaining global settings
Computerdores 4e7406f
feat: add page size setting
Computerdores feaed58
Merge branch 'main' into feat/settings_menu
Computerdores 7f3d8ca
fix: version mismatch between pydantic and typing_extensions
Computerdores 4aee8d2
Merge branch 'main' into feat/settings_menu
Computerdores e44316c
fix: update test_driver.py
Computerdores 4ef2b16
fix(test_file_path_options): replace patch with change of settings
Computerdores fca2ce4
feat: setting for dark mode
Computerdores 1aba3eb
fix: only show restart_label when necessary
Computerdores 6f0e3ed
fix: change modal from "done" type to "Save/Cancel" type
Computerdores 3023051
feat: add test for GlobalSettings
Computerdores f4621df
docs: mark roadmap item as completed
Computerdores 76972da
fix(test_filepath_setting): Mock the app field of QtDriver
Computerdores 9a41873
Merge branch 'main' into feat/settings_menu
CyanVoxel 14d1e04
Update src/tagstudio/main.py
Computerdores 28a663f
fix: address review suggestions
Computerdores aba2f1c
fix: page size setting
Computerdores eb32baa
feat: change dark mode option to theme dropdown
Computerdores 32a2c2c
fix: test was expecting wrong behaviour
Computerdores 66ac034
fix: test was testing for correct behaviour, fix behaviour instead
Computerdores 740f1ec
fix: test fr fr
Computerdores 67339d6
fix: tests fr fr fr
Computerdores e119b3b
fix: tests fr fr fr fr
Computerdores 01a2bc3
fix: update test
Computerdores 891db6d
fix: tests fr fr fr fr fr
Computerdores de8543e
fix: select all was selecting hidden entries
Computerdores 0478eb4
fix: create more thumbitems as necessary
Computerdores File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Licensed under the GPL-3.0 License. | ||
| # Created for TagStudio: https://github.com/CyanVoxel/TagStudio | ||
|
|
||
| import platform | ||
| from enum import Enum | ||
| from pathlib import Path | ||
| from typing import override | ||
|
|
||
| import structlog | ||
| import toml | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| from tagstudio.core.enums import ShowFilepathOption | ||
|
|
||
| if platform.system() == "Windows": | ||
| DEFAULT_GLOBAL_SETTINGS_PATH = ( | ||
| Path.home() / "Appdata" / "Roaming" / "TagStudio" / "settings.toml" | ||
| ) | ||
| else: | ||
| DEFAULT_GLOBAL_SETTINGS_PATH = Path.home() / ".config" / "TagStudio" / "settings.toml" | ||
|
|
||
| logger = structlog.get_logger(__name__) | ||
|
|
||
|
|
||
| class TomlEnumEncoder(toml.TomlEncoder): | ||
| @override | ||
| def dump_value(self, v): | ||
| if isinstance(v, Enum): | ||
| return super().dump_value(v.value) | ||
| return super().dump_value(v) | ||
|
|
||
|
|
||
| class Theme(Enum): | ||
| DARK = 0 | ||
| LIGHT = 1 | ||
| SYSTEM = 2 | ||
| DEFAULT = SYSTEM | ||
|
|
||
|
|
||
| # NOTE: pydantic also has a BaseSettings class (from pydantic-settings) that allows any settings | ||
| # properties to be overwritten with environment variables. as tagstudio is not currently using | ||
| # environment variables, i did not base it on that, but that may be useful in the future. | ||
| class GlobalSettings(BaseModel): | ||
| language: str = Field(default="en") | ||
| open_last_loaded_on_startup: bool = Field(default=False) | ||
| autoplay: bool = Field(default=False) | ||
| show_filenames_in_grid: bool = Field(default=False) | ||
| page_size: int = Field(default=500) | ||
| show_filepath: ShowFilepathOption = Field(default=ShowFilepathOption.DEFAULT) | ||
| theme: Theme = Field(default=Theme.SYSTEM) | ||
|
|
||
| @staticmethod | ||
| def read_settings(path: Path = DEFAULT_GLOBAL_SETTINGS_PATH) -> "GlobalSettings": | ||
| if path.exists(): | ||
| with open(path) as file: | ||
| filecontents = file.read() | ||
| if len(filecontents.strip()) != 0: | ||
| logger.info("[Settings] Reading Global Settings File", path=path) | ||
| settings_data = toml.loads(filecontents) | ||
| settings = GlobalSettings(**settings_data) | ||
| return settings | ||
|
|
||
| return GlobalSettings() | ||
|
|
||
| def save(self, path: Path = DEFAULT_GLOBAL_SETTINGS_PATH) -> None: | ||
| if not path.parent.exists(): | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| with open(path, "w") as f: | ||
| toml.dump(dict(self), f, encoder=TomlEnumEncoder()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.