A bit better error handling
This commit is contained in:
parent
20de55c562
commit
ff0e68327d
1 changed files with 20 additions and 4 deletions
|
@ -207,6 +207,7 @@ class CoordinatesExtension(inkex.EffectExtension):
|
||||||
|
|
||||||
def effect(self) -> None:
|
def effect(self) -> None:
|
||||||
images = self.svg.selection.get(IImage)
|
images = self.svg.selection.get(IImage)
|
||||||
|
pilimages = list()
|
||||||
for elem in images:
|
for elem in images:
|
||||||
xlink = elem.get("xlink:href")
|
xlink = elem.get("xlink:href")
|
||||||
if xlink is not None and xlink[:5] == "data:":
|
if xlink is not None and xlink[:5] == "data:":
|
||||||
|
@ -221,15 +222,30 @@ class CoordinatesExtension(inkex.EffectExtension):
|
||||||
else:
|
else:
|
||||||
imgdata = base64.b64decode(data)
|
imgdata = base64.b64decode(data)
|
||||||
pilimage = Image.open(io.BytesIO(imgdata))
|
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.message_box("Could not find image in selection")
|
||||||
self.window.show_all()
|
self.window.show_all()
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
else:
|
else:
|
||||||
self.window.add_image(pilimage, mimetype)
|
breakout = False
|
||||||
self.window.show_all()
|
for pilimage in pilimages:
|
||||||
Gtk.main()
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue