From 35c3c3cd2df2f5d40bc9a2101e97d534b4b6f9b5 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 11 Apr 2013 15:50:53 +0400 Subject: [PATCH] [sextante] catch IO error when user tried to save file in system directory (fix #7259) --- .../plugins/sextante/r/EditRScriptDialog.py | 20 ++++++++++++------- .../sextante/script/EditScriptDialog.py | 17 ++++++++++++---- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/python/plugins/sextante/r/EditRScriptDialog.py b/python/plugins/sextante/r/EditRScriptDialog.py index 1ef1bbdfdaec..928342b14415 100644 --- a/python/plugins/sextante/r/EditRScriptDialog.py +++ b/python/plugins/sextante/r/EditRScriptDialog.py @@ -26,6 +26,8 @@ # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' +import sys + from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -79,7 +81,6 @@ def setupUi(self): self.setLayout(layout) QtCore.QMetaObject.connectSlotsByName(self) - def editHelp(self): if self.alg is None: alg = RAlgorithm(None, unicode(self.text.toPlainText())) @@ -92,7 +93,6 @@ def editHelp(self): if self.alg is None and dlg.descriptions: self.help = dlg.descriptions - def runAlgorithm(self): alg = RAlgorithm(None, unicode(self.text.toPlainText())) alg.provider = Providers.providers['r'] @@ -110,7 +110,6 @@ def runAlgorithm(self): pass canvas.setMapTool(prevMapTool) - def saveAlgorithm(self): if self.filename is None: self.filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save Script", RUtils.RScriptsFolder(), "SEXTANTE R script (*.rsx)")) @@ -121,9 +120,16 @@ def saveAlgorithm(self): text = str(self.text.toPlainText()) if self.alg is not None: self.alg.script = text - fout = open(self.filename, "w") - fout.write(text) - fout.close() + try: + fout = open(self.filename, "w") + fout.write(text) + fout.close() + except IOError: + QMessageBox.warning(self, + self.tr("I/O error"), + self.tr("Unable to save edits. Reason:\n %1").arg(unicode(sys.exc_info()[1])) + ) + return self.update = True #if help strings were defined before saving the model for the first time, we do it here if self.help: @@ -137,4 +143,4 @@ def saveAlgorithm(self): def cancelPressed(self): #self.update = False - self.close() \ No newline at end of file + self.close() diff --git a/python/plugins/sextante/script/EditScriptDialog.py b/python/plugins/sextante/script/EditScriptDialog.py index 7cf5c8e5ef4b..f123ad0a402b 100644 --- a/python/plugins/sextante/script/EditScriptDialog.py +++ b/python/plugins/sextante/script/EditScriptDialog.py @@ -23,6 +23,8 @@ # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' +import sys + from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -96,9 +98,16 @@ def saveAlgorithm(self): text = str(self.text.toPlainText()) if self.alg is not None: self.alg.script = text - fout = open(self.filename, "w") - fout.write(text) - fout.close() + try: + fout = open(self.filename, "w") + fout.write(text) + fout.close() + except: + QMessageBox.warning(self, + self.tr("I/O error"), + self.tr("Unable to save edits. Reason:\n %1").arg(unicode(sys.exc_info()[1])) + ) + return self.update = True #if help strings were defined before saving the model for the first time, we do it here if self.help: @@ -112,4 +121,4 @@ def saveAlgorithm(self): def cancelPressed(self): #self.update = False - self.close() \ No newline at end of file + self.close()