From 4af5f8313b9a7b0bcac4bc88a4bb4e16ae51bf0e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 5 Aug 2021 14:52:59 -0700 Subject: [PATCH] Add editor settings to the configure dialog, including loading and saving --- src/ukatali/configuredialog.py | 46 ++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/ukatali/configuredialog.py b/src/ukatali/configuredialog.py index d8ffa7f..f9d151f 100644 --- a/src/ukatali/configuredialog.py +++ b/src/ukatali/configuredialog.py @@ -18,9 +18,9 @@ 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() + self.editor_values = {} def setup_ui(self): self.setObjectName('ConfigureDialog') @@ -47,8 +47,16 @@ class ConfigureDialog(QtWidgets.QDialog): self.editor_page.setObjectName('editor_page') self.category_stack.addWidget(self.editor_page) self.editor_layout = QtWidgets.QFormLayout(self.editor_page) + self.editor_layout.setObjectName('editor_layout') self.editor_font_combobox = QtWidgets.QFontComboBox(self.editor_page) + self.editor_font_combobox.setFontFilters(QtWidgets.QFontComboBox.MonospacedFonts) + self.editor_font_combobox.setCurrentFont(QtGui.QFont('monospace')) + self.editor_font_combobox.setObjectName('editor_font_combobox') self.editor_layout.addRow('Font', self.editor_font_combobox) + self.editor_size_spinbox = QtWidgets.QSpinBox(self.editor_page) + self.editor_size_spinbox.setValue(10) + self.editor_size_spinbox.setObjectName('editor_size_spinbox') + self.editor_layout.addRow('Size', self.editor_size_spinbox) # Renderer settings self.renderer_page = QtWidgets.QWidget() self.renderer_page.setObjectName('renderer_page') @@ -73,6 +81,8 @@ class ConfigureDialog(QtWidgets.QDialog): 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.editor_font_combobox.currentFontChanged.connect(self.on_editor_font_changed) + self.editor_size_spinbox.valueChanged.connect(self.on_editor_size_changed) def retranslate_ui(self): _translate = QtCore.QCoreApplication.translate @@ -129,12 +139,25 @@ class ConfigureDialog(QtWidgets.QDialog): def load_settings(self): """Load the settings""" + # Editor settings + self.settings.beginGroup('editor') + if self.settings.contains('font'): + value = self.settings.value('font') + self.editor_values['font'] = value + self.editor_font_combobox.setCurrentFont(QtGui.QFont(value)) + if settings.value.contains('size') + value = self.settings.value('size') + self.editor_values['size'] = int(size) + self.editor_size.setValue(int(size)) + self.settings.endGroup() + # Renderer settings + self.settings.beginGroup('render') for name, details in get_options().items(): if self.settings.contains(name): value = self.settings.value(name) if value is None: continue - if details["type"] is int: + if details['type'] is int: value = int(value) self.option_widgets[name].setValue(value) elif details['type'] is bool: @@ -146,13 +169,24 @@ class ConfigureDialog(QtWidgets.QDialog): else: self.option_widgets[name].setText(value) self.option_values[name] = value + self.settings.endGroup() def save_settings(self): """Save the settings""" + # Editor settings + self.settings.beginGroup('editor') + for name, value in self.editor_values.items(): + if isinstance(value, QtGui.QFont): + value = value.family() + self.settings.setValue(name, value) + self.settings.endGroup() + # Renderer settings + self.settings.beginGroup('render') for name, value in self.option_values.items(): if isinstance(value, QtGui.QFont): value = value.family() self.settings.setValue(name, value) + self.settings.endGroup() def exec(self): """Execute the dialog""" @@ -163,3 +197,11 @@ class ConfigureDialog(QtWidgets.QDialog): """The user clicked the "OK" button""" self.save_settings() return super().accept() + + def on_editor_font_changed(self, font): + """Set the new font if the font has changed""" + self.editor_values['font'] = font.family() + + def on_editor_size_changed(self, size): + """Set the new size if the size has changed""" + self.editor_values['size'] = size \ No newline at end of file