Added settings and implemented restoring of window size.
This commit is contained in:
parent
99934e73b7
commit
6aae95c865
6 changed files with 36 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
wobuzz/settings.json
|
||||
__pycache__
|
||||
.idea
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
11
wobuzz/settings.py
Normal file
11
wobuzz/settings.py
Normal 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"
|
||||
|
|
@ -25,3 +25,4 @@ class MainWindow(QMainWindow):
|
|||
)
|
||||
self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, self.library_dock)
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue