Commit b91ed246 authored by Samuel GAIST's avatar Samuel GAIST

[widgets][plotterparameterseditor] Fix bool type default value handling

parent f2902bcb
Pipeline #49892 failed with stage
in 11 minutes and 45 seconds
...@@ -126,17 +126,29 @@ class RestrictedParameterWidget(QWidget): ...@@ -126,17 +126,29 @@ class RestrictedParameterWidget(QWidget):
super().__init__(parent) super().__init__(parent)
self._type = data.get("type", None) self._type = data.get("type", None)
default = data.get("default", "" if self._type == "string" else 0)
# cast the default value to the required type # cast the default value to the required type
cast_fn = np.cast[self._type] if self._type != "string" else str if self._type == "string":
cast_fn = str
default = data.get("default", "")
self.default = ""
elif self._type == "bool":
cast_fn = bool
default = data.get("default", False)
self.default = False
else:
cast_fn = np.cast[self._type]
default = data.get("default", 0)
self.default = 0
try: try:
default = cast_fn(default) default = cast_fn(default)
except ValueError: except ValueError:
logger.exception( logger.exception(
f"Failed to convert the default value: {default} to type {self._type}", f"Failed to convert the default value: {default} to type {self._type}",
) )
default = cast_fn("" if self._type == "string" else 0) else:
self.default = default self.default = default
self.current_type = InputType[self._type.upper()] self.current_type = InputType[self._type.upper()]
self.modality = "single" self.modality = "single"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment