Skip to content

Commit

Permalink
#30 add recipe default option to settings (#31)
Browse files Browse the repository at this point in the history
* add default recipe in preferences

* Update CHANGELOG

* ref: changes for review #31
  • Loading branch information
B-Hartmann authored Oct 15, 2024
1 parent ffdced0 commit ec362ca
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.7.4
- enh: add user preference for default recipe
0.7.3
- fix: segmentation fault due to mixing threading.Thread with PyQt6
- enh: introduce logging and make logging Path available to the user
Expand Down
9 changes: 7 additions & 2 deletions mpl_data_cast/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ def __init__(self, *args, **kwargs):
recipes = mpldc_recipe.get_available_recipe_names()
for rr in recipes:
self.comboBox_recipe.addItem(rr, rr)
# Set default recipe to "CatchAll"
default = recipes.index("CatchAll")
# Set recipe according to preferences
recipe_settings = self.settings.value("main/recipe",
"CatchAll")
if recipe_settings in recipes:
default = recipes.index(recipe_settings)
else:
default = recipes.index("CatchAll")
self.comboBox_recipe.setCurrentIndex(default)
self.on_recipe_changed()

Expand Down
11 changes: 11 additions & 0 deletions mpl_data_cast/gui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from PyQt6 import uic, QtCore, QtWidgets

from .. import recipe as mpldc_recipe
from ..util import is_dir_writable


Expand All @@ -21,10 +22,15 @@ def __init__(self, parent, *args, **kwargs):
self.settings = QtCore.QSettings()
self.parent = parent

# Populate the recipe list
self.available_recipes = mpldc_recipe.get_available_recipe_names()
for rr in self.available_recipes:
self.comboBox_recipe.addItem(rr, rr)
#: configuration keys, corresponding widgets, and defaults
self.config_pairs = [
["main/output_path", self.lineEdit_output_path,
pathlib.Path.home()],
["main/recipe", self.comboBox_recipe, "CatchAll"]
]
self.reload()

Expand All @@ -50,6 +56,9 @@ def reload(self):
widget.setText(str(value))
elif isinstance(widget, QtWidgets.QSpinBox):
widget.setValue(int(value))
elif widget is self.comboBox_recipe:
recipe_idx = self.available_recipes.index(str(value))
widget.setCurrentIndex(recipe_idx)
else:
raise NotImplementedError("No rule for '{}'".format(key))

Expand All @@ -68,6 +77,8 @@ def on_settings_ok(self):
value = str(pathlib.Path.home())
elif isinstance(widget, QtWidgets.QSpinBox):
value = int(widget.value())
elif isinstance(widget, QtWidgets.QComboBox):
value = widget.currentData()
else:
raise NotImplementedError("No rule for '{}'".format(key))
self.settings.setValue(key, value)
Expand Down
60 changes: 39 additions & 21 deletions mpl_data_cast/gui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,61 @@
<iconset theme="gtk-preferences">
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_output_path">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Select directory</string>
<string>Default output directory:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_output_path"/>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_output_path">
<property name="text">
<string>Select directory</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Default output directory:</string>
<string>Default recipe:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_recipe">
<property name="insertPolicy">
<enum>QComboBox::InsertAlphabetically</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit ec362ca

Please sign in to comment.