Added settings and implemented restoring of window size.

This commit is contained in:
The Wobbler 2024-12-23 17:12:21 +01:00
parent 99934e73b7
commit 6aae95c865
6 changed files with 36 additions and 1 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
wobuzz/settings.json
__pycache__ __pycache__
.idea .idea

View file

@ -9,10 +9,16 @@ class GUI:
self.window = MainWindow() 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.connect()
self.window.show() self.window.show()
def connect(self): def connect(self):
pass self.window.closeEvent = self.app.utils.on_close

View file

@ -2,6 +2,8 @@
import sys import sys
from PyQt6.QtWidgets import QApplication from PyQt6.QtWidgets import QApplication
from wobbl_tools.data_file import load_dataclass_json
from settings import Settings
from utils import Utils from utils import Utils
from player.player import Player from player.player import Player
from gui import GUI from gui import GUI
@ -13,6 +15,7 @@ class Wobuzz:
self.qt_app = QApplication([]) self.qt_app = QApplication([])
self.utils = Utils(self) self.utils = Utils(self)
self.settings = load_dataclass_json(Settings, self.utils.settings_location)
self.player = Player(self) self.player = Player(self)
self.gui = GUI(self) self.gui = GUI(self)
self.gui_communication = GUICommunication(self) self.gui_communication = GUICommunication(self)

11
wobuzz/settings.py Normal file
View file

@ -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"

View file

@ -25,3 +25,4 @@ class MainWindow(QMainWindow):
) )
self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, self.library_dock) self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, self.library_dock)

View file

@ -1,7 +1,14 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os
from pathlib import Path
class Utils: 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): def __init__(self, app):
self.app = app self.app = app
@ -22,4 +29,10 @@ class Utils:
return output 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)