From 0cdae997ba4e9b7acfc3c0da70b4b54bcc0b8cbc Mon Sep 17 00:00:00 2001 From: Martin <martin.hogstedt@hotmail.com> Date: Tue, 2 Jul 2024 14:06:09 +0200 Subject: [PATCH] grx will no longer crash when a string is entered in the edit module state dialog --- .../module_graphics_item/module_graphics_item.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/simudator/gui/module_graphics_item/module_graphics_item.py b/src/simudator/gui/module_graphics_item/module_graphics_item.py index 320ae76..172f5d4 100644 --- a/src/simudator/gui/module_graphics_item/module_graphics_item.py +++ b/src/simudator/gui/module_graphics_item/module_graphics_item.py @@ -183,12 +183,27 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): """ try: parsed_value = ast.literal_eval(value) + + # ast.literal_eval only raises an error the the + # parsed value isn't a valid data type. + # If the user edits GRX and enters a string "a" + # it will crash + + if isinstance(parsed_value, list): + for value in parsed_value: + if isinstance(value, str): + raise TypeError + except SyntaxError as e: self.errorMessageWidget.showMessage(str(e)) except ValueError as e: self.errorMessageWidget.showMessage( "Value Error. Unable to parse input. Make sure it is in the correct base." ) + except TypeError as e: + self.errorMessageWidget.showMessage( + "Type Error. Unable to parse input. Make sure it is the correct type." + ) else: module_state = self.module.get_state() module_state[state] = parsed_value -- GitLab