From d10d4a1e3b430eed4151e620b4fc01cd9ce4a705 Mon Sep 17 00:00:00 2001 From: tsi-billypom Date: Thu, 26 Sep 2024 16:20:12 -0400 Subject: [PATCH] preferences window navigation pane --- components/LyricsWindow.py | 2 +- components/MusicTable.py | 1 - components/PreferencesWindow.py | 106 +++++++++++++++++++++++--------- main.py | 1 + 4 files changed, 80 insertions(+), 30 deletions(-) diff --git a/components/LyricsWindow.py b/components/LyricsWindow.py index 7784953..40362c2 100644 --- a/components/LyricsWindow.py +++ b/components/LyricsWindow.py @@ -37,7 +37,7 @@ class LyricsWindow(QDialog): value=self.input_field.toPlainText(), ) if success: - print("success! yay") + print("lyrical success! yay") else: error_dialog = ErrorDialog("Could not save lyrics :( sad") error_dialog.exec() diff --git a/components/MusicTable.py b/components/MusicTable.py index a3173db..bf8287b 100644 --- a/components/MusicTable.py +++ b/components/MusicTable.py @@ -575,7 +575,6 @@ class MusicTable(QTableView): return # Populate the model for row_data in data: - print(f"row_data: {row_data}") id, *rest_of_data = row_data # handle different datatypes items = [] diff --git a/components/PreferencesWindow.py b/components/PreferencesWindow.py index 2fca613..aed4a25 100644 --- a/components/PreferencesWindow.py +++ b/components/PreferencesWindow.py @@ -1,10 +1,13 @@ +from PyQt5.QtCore import Qt from PyQt5.QtWidgets import ( QDialog, - QFrame, QVBoxLayout, QLabel, QLineEdit, QPushButton, + QHBoxLayout, + QListWidget, + QWidget, QDial, ) from PyQt5.QtGui import QFont @@ -13,49 +16,96 @@ from PyQt5.QtGui import QFont class PreferencesWindow(QDialog): def __init__(self, config): super(PreferencesWindow, self).__init__() + # Config self.setWindowTitle("Preferences") - self.setMinimumSize(400, 800) + self.setMinimumSize(800, 800) self.config = config - layout = QVBoxLayout() + self.current_category = "" - label = QLabel("Preferences") - label.setFont(QFont("Sans", weight=QFont.Bold)) - layout.addWidget(label) + # Widgets + self.content_area = QWidget() + nav_pane = QListWidget() - # Labels & input fields - self.input_fields = {} + # Layouts + central_widget = QWidget() + main_layout = QHBoxLayout() + self.content_layout = QVBoxLayout() + self.content_layout.setAlignment(Qt.AlignmentFlag.AlignTop) + + central_widget.setLayout(main_layout) + self.content_area.setLayout(self.content_layout) + + # Navigation pane for category in self.config.sections(): - separator = QFrame() - separator.setFrameShape(QFrame.HLine) - layout.addWidget(separator) - category_label = QLabel(f"{category}") - category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold category - category_label.setStyleSheet( - "text-transform:uppercase;" - ) # uppercase category - layout.addWidget(category_label) - for key in self.config[category]: - label = QLabel(key) - input_field = QLineEdit(self.config[category][key]) - layout.addWidget(label) - layout.addWidget(input_field) - self.input_fields[key] = input_field + nav_pane.addItem(category) + nav_pane.itemClicked.connect(self.on_nav_item_clicked) + nav_pane.setCurrentRow(0) + first_category = self.config.sections()[0] + self.on_nav_item_clicked(first_category) + + # # Labels & input fields + self.input_fields = {} + # for category in self.config.sections(): + # separator = QFrame() + # separator.setFrameShape(QFrame.HLine) + # self.content_layout.addWidget(separator) + # category_label = QLabel(f"{category}") + # category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold + # category_label.setStyleSheet("text-transform:uppercase;") # uppercase + # self.content_layout.addWidget(category_label) + # for key in self.config[category]: + # label = QLabel(key) + # input_field = QLineEdit(self.config[category][key]) + # self.content_layout.addWidget(label) + # self.content_layout.addWidget(input_field) + # self.input_fields[key] = input_field + + # Add widgets to the layout + main_layout.addWidget(nav_pane) + main_layout.addWidget(self.content_area) + + # # Set the layout + self.setLayout(main_layout) + + def on_nav_item_clicked(self, item): + self.clear_layout(self.content_layout) + self.input_fields = {} + if isinstance(item, str): + self.current_category = item + else: + self.current_category = item.text() + category_label = QLabel(f"{self.current_category}") + category_label.setFont(QFont("Sans", weight=QFont.Bold)) + category_label.setStyleSheet("text-transform:uppercase;") + self.content_layout.addWidget(category_label) + for key in self.config[self.current_category]: + label = QLabel(key) + input_field = QLineEdit(self.config[self.current_category][key]) + self.content_layout.addWidget(label) + self.content_layout.addWidget(input_field) + self.input_fields[key] = input_field # Save button save_button = QPushButton("Save") save_button.clicked.connect(self.save_preferences) - layout.addWidget(save_button) - self.setLayout(layout) + self.content_layout.addWidget(save_button) + + def clear_layout(self, layout): + while layout.count(): + child = layout.takeAt(0) + if child.widget(): + child.widget().deleteLater() def save_preferences(self): # Upcate the config fields for key in self.input_fields: for category in self.config.sections(): if key in self.config[category]: - self.config[category][key] = self.input_fields[key].text() + self.config[self.current_category][key] = self.input_fields[ + key + ].text() # Write the config file with open("config.ini", "w") as configfile: self.config.write(configfile) - - self.close() + # self.close() diff --git a/main.py b/main.py index fbaf951..3e80e38 100644 --- a/main.py +++ b/main.py @@ -539,6 +539,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): """Opens the preferences window""" preferences_window = PreferencesWindow(self.config) preferences_window.exec_() # Display the preferences window modally + self.reload_config() # Quick Actions