Add an initial configure dialog

This commit is contained in:
Raoul Snyman 2021-08-02 14:06:01 -07:00
parent b9666a7503
commit 3029ebec4f
3 changed files with 138 additions and 1 deletions

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConfigureDialog</class>
<widget class="QDialog" name="ConfigureDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="configureLayout">
<item>
<widget class="QGroupBox" name="renderOptionsGroupBox">
<property name="title">
<string>Render Options</string>
</property>
<layout class="QFormLayout" name="renderOptionsLayout"/>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigureDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ConfigureDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

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

View File

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