Skip to content
Permalink
Browse files

[sextante] catch IO error when user tried to save file in system

directory (fix #7259)
  • Loading branch information
alexbruy committed Apr 11, 2013
1 parent f8834f2 commit 35c3c3cd2df2f5d40bc9a2101e97d534b4b6f9b5
Showing with 26 additions and 11 deletions.
  1. +13 −7 python/plugins/sextante/r/EditRScriptDialog.py
  2. +13 −4 python/plugins/sextante/script/EditScriptDialog.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()
self.close()
@@ -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()
self.close()

0 comments on commit 35c3c3c

Please sign in to comment.
You can’t perform that action at this time.