A bit better error handling

main
Micke Nordin 2 years ago
parent 20de55c562
commit ff0e68327d
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -207,6 +207,7 @@ class CoordinatesExtension(inkex.EffectExtension):
def effect(self) -> None:
images = self.svg.selection.get(IImage)
pilimages = list()
for elem in images:
xlink = elem.get("xlink:href")
if xlink is not None and xlink[:5] == "data:":
@ -221,15 +222,30 @@ class CoordinatesExtension(inkex.EffectExtension):
else:
imgdata = base64.b64decode(data)
pilimage = Image.open(io.BytesIO(imgdata))
pilimages.append(pilimage)
if not pilimage:
if len(pilimages) == 0:
self.window.message_box("Could not find image in selection")
self.window.show_all()
self.window.destroy()
else:
self.window.add_image(pilimage, mimetype)
self.window.show_all()
Gtk.main()
breakout = False
for pilimage in pilimages:
try:
self.window.add_image(pilimage, mimetype)
breakout = True
except gi.repository.GLib.GError as e:
self.window.message_box(
"Could not load image type: {}, error was: {}".format(
mimetype, e))
breakout = False
if breakout:
break
if breakout:
self.window.show_all()
Gtk.main()
else:
self.window.destroy()
if __name__ == '__main__':

Loading…
Cancel
Save