From 9d628a445806a1003d7f1d077e5f64699ef46c7b Mon Sep 17 00:00:00 2001 From: Christoph Wiedemann <62332054+cwiede@users.noreply.github.com> Date: Tue, 7 Jul 2020 17:44:40 +0200 Subject: [PATCH] - fix interpretation of properties from config files - fix bool editor --- nexxT/core/PropertyHandlers.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nexxT/core/PropertyHandlers.py b/nexxT/core/PropertyHandlers.py index 630f330..c1a6182 100644 --- a/nexxT/core/PropertyHandlers.py +++ b/nexxT/core/PropertyHandlers.py @@ -43,7 +43,7 @@ def fromConfig(self, value): :param value: an integer is expected :return: the validated integer """ - assert isinstance(value, int) + assert isinstance(value, (float, int, bool)) return self.validate(value) def toConfig(self, value): @@ -241,7 +241,7 @@ def fromConfig(self, value): :param value: a float is expected :return: the validated float """ - assert isinstance(value, (float, int)) + assert isinstance(value, (float, int, bool)) return float(self.validate(value)) def toConfig(self, value): @@ -335,7 +335,7 @@ def fromConfig(self, value): :param value: a bool is expected :return: the bool """ - assert isinstance(value, bool) + assert isinstance(value, (float, int, bool)) return self.validate(value) def toConfig(self, value): @@ -362,6 +362,8 @@ def validate(self, value): :param value: the value to be tested (a bool) :return: the adapted, valid value """ + if isinstance(value, str): + return value.lower() == "true" return bool(value) def createEditor(self, parent): @@ -370,7 +372,8 @@ def createEditor(self, parent): :param parent: the parent of the widget :return: a QCheckBox instance """ - res = QCheckBox(parent) + res = QComboBox(parent) + res.addItems([self.toViewValue(x) for x in [False, True]]) res.setFrame(False) return res @@ -381,7 +384,7 @@ def setEditorData(self, editor, value): :param value: the option value (a bool) :return: None """ - editor.setChecked(value) + editor.setCurrentText(self.toViewValue(value)) def getEditorData(self, editor): """ @@ -389,8 +392,10 @@ def getEditorData(self, editor): :param editor: the instance returned by createEditor :return: the bool value """ - return editor.isChecked() - + res = editor.currentText() == self.toViewValue(True) + return res + + def defaultHandler(propertyValue): """ Return a suitable property handler given the value.