Skip to content

Commit 1433a12

Browse files
author
cpolymeris@gmail.com
committed
Less obtrusive "missing parameter" error message in Algorithm Execution Dialog. c.f #5381
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@342 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent 12c014e commit 1433a12

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/sextante/gui/AlgorithmExecutionDialog.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
_fromUtf8 = lambda s: s
3838

3939
class AlgorithmExecutionDialog(QtGui.QDialog):
40+
class InvalidParameterValue(Exception):
41+
def __init__(self, param, widget):
42+
self.parameter, self.widget = param, widget
43+
4044
'''Base class for dialogs that execute algorithms'''
4145
def __init__(self, alg, mainWidget):
4246
QtGui.QDialog.__init__(self, None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
@@ -114,15 +118,15 @@ def setParamValues(self):
114118
if isinstance(param, ParameterExtent):
115119
continue
116120
if not self.setParamValue(param, self.paramTable.valueItems[param.name]):
117-
return False
121+
raise AlgorithmExecutionDialog.InvalidParameterValue(param, self.paramTable.valueItems[param.name])
118122

119123
for param in params:
120124
if isinstance(param, ParameterExtent):
121125
value = self.paramTable.valueItems[param.name].getValue()
122126
if value is not None:
123127
param.value = value
124128
else:
125-
return False
129+
raise AlgorithmExecutionDialog.InvalidParameterValue(param, self.paramTable.valueItems[param.name])
126130

127131
for output in outputs:
128132
if output.hidden:
@@ -168,16 +172,22 @@ def setParamValue(self, param, widget):
168172
return param.setValue(unicode(widget.toPlainText()))
169173
else:
170174
return param.setValue(unicode(widget.text()))
171-
172175
else:
173176
return param.setValue(unicode(widget.text()))
174-
177+
175178
@pyqtSlot()
176179
def accept(self):
177-
if self.setParamValues():
180+
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
181+
useThread = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
182+
try:
183+
self.setParamValues()
178184
msg = self.alg.checkParameterValuesBeforeExecuting()
179185
if msg:
180-
QMessageBox.critical(self, "Unable to execute algorithm", msg)
186+
if keepOpen or useThread:
187+
self.setInfo("Unable to execute algorithm: %s" % msg, True)
188+
self.tabWidget.setCurrentIndex(1) # log tab
189+
else:
190+
QMessageBox.critical(self, "Unable to execute algorithm", msg)
181191
return
182192
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
183193
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(False)
@@ -193,7 +203,6 @@ def accept(self):
193203
self.progress.setMaximum(0)
194204
self.progressLabel.setText("Processing algorithm...")
195205
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
196-
useThread = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
197206
if useThread:
198207
if iterateParam:
199208
self.algEx = AlgorithmExecutor(self.alg, iterateParam)
@@ -227,7 +236,6 @@ def accept(self):
227236
self.finish()
228237
else:
229238
QApplication.restoreOverrideCursor()
230-
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
231239
if not keepOpen:
232240
self.close()
233241
else:
@@ -238,8 +246,16 @@ def accept(self):
238246
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
239247
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)
240248
self.tabWidget.setCurrentIndex(1) # log tab
241-
else:
242-
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")
249+
except AlgorithmExecutionDialog.InvalidParameterValue as ex:
250+
try:
251+
self.buttonBox.accepted.connect(lambda: ex.widget.setPalette(QPalette()))
252+
palette = ex.widget.palette()
253+
palette.setColor(QPalette.Base, QColor(255, 255, 0))
254+
ex.widget.setPalette(palette)
255+
self.progressLabel.setText("<b>Missing parameter value</b>")
256+
return
257+
except:
258+
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")
243259

244260
@pyqtSlot()
245261
def finish(self):

0 commit comments

Comments
 (0)