From 6498f43d5fe12649d0dafbe187ff6b994b2750e4 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Tue, 24 Dec 2024 12:13:24 +0100 Subject: [PATCH] Added "library_path" setting, added a gui for the settings, changed the window layout and did a bunch of other things. --- wobuzz/gui_communication/gui_communication.py | 12 +++++--- wobuzz/gui_communication/menu_bar.py | 17 +++++++++++ wobuzz/gui_communication/settings.py | 25 +++++++++++++++++ wobuzz/gui_communication/track_control.py | 2 +- wobuzz/main.py | 10 ++++++- wobuzz/ui/library_dock.py | 5 ++++ wobuzz/ui/main_container.py | 21 -------------- wobuzz/ui/main_window.py | 28 ++++++++++++------- wobuzz/ui/settings/file.py | 15 ++++++++++ wobuzz/ui/settings/settings.py | 26 +++++++++++++++++ 10 files changed, 124 insertions(+), 37 deletions(-) create mode 100644 wobuzz/gui_communication/menu_bar.py create mode 100644 wobuzz/gui_communication/settings.py delete mode 100644 wobuzz/ui/main_container.py create mode 100644 wobuzz/ui/settings/file.py create mode 100644 wobuzz/ui/settings/settings.py diff --git a/wobuzz/gui_communication/gui_communication.py b/wobuzz/gui_communication/gui_communication.py index 22abad5..37f767f 100644 --- a/wobuzz/gui_communication/gui_communication.py +++ b/wobuzz/gui_communication/gui_communication.py @@ -1,6 +1,8 @@ #!/usr/bin/python3 +from .menu_bar import MenuBar from .track_control import TrackControl +from .settings import Settings class GUICommunication: @@ -11,13 +13,15 @@ class GUICommunication: def __init__(self, app): self.app = app + self.menu_bar = MenuBar(self.app) self.track_control = TrackControl(self.app) + self.settings = Settings(self.app) - self.connect() - - def connect(self): - pass + self.settings.update_all() def on_track_start(self): self.track_control.on_track_start() + def on_settings_change(self, key, value): + self.settings.update_settings(key, value) + diff --git a/wobuzz/gui_communication/menu_bar.py b/wobuzz/gui_communication/menu_bar.py new file mode 100644 index 0000000..5422a49 --- /dev/null +++ b/wobuzz/gui_communication/menu_bar.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + + +class MenuBar: + def __init__(self, app): + self.app = app + self.window = self.app.gui.window + self.settings_action = self.window.settings_action + + self.connect() + + def connect(self): + self.settings_action.triggered.connect(self.show_settings) + + def show_settings(self): + self.window.settings.show() + diff --git a/wobuzz/gui_communication/settings.py b/wobuzz/gui_communication/settings.py new file mode 100644 index 0000000..6c46d71 --- /dev/null +++ b/wobuzz/gui_communication/settings.py @@ -0,0 +1,25 @@ +#!/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.file_settings.library_path_input.returnPressed.connect(self.write_settings) + + def update_all(self): + 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() + diff --git a/wobuzz/gui_communication/track_control.py b/wobuzz/gui_communication/track_control.py index ce42a0d..b5d5b57 100644 --- a/wobuzz/gui_communication/track_control.py +++ b/wobuzz/gui_communication/track_control.py @@ -13,7 +13,7 @@ class TrackControl: def __init__(self, app): self.app = app - self.track_control = self.app.gui.window.main_container.track_control + self.track_control = self.app.gui.window.track_control self.track_progress_slider = self.track_control.track_progress_slider self.progress_update_timer = QTimer() diff --git a/wobuzz/main.py b/wobuzz/main.py index c164404..829f1a6 100644 --- a/wobuzz/main.py +++ b/wobuzz/main.py @@ -15,7 +15,10 @@ class Wobuzz: self.qt_app = QApplication([]) self.utils = Utils(self) - self.settings = load_dataclass_json(Settings, self.utils.settings_location) + + self.settings = load_dataclass_json(Settings, self.utils.settings_location, self, True, True) + self.settings.set_attribute_change_event(self.on_settings_change) + self.player = Player(self) self.gui = GUI(self) self.gui_communication = GUICommunication(self) @@ -25,6 +28,11 @@ class Wobuzz: if track_paths: self.player.load_tracks_from_paths(track_paths) + def on_settings_change(self, key, value): + self.gui_communication.on_settings_change(key, value) + + return True + if __name__ == "__main__": wobuzz = Wobuzz() diff --git a/wobuzz/ui/library_dock.py b/wobuzz/ui/library_dock.py index 2bb768d..ca69db1 100644 --- a/wobuzz/ui/library_dock.py +++ b/wobuzz/ui/library_dock.py @@ -15,6 +15,11 @@ class LibraryDock(QDockWidget): Qt.DockWidgetArea.BottomDockWidgetArea ) + self.setFeatures( + QDockWidget.DockWidgetFeature.DockWidgetMovable | + QDockWidget.DockWidgetFeature.DockWidgetFloatable + ) + self.library = Library(self) self.setWidget(self.library) diff --git a/wobuzz/ui/main_container.py b/wobuzz/ui/main_container.py deleted file mode 100644 index 72b51b2..0000000 --- a/wobuzz/ui/main_container.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python3 - -from PyQt6.QtWidgets import QWidget, QGridLayout, QSizePolicy -from .track_control import TrackControl -from .lines import HLine - - -class MainContainer(QWidget): - def __init__(self, parent=None): - super().__init__(parent) - - self.layout = QGridLayout() - self.setLayout(self.layout) - - self.track_control = TrackControl(self) - self.layout.addWidget(self.track_control) - - self.layout.addWidget(HLine(self)) # track_control separator line - - self.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed) - diff --git a/wobuzz/ui/main_window.py b/wobuzz/ui/main_window.py index 7961d31..59b47e3 100644 --- a/wobuzz/ui/main_window.py +++ b/wobuzz/ui/main_window.py @@ -1,9 +1,10 @@ #!/usr/bin/python3 from PyQt6.QtCore import Qt -from PyQt6.QtWidgets import QMainWindow, QMenu, QDockWidget -from .main_container import MainContainer +from PyQt6.QtWidgets import QMainWindow, QMenu +from .track_control import TrackControl from .library_dock import LibraryDock +from .settings.settings import Settings class MainWindow(QMainWindow): @@ -13,16 +14,23 @@ class MainWindow(QMainWindow): self.setWindowTitle("WoBuzz") self.menu_bar = self.menuBar() - self.menu_bar.addMenu(QMenu("&File", self)) - self.main_container = MainContainer(self) - self.setCentralWidget(self.main_container) + self.file_menu = QMenu("&File", self.menu_bar) + self.menu_bar.addMenu(self.file_menu) + + self.edit_menu = QMenu("&Edit", self.menu_bar) + self.menu_bar.addMenu(self.edit_menu) + + self.settings_action = self.edit_menu.addAction("Settings") + + self.track_control = TrackControl() + self.addToolBar(self.track_control) + + self.settings = Settings() + self.settings.hide() + self.addDockWidget(Qt.DockWidgetArea.LeftDockWidgetArea, self.settings) self.library_dock = LibraryDock() - self.library_dock.setFeatures( - QDockWidget.DockWidgetFeature.DockWidgetMovable | - QDockWidget.DockWidgetFeature.DockWidgetFloatable - ) - self.addDockWidget(Qt.DockWidgetArea.BottomDockWidgetArea, self.library_dock) + self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.library_dock) diff --git a/wobuzz/ui/settings/file.py b/wobuzz/ui/settings/file.py new file mode 100644 index 0000000..2017657 --- /dev/null +++ b/wobuzz/ui/settings/file.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 + +from PyQt6.QtWidgets import QWidget, QLineEdit, QFormLayout + + +class FileSettings(QWidget): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.layout = QFormLayout(self) + self.setLayout(self.layout) + + self.library_path_input = QLineEdit(self) + self.layout.addRow("Library Path:", self.library_path_input) + diff --git a/wobuzz/ui/settings/settings.py b/wobuzz/ui/settings/settings.py new file mode 100644 index 0000000..9153f20 --- /dev/null +++ b/wobuzz/ui/settings/settings.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +from PyQt6.QtCore import Qt +from PyQt6.QtWidgets import QDockWidget, QTabWidget +from .file import FileSettings + + +class Settings(QDockWidget): + def __init__(self, parent=None): + super().__init__(parent) + + self.setAllowedAreas( + Qt.DockWidgetArea.LeftDockWidgetArea | + Qt.DockWidgetArea.RightDockWidgetArea | + Qt.DockWidgetArea.BottomDockWidgetArea + ) + + self.setWindowTitle("Settings") + + self.tabs = QTabWidget() + + self.file_settings = FileSettings() + self.tabs.addTab(self.file_settings, "Files") + + self.setWidget(self.tabs) +