From b91ed246ef70f8b3f8150a32063e9421435e9c7b Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Wed, 14 Apr 2021 17:31:20 +0200
Subject: [PATCH] [widgets][plotterparameterseditor] Fix bool type default
 value handling

---
 .../editor/widgets/plotterparameterseditor.py | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/beat/editor/widgets/plotterparameterseditor.py b/beat/editor/widgets/plotterparameterseditor.py
index 01f972a0..3d919c09 100644
--- a/beat/editor/widgets/plotterparameterseditor.py
+++ b/beat/editor/widgets/plotterparameterseditor.py
@@ -126,17 +126,29 @@ class RestrictedParameterWidget(QWidget):
         super().__init__(parent)
 
         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_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:
             default = cast_fn(default)
         except ValueError:
             logger.exception(
                 f"Failed to convert the default value: {default} to type {self._type}",
             )
-            default = cast_fn("" if self._type == "string" else 0)
-        self.default = default
+        else:
+            self.default = default
 
         self.current_type = InputType[self._type.upper()]
         self.modality = "single"
-- 
GitLab