Skip to content

Commit e3d90a7

Browse files
committed
fix: many minor fixes
1 parent 9c9db62 commit e3d90a7

File tree

6 files changed

+23
-19
lines changed

6 files changed

+23
-19
lines changed

tagstudio/src/core/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def evaluate_path(self, open_path: str | None) -> LibraryStatus:
2121
if not library_path.exists():
2222
logger.error("Path does not exist.", open_path=open_path)
2323
return LibraryStatus(success=False, message="Path does not exist.")
24-
elif self.settings.open_last_loaded_on_startup and self.cache.last_lib:
24+
elif self.settings.open_last_loaded_on_startup and self.cache.last_library:
2525
library_path = Path(str(self.cache.last_library))
2626
if not (library_path / TS_FOLDER_NAME).exists():
2727
logger.error(

tagstudio/src/core/settings/tssettings.py

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

33
import toml
44
from pydantic import BaseModel, Field
5+
from typing import Any
56

67

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

2223
@staticmethod
2324
def read_settings(path: Path | str, **kwargs) -> "TSSettings":
24-
settings_data: dict[str, any] = dict()
25-
if path.exists():
25+
path_value = Path(path)
26+
settings_data: dict[str, Any] = dict()
27+
if path_value.exists():
2628
with open(path, "rb") as file:
2729
filecontents = file.read()
2830
if len(filecontents.strip()) != 0:
@@ -32,8 +34,8 @@ def read_settings(path: Path | str, **kwargs) -> "TSSettings":
3234
settings = TSSettings(**settings_data)
3335
return settings
3436

35-
def to_dict(self) -> dict[str, any]:
36-
d = dict[str, any]()
37+
def to_dict(self) -> dict[str, Any]:
38+
d = dict[str, Any]()
3739
for prop_name, prop_value in self:
3840
d[prop_name] = prop_value
3941

tagstudio/src/core/tscacheddata.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
logger = structlog.get_logger(__name__)
1010

11-
cache_dir = Path(user_cache_dir()) / ".TagStudio"
11+
cache_dir = Path(user_cache_dir()) / "TagStudio"
1212
cache_location = cache_dir / "cache.toml"
1313

1414

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

2021
path: str = Field()
2122

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

4243
def save(self):
4344
with open(self.path, "w") as f:
44-
toml.dump(dict(self), f)
45+
file_data = dict(self)
46+
file_data.pop("path")
47+
toml.dump(file_data, f)

tagstudio/src/qt/modals/settings_modal.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
QLabel,
88
QVBoxLayout,
99
)
10-
from src.core.settings import tssettings
10+
from src.core.settings import TSSettings
1111
from src.qt.widgets.panel import PanelWidget
12+
from typing import Any
1213

1314

1415
class SettingsModal(PanelWidget):
15-
def __init__(self, settings: tssettings):
16+
def __init__(self, settings: TSSettings):
1617
super().__init__()
17-
self.tempSettings = copy.deepcopy(settings)
18+
self.tempSettings: TSSettings = copy.deepcopy(settings)
1819

1920
self.main = QVBoxLayout(self)
2021

@@ -84,8 +85,8 @@ def __init__(self, settings: tssettings):
8485
self.main.addLayout(self.show_library_list_Row)
8586
self.main.addLayout(self.show_filenames_Row)
8687

87-
def set_property(self, prop_name: str, value: any) -> None:
88+
def set_property(self, prop_name: str, value: Any) -> None:
8889
setattr(self.tempSettings, prop_name, value)
8990

90-
def get_content(self) -> tssettings:
91+
def get_content(self):
9192
return self.tempSettings

tagstudio/src/qt/ts_qt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def __init__(self, backend, args):
175175
logger.info("Using Config File", path=path)
176176
self.settings = TSSettings.read_settings(path)
177177
else:
178-
path = ""
178+
path = Path()
179179
if sys.platform == "win32":
180180
path = Path.home() / "AppData" / "Roaming" / "TagStudio" / "config.toml"
181181
else: # "linux" and "darwin" should use the same config directory
@@ -628,7 +628,7 @@ def close_library(self, is_shutdown: bool = False):
628628
self.main_window.statusbar.showMessage(Translations["status.library_closing"])
629629
start_time = time.time()
630630

631-
self.cache.last_library = self.lib.library_dir
631+
self.cache.last_library = str(self.lib.library_dir)
632632
self.settings.save()
633633

634634
self.lib.close()
@@ -1238,13 +1238,13 @@ def filter_items(self, filter: FilterState | None = None) -> None:
12381238
)
12391239

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

12431243
def update_libs_list(self, path: Path | str):
12441244
item_limit: int = 5
12451245
path = Path(path)
12461246

1247-
all_libs = {str(time.time()): str(path)}
1247+
all_libs = {datetime.datetime.fromtimestamp(time.time()).isoformat(): str(path)}
12481248

12491249
for access_time in self.cache.library_history:
12501250
lib = self.cache.library_history[access_time]

tagstudio/src/qt/widgets/preview_panel.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ def __init__(self, library: Library, driver: "QtDriver"):
252252
# set initial visibility based on settings
253253
if not self.driver.settings.show_library_list:
254254
self.libs_flow_container.hide()
255-
else:
256-
self.libs_flow_container.show()
257255

258256
splitter = QSplitter()
259257
splitter.setOrientation(Qt.Orientation.Vertical)

0 commit comments

Comments
 (0)