Skip to content

Commit

Permalink
Handle algorithm errors.
Browse files Browse the repository at this point in the history
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@238 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
cpolymeris@gmail.com committed Jun 11, 2012
1 parent f284e29 commit 377bbf8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/sextante/core/Sextante.py
Expand Up @@ -341,6 +341,11 @@ def runandload(name, *args):
def finish():
SextantePostprocessing.handleAlgorithmResults(alg)
QApplication.restoreOverrideCursor()
def error(msg):
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, "Error", msg)
SextanteLog.addToLog(SextanteLog.LOG_ERROR, msg)
algEx.error.connect(error)
algEx.finished.connect(finish)
algEx.start()

Expand Down
10 changes: 5 additions & 5 deletions src/sextante/gui/AlgorithmExecutor.py
Expand Up @@ -10,7 +10,7 @@
class AlgorithmExecutor(QThread):
percentageChanged = pyqtSignal(int)
textChanged = pyqtSignal(QString)
cancelled = pyqtSignal()
#~ cancelled = pyqtSignal()
error = pyqtSignal()
iterated = pyqtSignal(int)
#started & finished inherited from QThread
Expand Down Expand Up @@ -57,10 +57,10 @@ def runalg(self):
# if self.algorithm.canceled:
# self.canceled.emit()
#===================================================================
except GeoAlgorithmExecutionException, e :
self.error.emit()
except:
self.error.emit()
except GeoAlgorithmExecutionException as e :
self.error.emit(e.msg)
except BaseException as e:
self.error.emit(str(e))

def runalgIterating(self):
outputs = {}
Expand Down
9 changes: 8 additions & 1 deletion src/sextante/gui/BatchProcessingDialog.py
Expand Up @@ -95,7 +95,6 @@ def okPressed(self):
QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.algs = None
return
#~ row+=1 ??? - why?
self.algs.append(alg)

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Expand Down Expand Up @@ -126,8 +125,16 @@ def finish(self, i):
else:
self.nextAlg(i)

@pyqtSlot()
def error(self, msg):
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, "Error", msg)
SextanteLog.addToLog(SextanteLog.LOG_ERROR, msg)
self.close()

def nextAlg(self, i):
self.algEx = AlgorithmExecutor(self.algs[i]);
self.algEx.error.connect(self.error)
self.algEx.finished.connect(lambda: self.finish(i))
self.algEx.start()

Expand Down
23 changes: 13 additions & 10 deletions src/sextante/gui/ParametersDialog.py
Expand Up @@ -181,6 +181,7 @@ def accept(self):
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
self.algEx = AlgorithmExecutor(self.alg)
self.algEx.finished.connect(self.finish)
self.algEx.error.connect(self.error)
self.algEx.percentageChanged.connect(self.setPercentage)
self.algEx.textChanged.connect(self.setText)
self.algEx.start()
Expand All @@ -204,16 +205,18 @@ def finish(self):
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)
SextantePostprocessing.handleAlgorithmResults(self.alg, not keepOpen)

#~ except GeoAlgorithmExecutionException, e :
#~ QApplication.restoreOverrideCursor()
#~ QMessageBox.critical(self, "Error",e.msg)
#~ SextanteLog.addToLog(SextanteLog.LOG_ERROR, e.msg)
#~ if not keepOpen:
#~ self.dialog.close()
#~ else:
#~ self.progressLabel.setText("")
#~ self.progress.setValue(0)
#~ self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
@pyqtSlot()
def error(self, msg):
self.algEx.finished.disconnect()
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, "Error", msg)
SextanteLog.addToLog(SextanteLog.LOG_ERROR, msg)
if not keepOpen:
self.dialog.close()
else:
self.progressLabel.setText("")
self.progress.setValue(0)
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)

@pyqtSlot()
def cancel(self):
Expand Down

0 comments on commit 377bbf8

Please sign in to comment.