Skip to content

Commit

Permalink
- fix interpretation of properties from config files
Browse files Browse the repository at this point in the history
- fix bool editor
  • Loading branch information
cwiede committed Jul 7, 2020
1 parent 424dc7f commit 9d628a4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nexxT/core/PropertyHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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

Expand All @@ -381,16 +384,18 @@ 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):
"""
return the currently edited value
: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.
Expand Down

0 comments on commit 9d628a4

Please sign in to comment.