Skip to content

Commit

Permalink
fix: many minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
python357-1 committed Jan 1, 2025
1 parent 9c9db62 commit e3d90a7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tagstudio/src/core/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def evaluate_path(self, open_path: str | None) -> LibraryStatus:
if not library_path.exists():
logger.error("Path does not exist.", open_path=open_path)
return LibraryStatus(success=False, message="Path does not exist.")
elif self.settings.open_last_loaded_on_startup and self.cache.last_lib:
elif self.settings.open_last_loaded_on_startup and self.cache.last_library:
library_path = Path(str(self.cache.last_library))
if not (library_path / TS_FOLDER_NAME).exists():
logger.error(
Expand Down
10 changes: 6 additions & 4 deletions tagstudio/src/core/settings/tssettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import toml
from pydantic import BaseModel, Field
from typing import Any


# NOTE: pydantic also has a BaseSettings class (from pydantic-settings) that allows any settings
Expand All @@ -21,8 +22,9 @@ class TSSettings(BaseModel):

@staticmethod
def read_settings(path: Path | str, **kwargs) -> "TSSettings":
settings_data: dict[str, any] = dict()
if path.exists():
path_value = Path(path)
settings_data: dict[str, Any] = dict()
if path_value.exists():
with open(path, "rb") as file:
filecontents = file.read()
if len(filecontents.strip()) != 0:
Expand All @@ -32,8 +34,8 @@ def read_settings(path: Path | str, **kwargs) -> "TSSettings":
settings = TSSettings(**settings_data)
return settings

def to_dict(self) -> dict[str, any]:
d = dict[str, any]()
def to_dict(self) -> dict[str, Any]:
d = dict[str, Any]()
for prop_name, prop_value in self:
d[prop_name] = prop_value

Expand Down
9 changes: 6 additions & 3 deletions tagstudio/src/core/tscacheddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

logger = structlog.get_logger(__name__)

cache_dir = Path(user_cache_dir()) / ".TagStudio"
cache_dir = Path(user_cache_dir()) / "TagStudio"
cache_location = cache_dir / "cache.toml"


class TSCachedData(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
last_library: str | None = Field(default=None)
library_history: dict[datetime, str] = Field(default_factory=dict[datetime, str])
# a dict of ISO formatted date strings -> paths
library_history: dict[str, str] = Field(default_factory=dict[datetime, str])

path: str = Field()

Expand All @@ -41,4 +42,6 @@ def open(path: str | None = None) -> "TSCachedData":

def save(self):
with open(self.path, "w") as f:
toml.dump(dict(self), f)
file_data = dict(self)
file_data.pop("path")
toml.dump(file_data, f)
11 changes: 6 additions & 5 deletions tagstudio/src/qt/modals/settings_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
QLabel,
QVBoxLayout,
)
from src.core.settings import tssettings
from src.core.settings import TSSettings
from src.qt.widgets.panel import PanelWidget
from typing import Any


class SettingsModal(PanelWidget):
def __init__(self, settings: tssettings):
def __init__(self, settings: TSSettings):
super().__init__()
self.tempSettings = copy.deepcopy(settings)
self.tempSettings: TSSettings = copy.deepcopy(settings)

self.main = QVBoxLayout(self)

Expand Down Expand Up @@ -84,8 +85,8 @@ def __init__(self, settings: tssettings):
self.main.addLayout(self.show_library_list_Row)
self.main.addLayout(self.show_filenames_Row)

def set_property(self, prop_name: str, value: any) -> None:
def set_property(self, prop_name: str, value: Any) -> None:
setattr(self.tempSettings, prop_name, value)

def get_content(self) -> tssettings:
def get_content(self):
return self.tempSettings
8 changes: 4 additions & 4 deletions tagstudio/src/qt/ts_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self, backend, args):
logger.info("Using Config File", path=path)
self.settings = TSSettings.read_settings(path)
else:
path = ""
path = Path()
if sys.platform == "win32":
path = Path.home() / "AppData" / "Roaming" / "TagStudio" / "config.toml"
else: # "linux" and "darwin" should use the same config directory
Expand Down Expand Up @@ -628,7 +628,7 @@ def close_library(self, is_shutdown: bool = False):
self.main_window.statusbar.showMessage(Translations["status.library_closing"])
start_time = time.time()

self.cache.last_library = self.lib.library_dir
self.cache.last_library = str(self.lib.library_dir)
self.settings.save()

self.lib.close()
Expand Down Expand Up @@ -1238,13 +1238,13 @@ def filter_items(self, filter: FilterState | None = None) -> None:
)

def remove_recent_library(self, item_key: str) -> None:
self.cache.library_history.pop(datetime.datetime.strptime(item_key))
self.cache.library_history.pop(item_key)

def update_libs_list(self, path: Path | str):
item_limit: int = 5
path = Path(path)

all_libs = {str(time.time()): str(path)}
all_libs = {datetime.datetime.fromtimestamp(time.time()).isoformat(): str(path)}

for access_time in self.cache.library_history:
lib = self.cache.library_history[access_time]
Expand Down
2 changes: 0 additions & 2 deletions tagstudio/src/qt/widgets/preview_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ def __init__(self, library: Library, driver: "QtDriver"):
# set initial visibility based on settings
if not self.driver.settings.show_library_list:
self.libs_flow_container.hide()
else:
self.libs_flow_container.show()

splitter = QSplitter()
splitter.setOrientation(Qt.Orientation.Vertical)
Expand Down

0 comments on commit e3d90a7

Please sign in to comment.