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 155567816c45c4e13061b8cd93931d2b9c0ddd5c..2860e9e50e343f03d66e29b1927522e2cf8d314e 100644 --- a/src/simudator/gui/module_graphics_item/module_graphics_item.py +++ b/src/simudator/gui/module_graphics_item/module_graphics_item.py @@ -6,6 +6,7 @@ from qtpy.QtCore import Slot from qtpy.QtGui import QCursor from qtpy.QtWidgets import ( QAction, + QErrorMessage, QGraphicsItem, QGraphicsObject, QGraphicsRectItem, @@ -46,6 +47,8 @@ class ModuleGraphicsItem(QGraphicsObject, QGraphicsItem): # Save module for later updates self.module = module + self.errorMessageWidget = QErrorMessage() + # Use modules name if no name is given if name is None: self.name = self.module.name @@ -185,8 +188,29 @@ 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 + if isinstance(parsed_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 diff --git a/src/simudator/processor/mia/gui/mia_grx_graphic.py b/src/simudator/processor/mia/gui/mia_grx_graphic.py index d7d94295ee0adc6f33fc7dc5f1c60d5beaa9bfc5..54dba094d489c8f8493d02cf60550c3cc5fb6c8a 100644 --- a/src/simudator/processor/mia/gui/mia_grx_graphic.py +++ b/src/simudator/processor/mia/gui/mia_grx_graphic.py @@ -3,6 +3,7 @@ import math from qtpy.QtCore import QPointF from qtpy.QtGui import QPolygonF from qtpy.QtWidgets import ( + QErrorMessage, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsRectItem, @@ -126,14 +127,18 @@ class GrxGraphicsItem(ModuleGraphicsItem): ) # Add ports to and from bus - from_bus_port = PortGraphicsItem(self.module.signals["in_input"], Orientation.RIGHT, self) + from_bus_port = PortGraphicsItem( + self.module.signals["in_input"], Orientation.RIGHT, self + ) from_bus_port.setPos( rect_width + self.LINE_LENGTH + self.MUX_WIDTH, # Use the buses port margins so the ports align nicely mux_height / 2 - BusGraphicsItem.PORT_MARGIN / 2, ) - to_bus_port = PortGraphicsItem(self.module.signals["out_content"], Orientation.RIGHT, self) + to_bus_port = PortGraphicsItem( + self.module.signals["out_content"], Orientation.RIGHT, self + ) to_bus_port.setPos( rect_width + self.LINE_LENGTH + self.MUX_WIDTH, # Use the buses port margins so the ports align nicely