diff --git a/gns3/items/node_item.py b/gns3/items/node_item.py index f12f5833e..c852992b4 100644 --- a/gns3/items/node_item.py +++ b/gns3/items/node_item.py @@ -144,7 +144,7 @@ def symbol(self): @qslot def _symbolLoadedCallback(self, path, *args): - renderer = QImageSvgRenderer(path) + renderer = QImageSvgRenderer(path, fallback=":/icons/cancel.svg") renderer.setObjectName(path) self.setSharedRenderer(renderer) if self._node.settings().get("symbol") != self._symbol: diff --git a/gns3/qt/qimage_svg_renderer.py b/gns3/qt/qimage_svg_renderer.py index ef7dfe08c..f5476074c 100644 --- a/gns3/qt/qimage_svg_renderer.py +++ b/gns3/qt/qimage_svg_renderer.py @@ -22,16 +22,21 @@ from . import QtSvg from . import QtGui +import logging +log = logging.getLogger(__name__) + class QImageSvgRenderer(QtSvg.QSvgRenderer): """ Renderer pixmap and svg to SVG item :param path_or_data: Svg element of path to a SVG + :param fallback: Image to display if the image is not working """ - def __init__(self, path_or_data=None): + def __init__(self, path_or_data=None, fallback=None): super().__init__() + self._fallback = fallback self._svg = """""" self.load(path_or_data) @@ -61,12 +66,21 @@ def load(self, path_or_data): data = QtCore.QByteArray() buf = QtCore.QBuffer(data) image.save(buf, 'PNG') - self._svg = """ - -""".format(data=bytes(data.toBase64()).decode(), - width=image.rect().width(), - height=image.rect().height()) - return super().load(self._svg.encode()) + if image.rect().width() > 0: + self._svg = """ + + """.format(data=bytes(data.toBase64()).decode(), + width=image.rect().width(), + height=image.rect().height()) + res = super().load(self._svg.encode()) + elif self._fallback: + log.error("Invalid or corrupted image file") + res = super().load(self._fallback) + else: + self._svg = """ + """ + res = super().load(self._svg.encode()) + return res def svg(self): """