Skip to content
Permalink
Browse files

[sextante] improvements in batch processing interface

  • Loading branch information
volaya committed Jun 6, 2013
1 parent 17ca300 commit 0d1d1b795c1138e4ee738ce57bafd87f975c13a1
@@ -31,7 +31,6 @@
from sextante.core.SextanteUtils import SextanteUtils
from sextante.tools.vector import getfeatures
from sextante.gui.SextantePostprocessing import SextantePostprocessing
import sextante
import sys

class AlgorithmExecutor(QThread):
@@ -52,26 +52,26 @@ def __init__(self, param, row, col, batchDialog, parent = None):

def showSelectionDialog(self):
settings = QtCore.QSettings()
text = str(self.text.text())
text = unicode(self.text.text())
if os.path.isdir(text):
path = text
elif os.path.isdir(os.path.dirname(text)):
path = os.path.dirname(text)
elif settings.contains("/SextanteQGIS/LastInputPath"):
path = str(settings.value( "/SextanteQGIS/LastInputPath",QtCore.QVariant("")).toString())
path = unicode(settings.value( "/SextanteQGIS/LastInputPath",QtCore.QVariant("")).toString())
else:
path = ""

ret = QtGui.QFileDialog.getOpenFileNames(self, "Open file", path, self.param.getFileFilter())
if ret:
files = list(ret)
if len(files) == 1:
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(str(files[0])))
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(unicode(files[0])))
self.text.setText(str(files[0]))
else:
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(str(files[0])))
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(unicode(files[0])))
if isinstance(self.param, ParameterMultipleInput):
self.text.setText(";".join(str(f) for f in files))
self.text.setText(";".join(unicode(f) for f in files))
else:
rowdif = len(files) - (self.table.rowCount() - self.row)
for i in range(rowdif):
@@ -62,7 +62,7 @@ def showSelectionDialog(self):
filefilter = self.output.getFileFilter(self.alg)
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", QtCore.QString(), filefilter)
if filename:
filename = str(filename)
filename = unicode(filename)
dlg = AutofillDialog(self.alg)
dlg.exec_()
if dlg.mode != None:
@@ -81,7 +81,7 @@ def showSelectionDialog(self):
widget = self.table.cellWidget(i+self.row, dlg.param)
param = self.alg.parameters[dlg.param]
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable, ParameterMultipleInput)):
s = str(widget.getText())
s = unicode(widget.getText())
s = os.path.basename(s)
s= s[:s.rfind(".")]
elif isinstance(param, ParameterBoolean):
@@ -91,7 +91,7 @@ def showSelectionDialog(self):
elif isinstance(param, ParameterFixedTable):
s = str(widget.table)
else:
s = str(widget.text())
s = unicode(widget.text())
name = filename[:filename.rfind(".")] + s + filename[filename.rfind("."):]
self.table.cellWidget(i + self.row, self.col).setValue(name)
except:
@@ -100,5 +100,5 @@ def setValue(self, text):
return self.text.setText(text)

def getValue(self):
return str(self.text.text())
return unicode(self.text.text())

@@ -154,8 +154,7 @@ def accept(self):
continue
widget = self.table.cellWidget(row, col)
if not self.setParameterValueFromWidget(param, widget, alg):
self.progressLabel.setText("<b>Missing parameter value: " + param.description + " (row " + str(row + 1) + ")</b>")
#QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.progressLabel.setText("<b>Missing parameter value: " + param.description + " (row " + str(row + 1) + ")</b>")
self.algs = None
return
col+=1
@@ -168,8 +167,7 @@ def accept(self):
out.value = text
col+=1
else:
self.progressLabel.setText("<b>Wrong or missing parameter value: " + out.description + " (row " + str(row + 1) + ")</b>")
#QMessageBox.critical(self, "Unable to execute batch process", "Wrong or missing parameter values")
self.progressLabel.setText("<b>Wrong or missing parameter value: " + out.description + " (row " + str(row + 1) + ")</b>")
self.algs = None
return
self.algs.append(alg)
@@ -179,15 +177,14 @@ def accept(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.table.setEnabled(False)
if SextanteConfig.getSetting(SextanteConfig.USE_THREADS):
self.tabWidget.setCurrentIndex(1)
self.nextAlg(0)
else:
i=0
self.progress.setMaximum(len(self.algs))
for alg in self.algs:
self.setBaseText("Processing algorithm " + str(i+1) + "/" + str(len(self.algs)) + "...")
if UnthreadedAlgorithmExecutor.runalg(alg, self):
#self.progress.setValue(i)
#self.loadHTMLResults(alg, i)
if self.load[i]:
SextantePostprocessing.handleAlgorithmResults(alg, self, False)
i+=1
@@ -209,15 +206,13 @@ def cancel(self):
if self.algEx:
self.algEx.terminate()
self.table.setEnabled(True)
#self.close()

@pyqtSlot()
def finish(self, i):
if not self.stop:
if self.load[i]:
SextantePostprocessing.handleAlgorithmResults(self.algs[i], self, False)
i += 1
#self.progress.setValue(i)
if len(self.algs) == i:
self.finishAll()
self.algEx = None
@@ -232,17 +227,21 @@ def error(self, msg):
if self.algEx:
self.algEx.terminate()
self.table.setEnabled(True)
#self.close()


def nextAlg(self, i):
self.stop = False
self.setBaseText("Processing algorithm " + str(i) + "/" + str(len(self.algs)) + "...")
self.setBaseText("Processing algorithm " + str(i + 1) + "/" + str(len(self.algs)) + "...")
self.algEx = AlgorithmExecutor(self.algs[i]);
self.algEx.percentageChanged.connect(self.setPercentage)
self.algEx.textChanged.connect(self.setText)
self.algEx.error.connect(self.error)
self.algEx.finished.connect(lambda: self.finish(i))
self.algEx.infoSet.connect(self.setInfo)
if SextanteConfig.getSetting(SextanteConfig.SHOW_DEBUG_IN_DIALOG):
self.algEx.commandSet.connect(self.setCommand)
self.algEx.debugInfoSet.connect(self.setDebugInfo)
self.algEx.consoleInfoSet.connect(self.setConsoleInfo)
self.algEx.start()

def createSummaryTable(self):
@@ -273,7 +272,6 @@ def finishAll(self):
QApplication.restoreOverrideCursor()
self.table.setEnabled(True)
QMessageBox.information(self, "Batch processing", "Batch processing successfully completed!")
#self.close()

def setParameterValueFromWidget(self, param, widget, alg = None):
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable, ParameterMultipleInput)):

0 comments on commit 0d1d1b7

Please sign in to comment.
You can’t perform that action at this time.