gui: catch invalid inputs

Change-Id: Ie0525e4ef9a94085da811e7eaa2e0b7430bade95
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/33388
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
Alexander Zaft 2024-03-26 15:49:07 +01:00 committed by Markus Zolliker
parent 76a78871b4
commit a73b7e7d88

View File

@ -24,9 +24,9 @@ from frappy.gui.qt import QColor, QDialog, QHBoxLayout, QIcon, QLabel, \
QLineEdit, QMessageBox, QPropertyAnimation, QPushButton, Qt, QToolButton, \
QWidget, pyqtProperty, pyqtSignal
from frappy.gui.inputwidgets import get_input_widget
from frappy.gui.util import Colors, loadUi
from frappy.gui.valuewidgets import get_widget
from frappy.gui.inputwidgets import get_input_widget
class CommandDialog(QDialog):
@ -54,7 +54,11 @@ class CommandDialog(QDialog):
self.resize(self.sizeHint())
def get_value(self):
return True, self.widgets[0].get_value()
try:
return self.widgets[0].get_value()
except Exception as e:
QMessageBox.warning(self.parent(), 'Operation failed', str(e))
return None
def exec(self):
if super().exec():
@ -95,8 +99,9 @@ class CommandButton(QPushButton):
if self._argintype:
dlg = CommandDialog(self._cmdname, self._argintype)
args = dlg.exec()
if args: # not 'Cancel' clicked
self._cb(self._cmdname, args[1])
if args is not None:
# no errors when converting value and 'Cancel' wasn't clicked
self._cb(self._cmdname, args)
else:
# no need for arguments
self._cb(self._cmdname, None)
@ -442,8 +447,8 @@ class ModuleWidget(QWidget):
self.paramDetails.emit(self._name, param)
def _button_pressed(self, param):
target = self._paramInputs[param].get_input()
try:
target = self._paramInputs[param].get_input()
self._node.setParameter(self._name, param, target)
except Exception as e:
QMessageBox.warning(self.parent(), 'Operation failed', str(e))