37
37
_fromUtf8 = lambda s : s
38
38
39
39
class AlgorithmExecutionDialog (QtGui .QDialog ):
40
+ class InvalidParameterValue (Exception ):
41
+ def __init__ (self , param , widget ):
42
+ self .parameter , self .widget = param , widget
43
+
40
44
'''Base class for dialogs that execute algorithms'''
41
45
def __init__ (self , alg , mainWidget ):
42
46
QtGui .QDialog .__init__ (self , None , QtCore .Qt .WindowSystemMenuHint | QtCore .Qt .WindowTitleHint )
@@ -114,15 +118,15 @@ def setParamValues(self):
114
118
if isinstance (param , ParameterExtent ):
115
119
continue
116
120
if not self .setParamValue (param , self .paramTable .valueItems [param .name ]):
117
- return False
121
+ raise AlgorithmExecutionDialog . InvalidParameterValue ( param , self . paramTable . valueItems [ param . name ])
118
122
119
123
for param in params :
120
124
if isinstance (param , ParameterExtent ):
121
125
value = self .paramTable .valueItems [param .name ].getValue ()
122
126
if value is not None :
123
127
param .value = value
124
128
else :
125
- return False
129
+ raise AlgorithmExecutionDialog . InvalidParameterValue ( param , self . paramTable . valueItems [ param . name ])
126
130
127
131
for output in outputs :
128
132
if output .hidden :
@@ -168,16 +172,22 @@ def setParamValue(self, param, widget):
168
172
return param .setValue (unicode (widget .toPlainText ()))
169
173
else :
170
174
return param .setValue (unicode (widget .text ()))
171
-
172
175
else :
173
176
return param .setValue (unicode (widget .text ()))
174
-
177
+
175
178
@pyqtSlot ()
176
179
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 ()
178
184
msg = self .alg .checkParameterValuesBeforeExecuting ()
179
185
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 )
181
191
return
182
192
self .buttonBox .button (QtGui .QDialogButtonBox .Ok ).setEnabled (False )
183
193
self .buttonBox .button (QtGui .QDialogButtonBox .Close ).setEnabled (False )
@@ -193,7 +203,6 @@ def accept(self):
193
203
self .progress .setMaximum (0 )
194
204
self .progressLabel .setText ("Processing algorithm..." )
195
205
QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
196
- useThread = SextanteConfig .getSetting (SextanteConfig .USE_THREADS )
197
206
if useThread :
198
207
if iterateParam :
199
208
self .algEx = AlgorithmExecutor (self .alg , iterateParam )
@@ -227,7 +236,6 @@ def accept(self):
227
236
self .finish ()
228
237
else :
229
238
QApplication .restoreOverrideCursor ()
230
- keepOpen = SextanteConfig .getSetting (SextanteConfig .KEEP_DIALOG_OPEN )
231
239
if not keepOpen :
232
240
self .close ()
233
241
else :
@@ -238,8 +246,16 @@ def accept(self):
238
246
self .buttonBox .button (QtGui .QDialogButtonBox .Close ).setEnabled (True )
239
247
self .buttonBox .button (QtGui .QDialogButtonBox .Cancel ).setEnabled (False )
240
248
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" )
243
259
244
260
@pyqtSlot ()
245
261
def finish (self ):
0 commit comments