FEM: gui objects, catch a syntax error, if the user triggers the OK button with a wrong input

This commit is contained in:
Bernd Hahnebach
2019-06-27 00:20:00 +02:00
parent 26a538f824
commit e5ba35735b

View File

@@ -124,6 +124,17 @@ class _TaskPanel(object):
self._obj.PotentialEnabled = \
not self._paramWidget.potentialBox.isChecked()
if self._obj.PotentialEnabled:
quantity = Units.Quantity(self._paramWidget.potentialTxt.text())
self._obj.Potential = float(quantity.getValueAs(unit))
# if the input widget shows not a green hook, but the user presses ok
# we could run into a syntax error on getting the quantity, try mV
quantity = None
try:
quantity = Units.Quantity(self._paramWidget.potentialTxt.text())
except:
FreeCAD.Console.PrintMessage(
'Potential not set. OK has been triggered wihtout a green hook '
'in the input field. Not recognised input: {}\n'
.format(self._paramWidget.potentialTxt.text())
)
if quantity is not None:
self._obj.Potential = float(quantity.getValueAs(unit))
self._obj.PotentialConstant = self._paramWidget.potentialConstantBox.isChecked()