Skip to content

Commit

Permalink
Some formatting in parameters dialog log. Plus "debug" info for model…
Browse files Browse the repository at this point in the history
…er algorithms.

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@336 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
cpolymeris@gmail.com committed Aug 6, 2012
1 parent cb99d37 commit 083f3e4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/sextante/gui/AlgorithmExecutionDialog.py
Expand Up @@ -206,8 +206,10 @@ def accept(self):
self.algEx.textChanged.connect(self.setText)
self.algEx.iterated.connect(self.iterate)
self.algEx.infoSet.connect(self.setInfo)
self.algEx.commandSet.connect(self.setCommand)
self.algEx.debugInfoSet.connect(self.setDebugInfo)
self.algEx.start()
self.setInfo("Algorithm %s started" % self.alg.name)
self.setInfo("<b>Algorithm %s started</b>" % self.alg.name)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True)
self.tabWidget.setCurrentIndex(1) # log tab
else:
Expand Down Expand Up @@ -268,11 +270,11 @@ def error(self, msg):

@pyqtSlot(int)
def iterate(self, i):
self.setInfo("Algorithm %s iteration #%i completed" % (self.alg.name, i))
self.setInfo("<b>Algorithm %s iteration #%i completed</b>" % (self.alg.name, i))

@pyqtSlot()
def cancel(self):
self.setInfo("Algorithm %s canceled" % self.alg.name)
self.setInfo("<b>Algorithm %s canceled</b>" % self.alg.name)
try:
self.algEx.finished.disconnect()
self.algEx.terminate()
Expand All @@ -284,14 +286,23 @@ def cancel(self):
pass

@pyqtSlot(str)
@pyqtSlot(str, bool)
def setInfo(self, msg, error = False):
if error:
#SextanteLog.addToLog(SextanteLog.LOG_ERROR, msg)
self.logText.append('<b>' + msg + '</b>')
self.logText.append('<span style="color:red">' + msg + '</span>')
else:
#SextanteLog.addToLog(SextanteLog.LOG_INFO, msg)
self.logText.append(msg)

@pyqtSlot(str)
def setCommand(self, cmd):
self.setInfo('<tt>' + cmd + '<tt>')

@pyqtSlot(str)
def setDebugInfo(self, msg):
self.setInfo('<span style="color:blue">' + msg + '</span>')

def setPercentage(self, i):
if self.progress.maximum() == 0:
self.progress.setMaximum(100)
Expand Down
6 changes: 6 additions & 0 deletions src/sextante/gui/AlgorithmExecutor.py
Expand Up @@ -12,6 +12,8 @@ class AlgorithmExecutor(QThread):
error = pyqtSignal(str)
iterated = pyqtSignal(int)
infoSet = pyqtSignal(str)
commandSet = pyqtSignal(str)
debugInfoSet = pyqtSignal(str)
#started & finished inherited from QThread

def __init__(self, alg, iterParam = None, parent = None):
Expand All @@ -28,6 +30,10 @@ def setPercentage(self, p):
self.algorithmExecutor.percentageChanged.emit(p)
def setInfo(self, info):
self.algorithmExecutor.infoSet.emit(info)
def setCommand(self, cmd):
self.algorithmExecutor.commandSet.emit(cmd)
def setDebugInfo(self, info):
self.algorithmExecutor.debugInfoSet.emit(info)
self.progress = Progress(self)
if self.parameterToIterate:
self.run = self.runalgIterating
Expand Down
6 changes: 6 additions & 0 deletions src/sextante/gui/UnthreadedAlgorithmExecutor.py
Expand Up @@ -77,3 +77,9 @@ def setPercentage(self, i):

def setInfo(self, _):
pass

def setCommand(self, _):
pass

def setDebugInfo(self, _):
pass
8 changes: 7 additions & 1 deletion src/sextante/modeler/ModelerAlgorithm.py
Expand Up @@ -370,6 +370,7 @@ def processAlgorithm(self, progress):
if canExecute:
try:
alg = alg.getCopy()
progress.setDebugInfo("Prepare algorithm %i: %s" % (iAlg, alg.name))
self.prepareAlgorithm(alg, iAlg)
progress.setText("Running " + alg.name + " [" + str(iAlg+1) + "/"
+ str(len(self.algs) - len(self.deactivated)) +"]")
Expand All @@ -379,9 +380,14 @@ def processAlgorithm(self, progress):
outputs[out.name] = out.value
self.producedOutputs[iAlg] = outputs
executed.append(iAlg)
progress.setDebugInfo("OK. %i outputs" % len(outputs))
except GeoAlgorithmExecutionException, e :
progress.setDebugInfo("Failed")
raise GeoAlgorithmExecutionException("Error executing algorithm " + str(iAlg) + "\n" + e.msg)
else:
progress.setDebugInfo("Algorithm %s deactivated (or already executed)" % alg.name)
iAlg += 1
progress.setDebugInfo("Model processed ok. Executed %i algorithms total" % iAlg)

def getOutputType(self, i, outname):
for out in self.algs[i].outputs:
Expand Down Expand Up @@ -509,4 +515,4 @@ def name(self):
return self.paramName

def __str__(self):
return str(self.alg) + "|" + str(self.param)
return str(self.alg) + "|" + str(self.param)
7 changes: 4 additions & 3 deletions src/sextante/otb/OTBAlgorithm.py
Expand Up @@ -142,7 +142,7 @@ def processAlgorithm(self, progress):
"-sizex", str(sizeX),
"-sizey", str(sizeY)]
SextanteLog.addToLog(SextanteLog.LOG_INFO, helperCommands)
progress.setInfo(helperCommands)
progress.setCommand(helperCommands)
OTBUtils.executeOtb(helperCommands, progress)

if self.roiRasters:
Expand All @@ -155,13 +155,14 @@ def processAlgorithm(self, progress):
"-io.out", roiFile,
"-elev.dem.path", OTBUtils.otbSRTMPath()]
SextanteLog.addToLog(SextanteLog.LOG_INFO, helperCommands)
progress.setCommand(helperCommands)
OTBUtils.executeOtb(helperCommands, progress)

loglines = []
loglines.append("OTB execution command")
for line in commands:
loglines.append(line)

SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
progress.setCommand(loglines)
OTBUtils.executeOtb(commands, progress)


2 changes: 1 addition & 1 deletion src/sextante/saga/SagaAlgorithm.py
Expand Up @@ -278,7 +278,7 @@ def processAlgorithm(self, progress):
loglines = []
loglines.append("SAGA execution commands")
for line in commands:
progress.setInfo(line)
progress.setCommand(line)
loglines.append(line)
if SextanteConfig.getSetting(SagaUtils.SAGA_LOG_COMMANDS):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
Expand Down

0 comments on commit 083f3e4

Please sign in to comment.