diff --git a/.gitignore b/.gitignore index 341e31e..099bf9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +wobuzz/settings.json __pycache__ .idea \ No newline at end of file diff --git a/wobuzz/gui.py b/wobuzz/gui.py index 4d44f21..f5068e7 100644 --- a/wobuzz/gui.py +++ b/wobuzz/gui.py @@ -9,10 +9,16 @@ class GUI: self.window = MainWindow() + if self.app.settings.window_maximized: + self.window.showMaximized() + + elif not self.app.settings.window_size is None: + self.window.resize(*self.app.settings.window_size) + self.connect() self.window.show() def connect(self): - pass + self.window.closeEvent = self.app.utils.on_close diff --git a/wobuzz/main.py b/wobuzz/main.py index 42db9ed..c164404 100644 --- a/wobuzz/main.py +++ b/wobuzz/main.py @@ -2,6 +2,8 @@ import sys from PyQt6.QtWidgets import QApplication +from wobbl_tools.data_file import load_dataclass_json +from settings import Settings from utils import Utils from player.player import Player from gui import GUI @@ -13,6 +15,7 @@ class Wobuzz: self.qt_app = QApplication([]) self.utils = Utils(self) + self.settings = load_dataclass_json(Settings, self.utils.settings_location) self.player = Player(self) self.gui = GUI(self) self.gui_communication = GUICommunication(self) diff --git a/wobuzz/settings.py b/wobuzz/settings.py new file mode 100644 index 0000000..ed66a13 --- /dev/null +++ b/wobuzz/settings.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 + +from dataclasses import dataclass + + +@dataclass +class Settings: + window_size: tuple[int, int]=None + window_maximized: bool=False + library_path: str="~/.wobuzz" + diff --git a/wobuzz/ui/main_window.py b/wobuzz/ui/main_window.py index 34058f9..7961d31 100644 --- a/wobuzz/ui/main_window.py +++ b/wobuzz/ui/main_window.py @@ -25,3 +25,4 @@ class MainWindow(QMainWindow): ) self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, self.library_dock) + diff --git a/wobuzz/utils.py b/wobuzz/utils.py index d44672f..297b053 100644 --- a/wobuzz/utils.py +++ b/wobuzz/utils.py @@ -1,7 +1,14 @@ #!/usr/bin/python3 +import os +from pathlib import Path + class Utils: + home_path = str(Path.home()) + wobuzz_location = os.path.dirname(os.path.abspath(__file__)) + settings_location = f"{wobuzz_location}/settings.json" + def __init__(self, app): self.app = app @@ -22,4 +29,10 @@ class Utils: return output + def on_close(self, event): + self.app.settings.window_size = (self.app.gui.window.width(), self.app.gui.window.height()) + self.app.settings.window_maximized = self.app.gui.window.isMaximized() + + self.app.settings.save(self.settings_location) +