From 27238aa0ca2fae4c7e3430e5791c731ea8b57d5f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 3 Aug 2021 00:04:26 -0700 Subject: [PATCH] Enhance the configuration dialog --- src/ukatali/configuredialog.py | 61 ++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/ukatali/configuredialog.py b/src/ukatali/configuredialog.py index c068275..eaae727 100644 --- a/src/ukatali/configuredialog.py +++ b/src/ukatali/configuredialog.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from PyQt5 import QtCore, QtWidgets -from chordpro.renderers.html import OPTION_GROUPS, get_options +from chordpro.renderers.html import get_options, get_option_groups class ConfigureDialog(QtWidgets.QDialog): @@ -14,15 +14,37 @@ class ConfigureDialog(QtWidgets.QDialog): def setup_ui(self): self.setObjectName('ConfigureDialog') - self.resize(800, 600) + self.resize(600, 400) self.configure_layout = QtWidgets.QVBoxLayout(self) self.configure_layout.setObjectName("configure_layout") - self.render_options_combobox = QtWidgets.QComboBox(self) + self.category_layout = QtWidgets.QHBoxLayout() + self.category_layout.setObjectName('category_layout') + self.configure_layout.addLayout(self.category_layout) + self.category_list_widget = QtWidgets.QListWidget(self) + self.category_list_widget.setFixedWidth(100) + self.category_list_widget.addItems(['', '', '']) + self.category_list_widget.setObjectName('category_list_widget') + self.category_layout.addWidget(self.category_list_widget) + self.category_stack = QtWidgets.QStackedWidget(self) + self.category_stack.setObjectName('category_stack') + self.category_layout.addWidget(self.category_stack) + self.general_page = QtWidgets.QWidget() + self.general_page.setObjectName('general_page') + self.category_stack.addWidget(self.general_page) + self.editor_page = QtWidgets.QWidget() + self.editor_page.setObjectName('editor_page') + self.category_stack.addWidget(self.editor_page) + self.renderer_page = QtWidgets.QWidget() + self.renderer_page.setObjectName('renderer_page') + self.category_stack.addWidget(self.renderer_page) + self.render_layout = QtWidgets.QVBoxLayout(self.renderer_page) + self.render_options_combobox = QtWidgets.QComboBox(self.renderer_page) self.render_options_combobox.setObjectName("render_options_combobox") - self.configure_layout.addWidget(self.render_options_combobox) + self.render_layout.addWidget(self.render_options_combobox) self.render_options_stack = QtWidgets.QStackedWidget(self) self.render_options_stack.setObjectName("render_options_stack") - self.configure_layout.addWidget(self.render_options_stack) + self.render_layout.addWidget(self.render_options_stack) + # self.renderer_page.setLayout(self.render_layout) self.button_box = QtWidgets.QDialogButtonBox(self) self.button_box.setOrientation(QtCore.Qt.Horizontal) self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | @@ -33,16 +55,19 @@ class ConfigureDialog(QtWidgets.QDialog): self.retranslate_ui() self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.reject) + self.category_list_widget.currentRowChanged.connect(self.category_stack.setCurrentIndex) self.render_options_combobox.activated.connect(self.render_options_stack.setCurrentIndex) def retranslate_ui(self): _translate = QtCore.QCoreApplication.translate self.setWindowTitle(_translate("ConfigureDialog", "Configure")) - # self.render_options_groupbox.setTitle(_translate("ConfigureDialog", "Render Options")) + self.category_list_widget.item(0).setText(_translate('ConfigureDialog', 'General')) + self.category_list_widget.item(1).setText(_translate('ConfigureDialog', 'Editor')) + self.category_list_widget.item(2).setText(_translate('ConfigureDialog', 'Render')) def setup_options(self): self.option_widgets = {} - for group in OPTION_GROUPS: + for group in get_option_groups(): pretty_group = group.replace('_', ' ').title() self.render_options_combobox.addItem(pretty_group) page_widget = QtWidgets.QWidget() @@ -53,7 +78,29 @@ class ConfigureDialog(QtWidgets.QDialog): self.option_widgets[name] = QtWidgets.QSpinBox(page_widget) elif details["type"] is bool: self.option_widgets[name] = QtWidgets.QCheckBox(page_widget) + elif 'font' in name: + self.option_widgets[name] = QtWidgets.QFontComboBox(page_widget) else: self.option_widgets[name] = QtWidgets.QLineEdit(page_widget) page_layout.addRow(pretty_name, self.option_widgets[name]) self.render_options_stack.addWidget(page_widget) + + def load_settings(self): + """Load the settings""" + for name, details in get_options().items(): + if self.settings.contains(name): + if details["type"] is int: + self.option_widgets[name].setValue(self.settings.value(name)) + + def save_settings(self): + """Save the settings""" + + def exec(self): + """Execute the dialog""" + self.load_settings() + return super().exec() + + def accept(self): + """The user clicked the "OK" button""" + self.save_settings() + return super().accept()