Skip to content

Commit

Permalink
[sextante] improvements in batch processing interface
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Jun 6, 2013
1 parent 17ca300 commit 0d1d1b7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
1 change: 0 additions & 1 deletion python/plugins/sextante/gui/AlgorithmExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions python/plugins/sextante/gui/BatchInputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/sextante/gui/BatchOutputSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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())

20 changes: 9 additions & 11 deletions python/plugins/sextante/gui/BatchProcessingDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)):
Expand Down

0 comments on commit 0d1d1b7

Please sign in to comment.