Skip to content

Commit

Permalink
Less obtrusive "missing parameter" error message in Algorithm Executi…
Browse files Browse the repository at this point in the history
…on Dialog. c.f #5381

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@342 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
cpolymeris@gmail.com committed Aug 10, 2012
1 parent 12c014e commit 1433a12
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/sextante/gui/AlgorithmExecutionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
_fromUtf8 = lambda s: s

class AlgorithmExecutionDialog(QtGui.QDialog):
class InvalidParameterValue(Exception):
def __init__(self, param, widget):
self.parameter, self.widget = param, widget

'''Base class for dialogs that execute algorithms'''
def __init__(self, alg, mainWidget):
QtGui.QDialog.__init__(self, None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
Expand Down Expand Up @@ -114,15 +118,15 @@ def setParamValues(self):
if isinstance(param, ParameterExtent):
continue
if not self.setParamValue(param, self.paramTable.valueItems[param.name]):
return False
raise AlgorithmExecutionDialog.InvalidParameterValue(param, self.paramTable.valueItems[param.name])

for param in params:
if isinstance(param, ParameterExtent):
value = self.paramTable.valueItems[param.name].getValue()
if value is not None:
param.value = value
else:
return False
raise AlgorithmExecutionDialog.InvalidParameterValue(param, self.paramTable.valueItems[param.name])

for output in outputs:
if output.hidden:
Expand Down Expand Up @@ -168,16 +172,22 @@ def setParamValue(self, param, widget):
return param.setValue(unicode(widget.toPlainText()))
else:
return param.setValue(unicode(widget.text()))

else:
return param.setValue(unicode(widget.text()))

@pyqtSlot()
def accept(self):
if self.setParamValues():
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
useThread = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
try:
self.setParamValues()
msg = self.alg.checkParameterValuesBeforeExecuting()
if msg:
QMessageBox.critical(self, "Unable to execute algorithm", msg)
if keepOpen or useThread:
self.setInfo("Unable to execute algorithm: %s" % msg, True)
self.tabWidget.setCurrentIndex(1) # log tab
else:
QMessageBox.critical(self, "Unable to execute algorithm", msg)
return
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(False)
Expand All @@ -193,7 +203,6 @@ def accept(self):
self.progress.setMaximum(0)
self.progressLabel.setText("Processing algorithm...")
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
useThread = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
if useThread:
if iterateParam:
self.algEx = AlgorithmExecutor(self.alg, iterateParam)
Expand Down Expand Up @@ -227,7 +236,6 @@ def accept(self):
self.finish()
else:
QApplication.restoreOverrideCursor()
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
if not keepOpen:
self.close()
else:
Expand All @@ -238,8 +246,16 @@ def accept(self):
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)
self.tabWidget.setCurrentIndex(1) # log tab
else:
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")
except AlgorithmExecutionDialog.InvalidParameterValue as ex:
try:
self.buttonBox.accepted.connect(lambda: ex.widget.setPalette(QPalette()))
palette = ex.widget.palette()
palette.setColor(QPalette.Base, QColor(255, 255, 0))
ex.widget.setPalette(palette)
self.progressLabel.setText("<b>Missing parameter value</b>")
return
except:
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")

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

0 comments on commit 1433a12

Please sign in to comment.