2012-02-03 15:03:47 +00:00
|
|
|
from PyQt4 import QtCore
|
|
|
|
from PyQt4.QtGui import *
|
|
|
|
import time
|
2012-02-12 10:57:30 +00:00
|
|
|
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
|
2012-02-03 15:03:47 +00:00
|
|
|
|
|
|
|
class AlgorithmExecutor:
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def runalg(alg, progress):
|
2012-02-12 10:57:30 +00:00
|
|
|
try:
|
|
|
|
alg.execute(progress)
|
|
|
|
except GeoAlgorithmExecutionException, e :
|
|
|
|
QMessageBox.critical(self, "Error",e.msg)
|
|
|
|
finally:
|
|
|
|
progress.setFinished()
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def runbatch(algs, progress):
|
|
|
|
try:
|
|
|
|
for alg in algs:
|
|
|
|
progress.addText(alg.getAsCommand())
|
|
|
|
AlgorithmExecutor.runalg(alg, SilentProgress())
|
|
|
|
progress.addText("Execution OK!")
|
|
|
|
except GeoAlgorithmExecutionException, e :
|
|
|
|
QMessageBox.critical(self, "Error",e.msg)
|
|
|
|
progress.addText("Execution Failed")
|
|
|
|
finally:
|
|
|
|
progress.setFinished()
|
|
|
|
|
|
|
|
|
2012-02-03 15:03:47 +00:00
|
|
|
#=======================================================================
|
|
|
|
# th = RunAlgorithmThread(alg, progress)
|
|
|
|
# th.start()
|
|
|
|
# th.wait()
|
|
|
|
#=======================================================================
|
|
|
|
|
|
|
|
class RunAlgorithmThread(QtCore.QThread):
|
|
|
|
|
|
|
|
def __init__(self, alg, progress):
|
|
|
|
self.alg = alg
|
|
|
|
self.progress = progress
|
|
|
|
QtCore.QThread.__init__(self)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
for i in range(2):
|
|
|
|
time.sleep(3)
|
|
|
|
self.progress.addText(str(i))
|
|
|
|
self.progress.setPercentage(i*50)
|
|
|
|
#self.alg.execute(self.progress)
|
|
|
|
|
|
|
|
class SilentProgress():
|
|
|
|
|
|
|
|
def addText(self, text):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setPercentage(self, i):
|
2012-02-12 10:57:30 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
def setFinished(self):
|
2012-02-03 15:03:47 +00:00
|
|
|
pass
|