Skip to content

Commit

Permalink
Fixes #22. Special handling of ANY options with default values
Browse files Browse the repository at this point in the history
- When default_value=None, now renders as 'None (default)' for consistency with combobox options when selected
- Can get back to the default value by writing the default value or clearing the line edit
  • Loading branch information
markfinal committed Dec 9, 2022
1 parent 1a0a561 commit 7fe501d
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions cruiz/recipe/recipewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,18 @@ def _load_configuration_dock(
):
value_edit = QtWidgets.QLineEdit()
if key in options:
value_edit.setText(options[key])
value_text = options[key]
else:
value_edit.setText(default_value or "")
if (
isinstance(values, list)
and None in values
and default_value is None
):
value_text = "None (default)"
else:
value_text = f"{default_value} (default)"
value_edit.setText(value_text)
value_edit.setProperty("DefaultValue", default_value)
value_edit.editingFinished.connect(self._option_any_changed)
self._ui.optionsLayout.addWidget(value_edit, i, 1)
else:
Expand Down Expand Up @@ -716,7 +725,17 @@ def _option_any_changed(self) -> None:
)
settings = RecipeSettings()
text = widget.text()
settings.append_options({name_of_option: text or None}) # type: ignore
default_value = widget.property("DefaultValue")
if (
text.endswith(" (default)")
or (str(default_value) == text)
or ((default_value is None and text.startswith("None")) or text == "")
):
settings.append_options({name_of_option: None}) # type: ignore
with BlockSignals(widget):
widget.setText(f"{default_value} (default)")
else:
settings.append_options({name_of_option: text}) # type: ignore
RecipeSettingsWriter.from_recipe(self.recipe).sync(settings)
self.configuration_changed.emit()

Expand All @@ -732,7 +751,7 @@ def _option_combo_changed(self, index: int) -> None:
option_value = widget.itemText(index)
real_option_value = widget.itemData(index)
settings = RecipeSettings()
if " (default)" in option_value:
if option_value.endswith(" (default)"):
settings.append_options({name_of_option: None}) # type: ignore
else:
settings.append_options(
Expand Down

0 comments on commit 7fe501d

Please sign in to comment.