From 3029ebec4f430716a66c551f2af8d9da9b1e4c69 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 2 Aug 2021 14:06:01 -0700 Subject: [PATCH] Add an initial configure dialog --- resources/configuredialog.ui | 72 ++++++++++++++++++++++++++++++++++ src/ukatali/configuredialog.py | 59 ++++++++++++++++++++++++++++ src/ukatali/mainwindow.py | 8 +++- 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 resources/configuredialog.ui create mode 100644 src/ukatali/configuredialog.py diff --git a/resources/configuredialog.ui b/resources/configuredialog.ui new file mode 100644 index 0000000..c96f327 --- /dev/null +++ b/resources/configuredialog.ui @@ -0,0 +1,72 @@ + + + ConfigureDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + Render Options + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ConfigureDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ConfigureDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ukatali/configuredialog.py b/src/ukatali/configuredialog.py new file mode 100644 index 0000000..c068275 --- /dev/null +++ b/src/ukatali/configuredialog.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +from PyQt5 import QtCore, QtWidgets + +from chordpro.renderers.html import OPTION_GROUPS, get_options + + +class ConfigureDialog(QtWidgets.QDialog): + def __init__(self, parent=None): + super().__init__(parent) + self.settings = QtCore.QSettings() + self.settings.beginGroup('render') + self.setup_ui() + self.setup_options() + + def setup_ui(self): + self.setObjectName('ConfigureDialog') + self.resize(800, 600) + self.configure_layout = QtWidgets.QVBoxLayout(self) + self.configure_layout.setObjectName("configure_layout") + self.render_options_combobox = QtWidgets.QComboBox(self) + self.render_options_combobox.setObjectName("render_options_combobox") + self.configure_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.button_box = QtWidgets.QDialogButtonBox(self) + self.button_box.setOrientation(QtCore.Qt.Horizontal) + self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel | + QtWidgets.QDialogButtonBox.Ok) + self.button_box.setObjectName("button_box") + self.configure_layout.addWidget(self.button_box) + + self.retranslate_ui() + self.button_box.accepted.connect(self.accept) + self.button_box.rejected.connect(self.reject) + 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")) + + def setup_options(self): + self.option_widgets = {} + for group in OPTION_GROUPS: + pretty_group = group.replace('_', ' ').title() + self.render_options_combobox.addItem(pretty_group) + page_widget = QtWidgets.QWidget() + page_layout = QtWidgets.QFormLayout(page_widget) + for name, details in get_options(group).items(): + pretty_name = name.replace(group, '').replace('_', ' ').title() + if details["type"] is int: + self.option_widgets[name] = QtWidgets.QSpinBox(page_widget) + elif details["type"] is bool: + self.option_widgets[name] = QtWidgets.QCheckBox(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) diff --git a/src/ukatali/mainwindow.py b/src/ukatali/mainwindow.py index c2ac673..14f65eb 100644 --- a/src/ukatali/mainwindow.py +++ b/src/ukatali/mainwindow.py @@ -4,6 +4,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets, Qsci from chordpro import Song from chordpro.renderers.html import render +from ukatali.configuredialog import ConfigureDialog from ukatali.lexer import ChordProLexer @@ -12,6 +13,7 @@ class MainWindow(QtWidgets.QMainWindow): super().__init__(parent) self.setup_ui() self.filename = None + self.configure_dialog = ConfigureDialog(self) def setup_ui(self): self.setObjectName('MainWindow') @@ -168,10 +170,10 @@ class MainWindow(QtWidgets.QMainWindow): self.cut_action.triggered.connect(self.file_editor.cut) self.copy_action.triggered.connect(self.file_editor.copy) self.paste_action.triggered.connect(self.file_editor.paste) - # QtCore.QMetaObject.connectSlotsByName(self) self.open_action.triggered.connect(self.on_open_clicked) self.save_action.triggered.connect(self.on_save_clicked) self.save_as_action.triggered.connect(self.on_save_as_clicked) + self.configure_action.triggered.connect(self.on_configure_clicked) self.file_editor.textChanged.connect(self.on_text_changed) def retranslate_ui(self): @@ -268,6 +270,10 @@ class MainWindow(QtWidgets.QMainWindow): QtCore.QSettings().setValue('files/last-directory', str(Path(filename).parent)) self.on_save_clicked() + def on_configure_clicked(self): + """Show the configuration dialog""" + self.configure_dialog.exec() + def on_text_changed(self): """Update the preview when the text changes""" text = self.file_editor.text()