From 5e28e9aeeaf2a26e347f5fc092f93a4da09fb6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20G=C3=BCtzkow?= Date: Tue, 18 Feb 2020 22:38:31 +0100 Subject: [PATCH] Fix crash when the file save dialog is cancelled The filename is an empty string when the file save dialog is cancelled, which results in an attempt to open a non-existent file in `ViewerWindow`'s `save()`, `EditorWindow`'s `export()` and `save()`. Since the error isn't caught viscm terminates. This fix checks if the returned string is empty and if it is, no file I/O operation is performed. --- viscm/gui.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/viscm/gui.py b/viscm/gui.py index caaa746..1bd0c86 100644 --- a/viscm/gui.py +++ b/viscm/gui.py @@ -1107,7 +1107,8 @@ def save(self): caption="Save file", directory=self.cmapname + ".png", filter="Image Files (*.png *.jpg *.bmp)") - self.viscm.save_figure(fileName) + if fileName: + self.viscm.save_figure(fileName) class EditorWindow(QtWidgets.QMainWindow): @@ -1296,7 +1297,8 @@ def export(self): caption="Export file", directory=self.viscm_editor.name + ".py", filter=".py (*.py)") - self.viscm_editor.export_py(fileName) + if fileName: + self.viscm_editor.export_py(fileName) def fileQuit(self): self.close() @@ -1309,7 +1311,8 @@ def save(self): caption="Save file", directory=self.viscm_editor.name + ".jscm", filter="JSCM Files (*.jscm)") - self.viscm_editor.save_colormap(fileName) + if fileName: + self.viscm_editor.save_colormap(fileName) def loadviewer(self): newfig = plt.figure()