Skip to content

Commit

Permalink
[sextante] catch IO error when user tried to save file in system
Browse files Browse the repository at this point in the history
directory (fix #7259)
  • Loading branch information
alexbruy committed Apr 11, 2013
1 parent f8834f2 commit 35c3c3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
20 changes: 13 additions & 7 deletions python/plugins/sextante/r/EditRScriptDialog.py
Expand Up @@ -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 *
Expand Down Expand Up @@ -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()))
Expand All @@ -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']
Expand All @@ -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)"))
Expand All @@ -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:
Expand All @@ -137,4 +143,4 @@ def saveAlgorithm(self):

def cancelPressed(self):
#self.update = False
self.close()
self.close()
17 changes: 13 additions & 4 deletions python/plugins/sextante/script/EditScriptDialog.py
Expand Up @@ -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 *
Expand Down Expand Up @@ -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:
Expand All @@ -112,4 +121,4 @@ def saveAlgorithm(self):

def cancelPressed(self):
#self.update = False
self.close()
self.close()

0 comments on commit 35c3c3c

Please sign in to comment.