Enhance the configuration dialog
This commit is contained in:
parent
3029ebec4f
commit
27238aa0ca
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from PyQt5 import QtCore, QtWidgets
|
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):
|
class ConfigureDialog(QtWidgets.QDialog):
|
||||||
@ -14,15 +14,37 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
def setup_ui(self):
|
def setup_ui(self):
|
||||||
self.setObjectName('ConfigureDialog')
|
self.setObjectName('ConfigureDialog')
|
||||||
self.resize(800, 600)
|
self.resize(600, 400)
|
||||||
self.configure_layout = QtWidgets.QVBoxLayout(self)
|
self.configure_layout = QtWidgets.QVBoxLayout(self)
|
||||||
self.configure_layout.setObjectName("configure_layout")
|
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.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 = QtWidgets.QStackedWidget(self)
|
||||||
self.render_options_stack.setObjectName("render_options_stack")
|
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 = QtWidgets.QDialogButtonBox(self)
|
||||||
self.button_box.setOrientation(QtCore.Qt.Horizontal)
|
self.button_box.setOrientation(QtCore.Qt.Horizontal)
|
||||||
self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel |
|
self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel |
|
||||||
@ -33,16 +55,19 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
self.retranslate_ui()
|
self.retranslate_ui()
|
||||||
self.button_box.accepted.connect(self.accept)
|
self.button_box.accepted.connect(self.accept)
|
||||||
self.button_box.rejected.connect(self.reject)
|
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)
|
self.render_options_combobox.activated.connect(self.render_options_stack.setCurrentIndex)
|
||||||
|
|
||||||
def retranslate_ui(self):
|
def retranslate_ui(self):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
self.setWindowTitle(_translate("ConfigureDialog", "Configure"))
|
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):
|
def setup_options(self):
|
||||||
self.option_widgets = {}
|
self.option_widgets = {}
|
||||||
for group in OPTION_GROUPS:
|
for group in get_option_groups():
|
||||||
pretty_group = group.replace('_', ' ').title()
|
pretty_group = group.replace('_', ' ').title()
|
||||||
self.render_options_combobox.addItem(pretty_group)
|
self.render_options_combobox.addItem(pretty_group)
|
||||||
page_widget = QtWidgets.QWidget()
|
page_widget = QtWidgets.QWidget()
|
||||||
@ -53,7 +78,29 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
self.option_widgets[name] = QtWidgets.QSpinBox(page_widget)
|
self.option_widgets[name] = QtWidgets.QSpinBox(page_widget)
|
||||||
elif details["type"] is bool:
|
elif details["type"] is bool:
|
||||||
self.option_widgets[name] = QtWidgets.QCheckBox(page_widget)
|
self.option_widgets[name] = QtWidgets.QCheckBox(page_widget)
|
||||||
|
elif 'font' in name:
|
||||||
|
self.option_widgets[name] = QtWidgets.QFontComboBox(page_widget)
|
||||||
else:
|
else:
|
||||||
self.option_widgets[name] = QtWidgets.QLineEdit(page_widget)
|
self.option_widgets[name] = QtWidgets.QLineEdit(page_widget)
|
||||||
page_layout.addRow(pretty_name, self.option_widgets[name])
|
page_layout.addRow(pretty_name, self.option_widgets[name])
|
||||||
self.render_options_stack.addWidget(page_widget)
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user