Skip to content
Permalink
Browse files

Modeler can now have hard-coded layer paths

Added "hidden" property to parameters

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@317 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf
volayaf committed Jul 28, 2012
1 parent e931725 commit b5d83c02a2cd717a8a49aebc0a4e598c583a8d99
@@ -196,6 +196,14 @@ def getVisibleOutputsCount(self):
i+=1
return i;

def getVisibleParametersCount(self):
'''returns the number of non-hidden parameters'''
i = 0;
for param in self.parameters:
if not param.hidden:
i+=1
return i;

def getOutputValuesAsDictionary(self):
d = {}
for out in self.outputs:
@@ -124,7 +124,7 @@ def updateProviders():

@staticmethod
def addAlgListListener(listener):
'''listener should implement a algsListHasChanged() method. whenever the list of algorithms changed,
'''listener should implement a algsListHasChanged() method. Whenever the list of algorithms changes,
that method will be called for all registered listeners'''
Sextante.listeners.append(listener)

@@ -254,9 +254,9 @@ def runAlgorithm(algOrName, onFinish, *args):
if alg == None:
print("Error: Algorithm not found\n")
return
if len(args) != len(alg.parameters) + alg.getVisibleOutputsCount():
if len(args) != alg.getVisibleParametersCount() + alg.getVisibleOutputsCount():
print ("Error: Wrong number of parameters")
Sextante.alghelp(name)
Sextante.alghelp(algOrName)
return

alg = alg.getCopy()#copy.deepcopy(alg)
@@ -272,10 +272,11 @@ def runAlgorithm(algOrName, onFinish, *args):
else:
i = 0
for param in alg.parameters:
if not param.setValue(args[i]):
print ("Error: Wrong parameter value: " + args[i])
return
i = i +1
if not param.hidden:
if not param.setValue(args[i]):
print ("Error: Wrong parameter value: " + args[i])
return
i = i +1

for output in alg.outputs:
if not output.hidden:
@@ -103,6 +103,8 @@ def setParamValues(self):
outputs = self.alg.outputs

for param in params:
if param.hidden:
continue
if not self.setParamValue(param, self.paramTable.valueItems[param.name]):
return False

@@ -1,37 +1,9 @@
#!/usr/bin/env python
# -*- coding: latin-1 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui, QtWebKit
from sextante.core.QGisLayers import QGisLayers
from sextante.gui.SextantePostprocessing import SextantePostprocessing
from sextante.gui.ParametersPanel import ParametersPanel
from sextante.gui.AlgorithmExecutionDialog import AlgorithmExecutionDialog
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.parameters.ParameterTable import ParameterTable
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor
from sextante.core.SextanteLog import SextanteLog
#~ from sextante.gui.SextantePostprocessing import SextantePostprocessing
from sextante.parameters.ParameterRange import ParameterRange
from sextante.parameters.ParameterNumber import ParameterNumber
from PyQt4 import QtCore

from sextante.gui.ParametersPanel import ParametersPanel
from sextante.parameters.ParameterFile import ParameterFile
from sextante.parameters.ParameterCrs import ParameterCrs
from sextante.core.SextanteConfig import SextanteConfig
from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.outputs.OutputHTML import OutputHTML
from sextante.outputs.OutputRaster import OutputRaster
from sextante.outputs.OutputVector import OutputVector
from sextante.outputs.OutputTable import OutputTable
from sextante.core.WrongHelpFileException import WrongHelpFileException
import os
from sextante.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor

try:
_fromUtf8 = QtCore.QString.fromUtf8
@@ -43,6 +15,6 @@ class ParametersDialog(AlgorithmExecutionDialog):
NOT_SELECTED = "[Not selected]"
'''the default parameters dialog, to be used when an algorithm is called from the toolbox'''
def __init__(self, alg):
self.paramTable = ParametersPanel(self, alg)
self.paramTable = ParametersPanel(self, alg)
AlgorithmExecutionDialog.__init__(self, alg, self.paramTable)
self.executed = False
@@ -80,6 +80,8 @@ def initGUI(self):
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)"
@@ -296,7 +298,10 @@ def somethingDependsOnThisParameter(self, parent):
def setTableContent(self):
params = self.alg.parameters
outputs = self.alg.outputs
numParams = len(self.alg.parameters)
numParams = 0
for param in params:
if not param.hidden:
numParams += 1
numOutputs = 0
for output in outputs:
if not output.hidden:
@@ -305,6 +310,8 @@ def setTableContent(self):

i=0
for param in params:
if param.hidden:
continue
item = QtGui.QTableWidgetItem(param.description)
item.setFlags(QtCore.Qt.ItemIsEnabled)
self.tableWidget.setItem(i,0, item)
@@ -268,21 +268,21 @@ def addInput(self):


def fillInputsTree(self):
inputsItem = QtGui.QTreeWidgetItem()
inputsItem.setText(0, "Inputs")
parametersItem = QtGui.QTreeWidgetItem()
parametersItem.setText(0, "Parameters")
for paramType in ModelerParameterDefinitionDialog.paramTypes:
inputItem = QtGui.QTreeWidgetItem()
inputItem.setText(0, paramType)
inputsItem.addChild(inputItem)
self.inputsTree.addTopLevelItem(inputsItem)
inputsItem.setExpanded(True)
paramItem = QtGui.QTreeWidgetItem()
paramItem.setText(0, paramType)
parametersItem.addChild(paramItem)
self.inputsTree.addTopLevelItem(parametersItem)
parametersItem.setExpanded(True)


def addAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = ModelerUtils.getAlgorithm(item.alg.commandLineName())
alg = alg.getCopy()#copy.deepcopy(alg)
alg = alg.getCopy()
dlg = alg.getCustomModelerParametersDialog(self.alg)
if not dlg:
dlg = ModelerParametersDialog(alg, self.alg)
@@ -230,20 +230,23 @@ def getTableFields(self):
def getWidgetFromParameter(self, param):
if isinstance(param, ParameterRaster):
item = QtGui.QComboBox()
item.setEditable(True)
layers = self.getRasterLayers()
if (param.optional):
item.addItem(self.NOT_SELECTED, None)
for layer in layers:
item.addItem(layer.name(), layer)
elif isinstance(param, ParameterVector):
item = QtGui.QComboBox()
item.setEditable(True)
layers = self.getVectorLayers()
if (param.optional):
item.addItem(self.NOT_SELECTED, None)
for layer in layers:
item.addItem(layer.name(), layer)
elif isinstance(param, ParameterTable):
item = QtGui.QComboBox()
item.setEditable(True)
layers = self.getTables()
if (param.optional):
item.addItem(self.NOT_SELECTED, None)
@@ -310,7 +313,10 @@ def getWidgetFromParameter(self, param):
def setTableContent(self):
params = self.alg.parameters
outputs = self.alg.outputs
numParams = len(self.alg.parameters)
numParams = 0
for param in params:
if not param.hidden:
numParams += 1
numOutputs = 0
for output in outputs:
if not output.hidden:
@@ -319,14 +325,15 @@ def setTableContent(self):

i=0
for param in params:
item = QtGui.QTableWidgetItem(param.description)
item.setFlags(QtCore.Qt.ItemIsEnabled)
self.tableWidget.setItem(i,0, item)
item = self.getWidgetFromParameter(param)
self.valueItems[param.name] = item
self.tableWidget.setCellWidget(i,1, item)
self.tableWidget.setRowHeight(i,22)
i+=1
if not param.hidden:
item = QtGui.QTableWidgetItem(param.description)
item.setFlags(QtCore.Qt.ItemIsEnabled)
self.tableWidget.setItem(i,0, item)
item = self.getWidgetFromParameter(param)
self.valueItems[param.name] = item
self.tableWidget.setCellWidget(i,1, item)
self.tableWidget.setRowHeight(i,22)
i+=1

for output in outputs:
if not output.hidden:
@@ -400,6 +407,8 @@ def setParamValues(self):
params = self.alg.parameters
outputs = self.alg.outputs
for param in params:
if param.hidden:
continue
if not self.setParamValue(param, self.valueItems[param.name]):
return False
for output in outputs:
@@ -413,21 +422,21 @@ def setParamValues(self):
return True


def setParamRasterValue(self, param, widget):
if widget.currentIndex() < 0:
return False
value = widget.itemData(widget.currentIndex()).toPyObject()
self.params[param.name] = value
def setParamValueLayerOrTable(self, param, widget):
idx = widget.findText(widget.currentText())
if idx < 0:
name = self.getSafeNameForHarcodedParameter(param)
value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
self.params[param.name] = value
s = str(widget.currentText())
self.values[name] = s
else:
value = widget.itemData(widget.currentIndex()).toPyObject()
self.params[param.name] = value
return True

def setParamVectorValue(self, param, widget):
if widget.currentIndex() < 0:
return False
value = widget.itemData(widget.currentIndex()).toPyObject()
self.params[param.name] = value
return True

def setParamTableValue(self, param, widget):

if widget.currentIndex() < 0:
return False
value = widget.itemData(widget.currentIndex()).toPyObject()
@@ -505,12 +514,8 @@ def setParamNumberValue(self, param, widget):
return True

def setParamValue(self, param, widget):
if isinstance(param, ParameterRaster):
return self.setParamRasterValue(param, widget)
elif isinstance(param, ParameterVector):
return self.setParamVectorValue(param, widget)
elif isinstance(param, ParameterTable):
return self.setParamTableValue(param, widget)
if isinstance(param, (ParameterRaster, ParameterVector, ParameterTable)):
return self.setParamValueLayerOrTable(param, widget)
elif isinstance(param, ParameterBoolean):
return self.setParamBooleanValue(param, widget)
elif isinstance(param, ParameterString):
@@ -539,13 +544,6 @@ def setParamValue(self, param, widget):
return True
if isinstance(param, ParameterTableField):
return self.setParamTableFieldValue(param, widget)
#===================================================================
# name = self.getSafeNameForHarcodedParameter(param)
# value = AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, name)
# self.params[param.name] = value
# self.values[name] = str(widget.text())
# return True
#===================================================================
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = self.getVectorLayers()
@@ -6,9 +6,12 @@ def __init__(self, name="", description=""):
self.description = description
self.value = None

#this is not used yet
self.isAdvanced = False

#a hidden parameter can be used to set a hard-coded value.
#It can be used as any other parameter, but it will not be shown to the user
self.hidden = False


def setValue(self, obj):
'''sets the value of the parameter.

0 comments on commit b5d83c0

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