preferences window navigation pane

This commit is contained in:
tsi-billypom 2024-09-26 16:20:12 -04:00
parent 52bce599e3
commit d10d4a1e3b
4 changed files with 80 additions and 30 deletions

View File

@ -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()

View File

@ -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 = []

View File

@ -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()

View File

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