74 changes: 14 additions & 60 deletions python/plugins/processing/gui/BatchProcessingDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@
from processing.gui.FixedTablePanel import FixedTablePanel
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.gui.BatchOutputSelectionPanel import BatchOutputSelectionPanel
from processing.gui.AlgorithmExecutor import AlgorithmExecutor
from processing.outputs.OutputHTML import OutputHTML
from processing.core.ProcessingResults import ProcessingResults
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor

class BatchProcessingDialog(AlgorithmExecutionDialog):
Expand Down Expand Up @@ -144,10 +141,11 @@ def setTableContent(self):


def accept(self):
self.canceled = False
self.algs = []
self.load = []
for row in range(self.table.rowCount()):
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
alg = self.alg.getCopy()
col = 0
for param in alg.parameters:
if param.hidden:
Expand Down Expand Up @@ -176,23 +174,18 @@ def accept(self):

QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.table.setEnabled(False)
if ProcessingConfig.getSetting(ProcessingConfig.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):
if self.load[i]:
Postprocessing.handleAlgorithmResults(alg, self, False)
i+=1
else:
QApplication.restoreOverrideCursor()
return
self.tabWidget.setCurrentIndex(1)
self.progress.setMaximum(len(self.algs))
for i, alg in enumerate(self.algs):
self.setBaseText("Processing algorithm " + str(i+1) + "/" + str(len(self.algs)) + "...")
if UnthreadedAlgorithmExecutor.runalg(alg, self) and not self.canceled:
if self.load[i]:
Postprocessing.handleAlgorithmResults(alg, self, False)
else:
QApplication.restoreOverrideCursor()
return

self.finishAll()
self.finishAll()

def loadHTMLResults(self, alg, i):
for out in alg.outputs:
Expand All @@ -202,48 +195,9 @@ def loadHTMLResults(self, alg, i):
ProcessingResults.addResult(out.description + "[" + str(i) + "]", out.value)

def cancel(self):
self.algs = None
if self.algEx:
self.algEx.terminate()
self.table.setEnabled(True)

@pyqtSlot()
def finish(self, i):
if not self.stop:
if self.load[i]:
Postprocessing.handleAlgorithmResults(self.algs[i], self, False)
i += 1
if len(self.algs) == i:
self.finishAll()
self.algEx = None
else:
self.nextAlg(i)

@pyqtSlot(str)
def error(self, msg):
QApplication.restoreOverrideCursor()
QMessageBox.critical(self, "Error", msg)
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, msg)
if self.algEx:
self.algEx.terminate()
self.canceled = True
self.table.setEnabled(True)


def nextAlg(self, i):
self.stop = False
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 ProcessingConfig.getSetting(ProcessingConfig.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):
createTable = False
for out in self.algs[0].outputs:
Expand Down
8 changes: 5 additions & 3 deletions python/plugins/processing/gui/ParametersDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

# -*- coding: latin-1 -*-
from PyQt4 import QtGui
from processing.gui.ParametersPanel import ParametersPanel
from processing.gui.AlgorithmExecutionDialog import AlgorithmExecutionDialog
from PyQt4 import QtCore


class ParametersDialog(AlgorithmExecutionDialog):
Expand All @@ -36,5 +35,8 @@ class ParametersDialog(AlgorithmExecutionDialog):
'''the default parameters dialog, to be used when an algorithm is called from the toolbox'''
def __init__(self, alg):
self.paramTable = ParametersPanel(self, alg)
AlgorithmExecutionDialog.__init__(self, alg, self.paramTable)
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setWidget(self.paramTable)
self.scrollArea.setWidgetResizable(True)
AlgorithmExecutionDialog.__init__(self, alg, self.scrollArea)
self.executed = False
152 changes: 67 additions & 85 deletions python/plugins/processing/gui/ParametersPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,93 +79,75 @@ def __init__(self, parent, alg):

def initGUI(self):
tooltips = self.alg.getParameterDescriptions()
tableLike = ProcessingConfig.getSetting(ProcessingConfig.TABLE_LIKE_PARAM_PANEL)
if tableLike:
self.tableWidget = QtGui.QTableWidget()
self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.tableWidget.setColumnCount(2)
self.tableWidget.setColumnWidth(0,300)
self.tableWidget.setColumnWidth(1,300)
self.tableWidget.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("Parameter"))
self.tableWidget.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("Value"))
self.tableWidget.verticalHeader().setVisible(False)
self.tableWidget.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.setTableContent()
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(0)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.tableWidget)
self.setLayout(self.verticalLayout)
else:
self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(5)
self.verticalLayout.setMargin(20)
for param in self.alg.parameters:
if param.isAdvanced:
self.advancedButton = QtGui.QPushButton()
self.advancedButton.setText("Show advanced parameters")
self.advancedButton.setMaximumWidth(250)
QtCore.QObject.connect(self.advancedButton, QtCore.SIGNAL("clicked()"), self.showAdvancedParametersClicked)
self.verticalLayout.addWidget(self.advancedButton)
break
for param in self.alg.parameters:
if param.hidden:
continue
desc = param.description
if isinstance(param, ParameterExtent):
desc += "(xmin, xmax, ymin, ymax)"
label = QtGui.QLabel(desc)
self.labels[param.name] = label
widget = self.getWidgetFromParameter(param)
self.valueItems[param.name] = widget
if isinstance(param, ParameterVector) and not self.alg.allowOnlyOpenedLayers:
layout = QtGui.QHBoxLayout()
layout.setSpacing(2)
layout.setMargin(0)
layout.addWidget(widget)
button = QtGui.QToolButton()
icon = QtGui.QIcon(os.path.dirname(__file__) + "/../images/iterate.png")
button.setIcon(icon)
button.setToolTip("Iterate over this layer")
button.setCheckable(True)
button.setMaximumWidth(30)
button.setMaximumHeight(30)
layout.addWidget(button)
self.iterateButtons[param.name] = button
QtCore.QObject.connect(button, QtCore.SIGNAL("toggled(bool)"), self.buttonToggled)
widget = QtGui.QWidget()
widget.setLayout(layout)
if param.name in tooltips.keys():
tooltip = tooltips[param.name]
else:
tooltip = param.description
label.setToolTip(tooltip)
widget.setToolTip(tooltip)
if param.isAdvanced:
label.setVisible(self.showAdvanced)
widget.setVisible(self.showAdvanced)
self.widgets[param.name] = widget
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)
self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(5)
self.verticalLayout.setMargin(20)
for param in self.alg.parameters:
if param.isAdvanced:
self.advancedButton = QtGui.QPushButton()
self.advancedButton.setText("Show advanced parameters")
self.advancedButton.setMaximumWidth(250)
QtCore.QObject.connect(self.advancedButton, QtCore.SIGNAL("clicked()"), self.showAdvancedParametersClicked)
self.verticalLayout.addWidget(self.advancedButton)
break
for param in self.alg.parameters:
if param.hidden:
continue
desc = param.description
if isinstance(param, ParameterExtent):
desc += "(xmin, xmax, ymin, ymax)"
label = QtGui.QLabel(desc)
self.labels[param.name] = label
widget = self.getWidgetFromParameter(param)
self.valueItems[param.name] = widget
if isinstance(param, ParameterVector) and not self.alg.allowOnlyOpenedLayers:
layout = QtGui.QHBoxLayout()
layout.setSpacing(2)
layout.setMargin(0)
layout.addWidget(widget)
button = QtGui.QToolButton()
icon = QtGui.QIcon(os.path.dirname(__file__) + "/../images/iterate.png")
button.setIcon(icon)
button.setToolTip("Iterate over this layer")
button.setCheckable(True)
button.setMaximumWidth(30)
button.setMaximumHeight(30)
layout.addWidget(button)
self.iterateButtons[param.name] = button
QtCore.QObject.connect(button, QtCore.SIGNAL("toggled(bool)"), self.buttonToggled)
widget = QtGui.QWidget()
widget.setLayout(layout)
if param.name in tooltips.keys():
tooltip = tooltips[param.name]
else:
tooltip = param.description
label.setToolTip(tooltip)
widget.setToolTip(tooltip)
if param.isAdvanced:
label.setVisible(self.showAdvanced)
widget.setVisible(self.showAdvanced)
self.widgets[param.name] = widget
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)

for output in self.alg.outputs:
if output.hidden:
continue
label = QtGui.QLabel(output.description)
widget = OutputSelectionPanel(output,self.alg)
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)
if isinstance(output, (OutputRaster, OutputVector, OutputTable)):
check = QtGui.QCheckBox()
check.setText("Open output file after running algorithm")
check.setChecked(True)
self.verticalLayout.addWidget(check)
self.checkBoxes[output.name] = check
self.valueItems[output.name] = widget
for output in self.alg.outputs:
if output.hidden:
continue
label = QtGui.QLabel(output.description)
widget = OutputSelectionPanel(output,self.alg)
self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)
if isinstance(output, (OutputRaster, OutputVector, OutputTable)):
check = QtGui.QCheckBox()
check.setText("Open output file after running algorithm")
check.setChecked(True)
self.verticalLayout.addWidget(check)
self.checkBoxes[output.name] = check
self.valueItems[output.name] = widget

self.verticalLayout.addStretch(1000)
self.setLayout(self.verticalLayout)
self.verticalLayout.addStretch(1000)
self.setLayout(self.verticalLayout)

def showAdvancedParametersClicked(self):
self.showAdvanced = not self.showAdvanced
Expand Down
1 change: 0 additions & 1 deletion python/plugins/processing/gui/ProcessingToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def executeAlgorithm(self):
if message:
dlg = MissingDependencyDialog(message)
dlg.exec_()
#QMessageBox.warning(self, self.tr("Warning"), message)
return
alg = alg.getCopy()
dlg = alg.getCustomParametersDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.Postprocessing import Postprocessing
from processing.core.SilentProgress import SilentProgress
import traceback

class UnthreadedAlgorithmExecutor:

Expand Down
12 changes: 8 additions & 4 deletions python/plugins/processing/modeler/ModelerAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -33,6 +34,7 @@
from processing.modeler.WrongModelException import WrongModelException
from processing.modeler.ModelerUtils import ModelerUtils
from processing.parameters.ParameterRaster import ParameterRaster
from processing.parameters.ParameterDataObject import ParameterDataObject
from processing.tools import dataobjects
from processing.parameters.ParameterExtent import ParameterExtent
from PyQt4 import QtCore, QtGui
Expand Down Expand Up @@ -461,12 +463,14 @@ def prepareAlgorithm(self, alg, iAlg):
value = self.getValueFromAlgorithmAndParameter(aap)
layerslist.append(str(value))
value = ";".join(layerslist)
if not param.setValue(value):
raise GeoAlgorithmExecutionException("Wrong value: " + str(value))

#if not param.setValue(value):
#raise GeoAlgorithmExecutionException("Wrong value: " + str(value))

else:
value = self.getValueFromAlgorithmAndParameter(aap)
if not param.setValue(value):
#we allow unexistent filepaths, since that allows algorithms to skip some conversion routines
if not param.setValue(value) and not isinstance(param, ParameterDataObject):
raise GeoAlgorithmExecutionException("Wrong value: " + str(value))
for out in alg.outputs:
val = self.algOutputs[iAlg][out.name]
Expand Down Expand Up @@ -557,7 +561,7 @@ def processAlgorithm(self, progress):
progress.setDebugInfo("Parameters: " +
', '.join([unicode(p).strip() + "=" + unicode(p.value) for p in alg.parameters]))
t0 = time.time()
alg.execute(progress)
alg.execute(progress, self)
dt = time.time() - t0
for out in alg.outputs:
outputs[out.name] = out.value
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/processing/parameters/ParameterRaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
* *
***************************************************************************
"""
import os

__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$'

import os
from processing.parameters.ParameterDataObject import ParameterDataObject
from processing.tools import dataobjects
from qgis.core import *
from processing.tools import dataobjects

class ParameterRaster(ParameterDataObject):

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def gen_test_parameters(self, alg, doSet = False):
yield

def setUp(self):
ProcessingConfig.setSettingValue(ProcessingConfig.USE_THREADS, self.threaded)
#ProcessingConfig.setSettingValue(ProcessingConfig.USE_THREADS, self.threaded)
print
print bcolors.INFO, self.msg, bcolors.ENDC,
print "Parameters: ", self.alg.parameters,
Expand Down