OOPing it more: Removed gui_communication/settings.py

This commit is contained in:
The Wobbler 2025-01-25 15:14:20 +01:00
parent 3685f25882
commit d2c74438cb
5 changed files with 24 additions and 35 deletions

View file

@ -10,6 +10,7 @@ class GUI:
self.app = app self.app = app
self.window = MainWindow() self.window = MainWindow()
self.settings = self.window.settings
self.window.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.app.library.main_library_dock) self.window.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.app.library.main_library_dock)
@ -28,6 +29,11 @@ class GUI:
self.window.show() self.window.show()
self.settings.update_all()
def connect(self): def connect(self):
self.window.closeEvent = self.app.utils.on_close self.window.closeEvent = self.app.utils.on_close
def on_settings_change(self, key, value):
self.settings.update_settings(key, value)

View file

@ -2,7 +2,6 @@
from .menu_bar import MenuBar from .menu_bar import MenuBar
from .track_control import TrackControl from .track_control import TrackControl
from .settings import Settings
class GUICommunication: class GUICommunication:
@ -15,9 +14,6 @@ class GUICommunication:
self.menu_bar = MenuBar(self.app) self.menu_bar = MenuBar(self.app)
self.track_control = TrackControl(self.app) self.track_control = TrackControl(self.app)
self.settings = Settings(self.app)
self.settings.update_all()
def on_track_change(self, previous_track=None, track=None): def on_track_change(self, previous_track=None, track=None):
self.track_control.on_track_change(previous_track, track) self.track_control.on_track_change(previous_track, track)
@ -26,6 +22,3 @@ class GUICommunication:
def on_playstate_update(self): def on_playstate_update(self):
self.track_control.on_playstate_update() self.track_control.on_playstate_update()
def on_settings_change(self, key, value):
self.settings.update_settings(key, value)

View file

@ -1,26 +0,0 @@
#!/usr/bin/python3
class Settings:
def __init__(self, app):
self.app = app
self.settings = self.app.gui.window.settings
self.connect()
def connect(self):
self.settings.visibilityChanged.connect(self.update_all)
self.settings.save_button.pressed.connect(self.write_settings)
def update_all(self, _=True): # ignore visible parameter passed by visibilityChanged event
self.settings.file_settings.library_path_input.setText(self.app.settings.library_path)
def update_settings(self, key, value):
match key:
case "library_path":
self.settings.file_settings.library_path_input.setText(value)
def write_settings(self):
self.app.settings.library_path = self.settings.file_settings.library_path_input.text()

View file

@ -26,7 +26,7 @@ class Wobuzz:
self.gui_communication = GUICommunication(self) self.gui_communication = GUICommunication(self)
def on_settings_change(self, key, value): def on_settings_change(self, key, value):
self.gui_communication.on_settings_change(key, value) self.gui.on_settings_change(key, value)
return True return True

View file

@ -6,9 +6,11 @@ from .file import FileSettings
class Settings(QDockWidget): class Settings(QDockWidget):
def __init__(self, parent=None): def __init__(self, app, parent=None):
super().__init__(parent) super().__init__(parent)
self.app = app
self.setAllowedAreas( self.setAllowedAreas(
Qt.DockWidgetArea.LeftDockWidgetArea | Qt.DockWidgetArea.LeftDockWidgetArea |
Qt.DockWidgetArea.RightDockWidgetArea | Qt.DockWidgetArea.RightDockWidgetArea |
@ -32,3 +34,17 @@ class Settings(QDockWidget):
self.setWidget(self.content) self.setWidget(self.content)
self.visibilityChanged.connect(self.update_all)
self.save_button.pressed.connect(self.write_settings)
def update_all(self, _=True): # ignore visible parameter passed by visibilityChanged event
self.file_settings.library_path_input.setText(self.app.settings.library_path)
def update_settings(self, key, value):
match key:
case "library_path":
self.file_settings.library_path_input.setText(value)
def write_settings(self):
self.app.settings.library_path = self.file_settings.library_path_input.text()