-
-
Notifications
You must be signed in to change notification settings - Fork 400
feat: begin adding settings menu #647
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.8 |
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 |
---|---|---|
|
@@ -24,3 +24,5 @@ | |
TAG_META = 2 | ||
RESERVED_TAG_START = 0 | ||
RESERVED_TAG_END = 999 | ||
|
||
DEFAULT_LIB_VERSION = 3 |
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,4 @@ | ||
from .libsettings import LibSettings | ||
from .tssettings import TSSettings | ||
|
||
__all__ = ["TSSettings", "LibSettings"] |
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,42 @@ | ||
from pathlib import Path | ||
|
||
import structlog | ||
import toml | ||
from pydantic import BaseModel, Field | ||
|
||
from ..constants import DEFAULT_LIB_VERSION | ||
|
||
logger = structlog.get_logger(__name__) | ||
|
||
|
||
class LibSettings(BaseModel): | ||
is_exclude_list: bool = Field(default=True) | ||
extension_list: list[str] = Field(default=[".json", ".xmp", ".aae"]) | ||
page_size: int = Field(default=500) | ||
db_version: int = Field(default=DEFAULT_LIB_VERSION) | ||
filename: str = Field(default="") | ||
|
||
@staticmethod | ||
def open(path_value: Path | str) -> "LibSettings": | ||
path: Path = Path(path_value) if not isinstance(path_value, Path) else path_value | ||
|
||
if path.exists(): | ||
with open(path) as settings_file: | ||
filecontents = settings_file.read() | ||
if len(filecontents.strip()) != 0: | ||
settings_data = toml.loads(filecontents) | ||
settings_data["filename"] = str(path) | ||
return LibSettings(**settings_data) | ||
|
||
# either settings file did not exist or was empty - either way, use default settings | ||
settings = LibSettings(filename=str(path)) | ||
return settings | ||
|
||
def save(self): | ||
if self.filename == "": # assume settings were opened for in-memory library | ||
return | ||
if not (parent_path := Path(self.filename).parent).exists(): | ||
parent_path.mkdir() | ||
|
||
with open(self.filename, "w") as settings_file: | ||
toml.dump(dict(self), settings_file) |
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,44 @@ | ||
from pathlib import Path | ||
|
||
import toml | ||
from pydantic import BaseModel, Field | ||
|
||
|
||
# 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 TSSettings(BaseModel): | ||
dark_mode: bool = Field(default=False) | ||
language: str = Field(default="en") | ||
|
||
# settings from the old SettingItem enum | ||
open_last_loaded_on_startup: bool = Field(default=False) | ||
show_library_list: bool = Field(default=True) | ||
autoplay: bool = Field(default=False) | ||
show_filenames_in_grid: bool = Field(default=False) | ||
|
||
filename: str = Field() | ||
|
||
@staticmethod | ||
def read_settings(path: Path | str) -> "TSSettings": | ||
path_value = Path(path) | ||
if path_value.exists(): | ||
with open(path) as file: | ||
filecontents = file.read() | ||
if len(filecontents.strip()) != 0: | ||
settings_data = toml.loads(filecontents) | ||
return TSSettings(**settings_data) | ||
|
||
return TSSettings(filename=str(path)) | ||
|
||
def save(self, path: Path | str | None = None) -> None: | ||
path_value: Path = Path(path) if isinstance(path, str) else Path(self.filename) | ||
if path_value == "": | ||
pass | ||
# settings were probably opened for an in-memory library - save to preferences table | ||
|
||
if not path_value.parent.exists(): | ||
path_value.parent.mkdir(parents=True, exist_ok=True) | ||
|
||
with open(path_value, "w") as f: | ||
toml.dump(dict(self), f) |
Oops, something went wrong.
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.