From e30628f28d4a3c3f6768ab417cfcaa14be8f07b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Wed, 11 Sep 2019 13:53:48 +0200 Subject: [PATCH] libroar/RoarCanvasCommandsFile.py:_import(): handle FileNotFoundError exception. --- libroar/RoarCanvasCommandsFile.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libroar/RoarCanvasCommandsFile.py b/libroar/RoarCanvasCommandsFile.py index 0be4b59..1fad2e1 100644 --- a/libroar/RoarCanvasCommandsFile.py +++ b/libroar/RoarCanvasCommandsFile.py @@ -22,16 +22,20 @@ import io, os, wx class RoarCanvasCommandsFile(): # {{{ _import(self, f, newDirty, pathName) def _import(self, f, newDirty, pathName): + rc = False self.parentCanvas.SetCursor(wx.Cursor(wx.CURSOR_WAIT)) - rc, error, newMap, newPathName, newSize = f(pathName) - if rc: - self.parentCanvas.dirty = newDirty - self.parentCanvas.update(newSize, False, newMap) - self.canvasPathName = newPathName - self.update(dirty=self.parentCanvas.dirty, pathName=self.canvasPathName, undoLevel=-1) - self.parentCanvas.canvas.journal.resetCursor() - self.parentCanvas.canvas.journal.resetUndo() - else: + try: + rc, error, newMap, newPathName, newSize = f(pathName) + if rc: + self.parentCanvas.dirty = newDirty + self.parentCanvas.update(newSize, False, newMap) + self.canvasPathName = newPathName + self.update(dirty=self.parentCanvas.dirty, pathName=self.canvasPathName, undoLevel=-1) + self.parentCanvas.canvas.journal.resetCursor() + self.parentCanvas.canvas.journal.resetUndo() + except FileNotFoundError as e: + rc, error, newMap, newPathName, newSize = False, str(e), None, None, None + if not rc: with wx.MessageDialog(self.parentCanvas, "Error: {}".format(error), "", wx.OK | wx.OK_DEFAULT) as dialog: dialogChoice = dialog.ShowModal() self.parentCanvas.SetCursor(wx.Cursor(wx.NullCursor))