Add editor settings to the configure dialog, including loading and saving
This commit is contained in:
parent
5edd932a86
commit
4af5f8313b
@ -18,9 +18,9 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.settings = QtCore.QSettings()
|
self.settings = QtCore.QSettings()
|
||||||
self.settings.beginGroup('render')
|
|
||||||
self.setup_ui()
|
self.setup_ui()
|
||||||
self.setup_options()
|
self.setup_options()
|
||||||
|
self.editor_values = {}
|
||||||
|
|
||||||
def setup_ui(self):
|
def setup_ui(self):
|
||||||
self.setObjectName('ConfigureDialog')
|
self.setObjectName('ConfigureDialog')
|
||||||
@ -47,8 +47,16 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
self.editor_page.setObjectName('editor_page')
|
self.editor_page.setObjectName('editor_page')
|
||||||
self.category_stack.addWidget(self.editor_page)
|
self.category_stack.addWidget(self.editor_page)
|
||||||
self.editor_layout = QtWidgets.QFormLayout(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 = 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_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
|
# Renderer settings
|
||||||
self.renderer_page = QtWidgets.QWidget()
|
self.renderer_page = QtWidgets.QWidget()
|
||||||
self.renderer_page.setObjectName('renderer_page')
|
self.renderer_page.setObjectName('renderer_page')
|
||||||
@ -73,6 +81,8 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
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.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)
|
||||||
|
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):
|
def retranslate_ui(self):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
@ -129,12 +139,25 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
"""Load the settings"""
|
"""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():
|
for name, details in get_options().items():
|
||||||
if self.settings.contains(name):
|
if self.settings.contains(name):
|
||||||
value = self.settings.value(name)
|
value = self.settings.value(name)
|
||||||
if value is None:
|
if value is None:
|
||||||
continue
|
continue
|
||||||
if details["type"] is int:
|
if details['type'] is int:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
self.option_widgets[name].setValue(value)
|
self.option_widgets[name].setValue(value)
|
||||||
elif details['type'] is bool:
|
elif details['type'] is bool:
|
||||||
@ -146,13 +169,24 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
else:
|
else:
|
||||||
self.option_widgets[name].setText(value)
|
self.option_widgets[name].setText(value)
|
||||||
self.option_values[name] = value
|
self.option_values[name] = value
|
||||||
|
self.settings.endGroup()
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
"""Save the settings"""
|
"""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():
|
for name, value in self.option_values.items():
|
||||||
if isinstance(value, QtGui.QFont):
|
if isinstance(value, QtGui.QFont):
|
||||||
value = value.family()
|
value = value.family()
|
||||||
self.settings.setValue(name, value)
|
self.settings.setValue(name, value)
|
||||||
|
self.settings.endGroup()
|
||||||
|
|
||||||
def exec(self):
|
def exec(self):
|
||||||
"""Execute the dialog"""
|
"""Execute the dialog"""
|
||||||
@ -163,3 +197,11 @@ class ConfigureDialog(QtWidgets.QDialog):
|
|||||||
"""The user clicked the "OK" button"""
|
"""The user clicked the "OK" button"""
|
||||||
self.save_settings()
|
self.save_settings()
|
||||||
return super().accept()
|
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
|
Loading…
Reference in New Issue
Block a user