3 changes: 1 addition & 2 deletions python/plugins/sextante/admintools/PostGISExecuteSQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
PostGISExecuteSQL.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Victor Olaya, Carterix Geomatics
Copyright : (C) 2012 by Victor Olaya and Carterix Geomatics
Email : volayaf at gmail dot com
***************************************************************************
* *
Expand All @@ -31,7 +31,6 @@
from sextante.parameters.ParameterString import ParameterString
from sextante.admintools import postgis_utils
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
import PyQt4

class PostGISExecuteSQL(GeoAlgorithm):

Expand Down
3 changes: 1 addition & 2 deletions python/plugins/sextante/algs/SextanteAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
* *
***************************************************************************
"""
from sextante.algs.EquivalentNumField import EquivalentNumField

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from sextante.algs.EquivalentNumField import EquivalentNumField
from sextante.core.AlgorithmProvider import AlgorithmProvider
from sextante.algs.AddTableField import AddTableField
from PyQt4 import QtGui
Expand Down
11 changes: 9 additions & 2 deletions python/plugins/sextante/core/Sextante.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def runAlgorithm(algOrName, onFinish, *args):
return
if len(args) != alg.getVisibleParametersCount() + alg.getVisibleOutputsCount():
print ("Error: Wrong number of parameters")
Sextante.alghelp(algOrName)
alghelp(algOrName)
return

alg = alg.getCopy()#copy.deepcopy(alg)
Expand Down Expand Up @@ -294,7 +294,14 @@ def runAlgorithm(algOrName, onFinish, *args):

SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, alg.getAsCommand())

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
# don't set the wait cursor twice, because then when you restore it
# it will still be a wait cursor
cursor = QApplication.overrideCursor()
if cursor == None or cursor == 0:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
elif cursor.shape() != Qt.WaitCursor:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

if SextanteConfig.getSetting(SextanteConfig.USE_THREADS):
algEx = AlgorithmExecutor(alg)
progress = QProgressDialog()
Expand Down
9 changes: 4 additions & 5 deletions python/plugins/sextante/core/SextanteUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import os
import time
import sys

import uuid
from PyQt4.QtCore import *

from qgis.core import *

class SextanteUtils:
Expand Down Expand Up @@ -64,9 +63,9 @@ def setTempOutput(out, alg):
ext = out.getDefaultFileExtension(alg)
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeCmdName = ''.join(c for c in alg.commandLineName() if c in validChars)
filename = SextanteUtils.tempFolder() + os.sep + safeCmdName + str(SextanteUtils.NUM_EXPORTED) + "." + ext
out.value = filename
SextanteUtils.NUM_EXPORTED += 1
uniqueSufix = str(uuid.uuid4()).replace("-","");
filename = SextanteUtils.tempFolder() + os.sep + safeCmdName + uniqueSufix + "." + ext
out.value = filename

@staticmethod
def getTempFilename(ext):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/grass/GrassUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def startGrassSession():
# End session by removing the temporary GRASS mapset and all the layers.
@staticmethod
def endGrassSession():
#shutil.rmtree(GrassUtils.grassMapsetFolder(), True)
shutil.rmtree(GrassUtils.grassMapsetFolder(), True)
GrassUtils.sessionRunning = False
GrassUtils.sessionLayers = {}

Expand Down
12 changes: 6 additions & 6 deletions python/plugins/sextante/grass/description/r.mapcalculator.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ r.mapcalculator
r.mapcalculator - Calculate new raster map from a r.mapcalc expression.
Raster (r.*)
ParameterRaster|amap|amap|False
ParameterRaster|bmap|bmap|False
ParameterRaster|cmap|cmap|False
ParameterRaster|dmap|dmap|False
ParameterRaster|emap|emap|False
ParameterRaster|fmap|fmap|False
ParameterString|formula|Formula (e.g. A-B or A*C+B|
ParameterRaster|bmap|bmap|True
ParameterRaster|cmap|cmap|True
ParameterRaster|dmap|dmap|True
ParameterRaster|emap|emap|True
ParameterRaster|fmap|fmap|True
ParameterString|formula|Formula (e.g. A-B or A*C+B)|
OutputRaster|outfile|Name for output raster map
6 changes: 3 additions & 3 deletions python/plugins/sextante/grass/description/r.series.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Raster (r.*)
ParameterMultipleInput|input|Name of input raster map(s)|3.0|False
ParameterBoolean|-n|Propagate NULLs|True
ParameterSelection|method|Aggregate operation|average;count;median;mode;minimum;min_raster;maximum;max_raster;stddev;range;sum;threshold;variance;diversity;slope;offset;detcoeff;quart1;quart3;perc90;quantile;skewness;kurtosis
ParameterNumber|quantile|Quantile to calculate for method=quantile|0.0|1.0|0.0
ParameterNumber|threshold|Threshold to calculate for method=threshold|None|None|0.0
ParameterString|range|Ignore values outside this range (lo,hi)|-10000000000,10000000000
*ParameterNumber|quantile|Quantile to calculate for method=quantile|0.0|1.0|0.0
*ParameterNumber|threshold|Threshold to calculate for method=threshold|None|None|0.0
*ParameterString|range|Ignore values outside this range (lo,hi)|-10000000000,10000000000
OutputRaster|output|Name for output raster map
9 changes: 6 additions & 3 deletions python/plugins/sextante/grass/description/r.univar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ r.univar
r.univar - Calculates univariate statistics from the non-null cells of a raster map.
Raster (r.*)
ParameterMultipleInput|map|Name of input raster map(s)|3.0|False
ParameterRaster|zones|Raster map used for zoning, must be of type CELL|False
ParameterNumber|percentile|Percentile to calculate (requires extended statistics flag)|0.0|100.0|90
ParameterBoolean|-e|Calculate extended statistics|False
ParameterRaster|zones|Raster map used for zoning, must be of type CELL|True
*ParameterBoolean|-e|Calculate extended statistics|False
*ParameterBoolean|-g|Print the stats in shell script style|False
*ParameterBoolean|-t|Table output format instead of standard output format|False
*ParameterNumber|percentile|Percentile to calculate (requires extended statistics flag)|0.0|100.0|90
OutputFile|output|Name for output text file
71 changes: 52 additions & 19 deletions python/plugins/sextante/gui/BatchProcessingDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
***************************************************************************
"""
from sextante.gui.CrsSelectionPanel import CrsSelectionPanel
from sextante.outputs.OutputNumber import OutputNumber
from sextante.outputs.OutputString import OutputString
from sextante.core.SextanteUtils import SextanteUtils

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -44,22 +47,19 @@
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
from sextante.gui.FixedTablePanel import FixedTablePanel
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
import copy
from sextante.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor
from sextante.outputs.OutputHTML import OutputHTML
from sextante.core.SextanteResults import SextanteResults
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteConfig import SextanteConfig
from sextante.gui.UnthreadedAlgorithmExecutor import SilentProgress,\
UnthreadedAlgorithmExecutor
from sextante.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor

class BatchProcessingDialog(AlgorithmExecutionDialog):
def __init__(self, alg):
self.algs = None
self.table = QtGui.QTableWidget(None)
AlgorithmExecutionDialog.__init__(self, alg, self.table)
#self.setModal(True)
AlgorithmExecutionDialog.__init__(self, alg, self.table)
self.setWindowModality(1)
self.algEx = None
self.resize(800, 500)
Expand All @@ -79,12 +79,12 @@ def __init__(self, alg):
self.deleteRowButton.setText("Delete row")
self.buttonBox.addButton(self.addRowButton, QtGui.QDialogButtonBox.ActionRole)
self.buttonBox.addButton(self.deleteRowButton, QtGui.QDialogButtonBox.ActionRole)
self.table.setColumnCount(len(self.alg.parameters) + len(self.alg.outputs))

self.table.setColumnCount(self.alg.getVisibleParametersCount() + self.alg.getVisibleOutputsCount())
self.setTableContent()
self.table.horizontalHeader().setStretchLastSection(True)
self.table.verticalHeader().setVisible(False)
self.table.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.progress = QtGui.QProgressBar()
self.table.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.addRowButton.clicked.connect(self.addRow)
self.deleteRowButton.clicked.connect(self.deleteRow)

Expand All @@ -110,13 +110,17 @@ def accept(self):
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
col = 0
for param in alg.parameters:
if param.hidden:
continue
widget = self.table.cellWidget(row, col)
if not self.setParameterValueFromWidget(param, widget, alg):
QMessageBox.critical(self.dialog, "Unable to execute batch process", "Wrong or missing parameter values")
self.algs = None
return
col+=1
for out in alg.outputs:
if out.hidden:
continue
widget = self.table.cellWidget(row, col)
text = widget.getValue()
if text.strip() != "":
Expand All @@ -128,19 +132,18 @@ def accept(self):
return
self.algs.append(alg)

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.progress.setMaximum(len(self.algs))
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.table.setEnabled(False)
if SextanteConfig.getSetting(SextanteConfig.USE_THREADS):
self.progress.setValue(0)
if SextanteConfig.getSetting(SextanteConfig.USE_THREADS):
self.nextAlg(0)
else:
i=1
self.progress.setMaximum(len(self.algs))
for alg in self.algs:
if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
self.progress.setValue(i)
self.loadHTMLResults(alg, i)
self.setBaseText("Processing algorithm " + str(i) + "/" + str(len(self.algs)) + "...")
if UnthreadedAlgorithmExecutor.runalg(alg, self):#SilentProgress()):
#self.progress.setValue(i)
#self.loadHTMLResults(alg, i)
i+=1
else:
QApplication.restoreOverrideCursor()
Expand All @@ -164,31 +167,55 @@ def cancel(self):
@pyqtSlot()
def finish(self, i):
i += 1
self.progress.setValue(i)
self.progress.setValue(i)
if len(self.algs) == i:
self.finishAll()
self.algEx = None
else:
self.nextAlg(i)

@pyqtSlot()
def error(self, msg):
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, "Error", msg)
SextanteLog.addToLog(SextanteLog.LOG_ERROR, msg)
self.close()



def nextAlg(self, i):
self.setBaseText("Processing algorithm " + str(i) + "/" + 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.start()

def createSummaryTable(self):
createTable = False
for out in self.algs[0].outputs:
if isinstance(out, (OutputNumber,OutputString)):
createTable = True
break
if not createTable:
return
outputFile = SextanteUtils.getTempFilename("html")
f = open(outputFile, "w")
for alg in self.algs:
f.write("<hr>\n")
for out in alg.outputs:
if isinstance(out, (OutputNumber,OutputString)):
f.write("<p>" + out.description + ": " + str(out.value) + "</p>\n")
f.write("<hr>\n")
f.close()
SextanteResults.addResult(self.algs[0].name + "[summary]", outputFile)

def finishAll(self):
i = 0
for alg in self.algs:
self.loadHTMLResults(alg, i)
i = i + 1
self.createSummaryTable()
QApplication.restoreOverrideCursor()
self.table.setEnabled(True)
QMessageBox.information(self, "Batch processing", "Batch processing successfully completed!")
Expand Down Expand Up @@ -266,4 +293,10 @@ def showAdvancedParametersClicked(self):
for param in self.alg.parameters:
if param.isAdvanced:
self.table.setColumnHidden(i, not self.showAdvanced)
i+=1
i+=1

def setText(self, text):
self.progressLabel.setText(self.baseText + " --- [" + text + "]")

def setBaseText(self, text):
self.baseText = text
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/FileSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def showSelectionDialog(self):
def getValue(self):
s = str(self.text.text())
if SextanteUtils.isWindows():
s = s.replace("/", "\\")
s = s.replace("\\", "/")
return s
Loading