@@ -245,9 +245,8 @@ def alghelp(name):
245
245
else :
246
246
print "Algorithm not found"
247
247
248
-
249
248
@staticmethod
250
- def runalg (algOrName , * args ):
249
+ def runAlgorithm (algOrName , onFinish , * args ):
251
250
if isinstance (algOrName , GeoAlgorithm ):
252
251
alg = algOrName
253
252
else :
@@ -287,27 +286,50 @@ def runalg(algOrName, *args):
287
286
288
287
msg = alg .checkParameterValuesBeforeExecuting ()
289
288
if msg :
290
- print ("Unable to execute algorithm\n " + msg )
291
- return
292
-
289
+ try :
290
+ QMessageBox .critical (None , "Unable to execute algorithm" , msg )
291
+ return
292
+ except :
293
+ print ("Unable to execute algorithm\n " + msg )
294
+ return
295
+
293
296
SextanteLog .addToLog (SextanteLog .LOG_ALGORITHM , alg .getAsCommand ())
294
297
295
298
QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
296
- if SextanteConfig .getSetting (SextanteConfig .USE_THREADS ):
299
+ if SextanteConfig .getSetting (SextanteConfig .USE_THREADS ) and onFinish :
297
300
algEx = AlgorithmExecutor (alg )
301
+ progress = QProgressDialog ()
302
+ progress .setWindowTitle (alg .name )
303
+ progress .setLabelText ("Executing %s..." % alg .name )
298
304
def finish ():
299
305
QApplication .restoreOverrideCursor ()
306
+ onFinish (alg )
307
+ progress .close ()
300
308
def error (msg ):
301
309
QApplication .restoreOverrideCursor ()
302
310
print msg
303
311
SextanteLog .addToLog (SextanteLog .LOG_ERROR , msg )
312
+ def cancel ():
313
+ try :
314
+ algEx .finished .disconnect ()
315
+ algEx .terminate ()
316
+ QApplication .restoreOverrideCursor ()
317
+ progress .close ()
318
+ except :
319
+ pass
304
320
algEx .error .connect (error )
305
321
algEx .finished .connect (finish )
306
322
algEx .start ()
307
323
algEx .wait ()
308
324
else :
309
325
UnthreadedAlgorithmExecutor .runalg (alg , SilentProgress ())
326
+ if onFinish :
327
+ onFinish (alg )
328
+ return alg
310
329
330
+ @staticmethod
331
+ def runalg (algOrName , * args ):
332
+ alg = Sextante .runAlgorithm (algOrName , None , * args )
311
333
return alg .getOutputValuesAsDictionary ()
312
334
313
335
@@ -329,66 +351,4 @@ def getObject(uri):
329
351
330
352
@staticmethod
331
353
def runandload (name , * args ):
332
- #a quick fix to call algorithms from the history dialog
333
- alg = Sextante .getAlgorithm (name )
334
- if alg == None :
335
- #in theory, this could not happen. Maybe we should show a message box?
336
- QMessageBox .critical (None ,"Error" , "Error: Algorithm not found\n " )
337
- return
338
- if len (args ) != len (alg .parameters ) + alg .getVisibleOutputsCount ():
339
- QMessageBox .critical (None ,"Error" , "Error: Wrong number of parameters" )
340
- Sextante .alghelp (name )
341
- return
342
-
343
- alg = alg .getCopy ()
344
- i = 0
345
- for param in alg .parameters :
346
- if not param .setValue (args [i ]):
347
- QMessageBox .critical (None , "Error" , "Error: Wrong parameter value: " + args [i ])
348
- return
349
- i = i + 1
350
-
351
- for output in alg .outputs :
352
- if not output .hidden :
353
- if not output .setValue (args [i ]):
354
- QMessageBox .critical (None , "Error" , "Error: Wrong output value: " + args [i ])
355
- return
356
- i = i + 1
357
-
358
- msg = alg .checkParameterValuesBeforeExecuting ()
359
- if msg :
360
- QMessageBox .critical (None , "Unable to execute algorithm" , msg )
361
- return
362
- QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
363
- if SextanteConfig .getSetting (SextanteConfig .USE_THREADS ):
364
- algEx = AlgorithmExecutor (alg )
365
- progress = QProgressDialog ()
366
- progress .setWindowTitle (alg .name )
367
- progress .setLabelText ("Executing %s..." % alg .name )
368
- def finish ():
369
- SextantePostprocessing .handleAlgorithmResults (alg )
370
- QApplication .restoreOverrideCursor ()
371
- progress .close ()
372
- def error (msg ):
373
- QApplication .restoreOverrideCursor ()
374
- QMessageBox .critical (None , "Error" , msg )
375
- SextanteLog .addToLog (SextanteLog .LOG_ERROR , msg )
376
- cancel ();
377
- def cancel ():
378
- try :
379
- algEx .finished .disconnect ()
380
- algEx .terminate ()
381
- QApplication .restoreOverrideCursor ()
382
- progress .close ()
383
- except :
384
- pass
385
- algEx .error .connect (error )
386
- algEx .finished .connect (finish )
387
- algEx .textChanged .connect (lambda t : progress .setLabelText (t ))
388
- algEx .percentageChanged .connect (lambda x : progress .setValue (x ))
389
- progress .canceled .connect (cancel )
390
- algEx .start ()
391
- progress .show ()
392
- else :
393
- if UnthreadedAlgorithmExecutor .runalg (alg , SilentProgress ()):
394
- SextantePostprocessing .handleAlgorithmResults (alg )
354
+ Sextante .runAlgorithm (name , SextantePostprocessing .handleAlgorithmResults , * args )
0 commit comments