Skip to content
Snippets Groups Projects
Commit 72abb33c authored by Martin Högstedt's avatar Martin Högstedt
Browse files

Merge branch '58-grx-craches-when-inputing-incorrect-data-in-edit-module-state' into 'main'

Grx displays error message instead of crashing

Closes #58

See merge request !36
parents a61ebd64 46757a0e
No related branches found
No related tags found
1 merge request!36Grx displays error message instead of crashing
Pipeline #133128 failed
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment