Skip to content
Permalink
Browse files

[processing] allow to use ParameterPoint in Graphical Modeler

  • Loading branch information
alexbruy committed Feb 23, 2016
1 parent dd68c33 commit 317639f1e064fd713668b6d7d0ca92c2c4e0b1c6
@@ -42,7 +42,18 @@
from processing.modeler.WrongModelException import WrongModelException
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.parameters import getParameterFromString, ParameterRaster, ParameterVector, ParameterTable, ParameterTableField, ParameterBoolean, ParameterString, ParameterNumber, ParameterExtent, ParameterDataObject, ParameterMultipleInput
from processing.core.parameters import (getParameterFromString,
ParameterRaster,
ParameterVector,
ParameterTable,
ParameterTableField,
ParameterBoolean,
ParameterString,
ParameterNumber,
ParameterExtent,
ParameterDataObject,
ParameterMultipleInput,
ParameterPoint)
from processing.tools import dataobjects
from processing.gui.Help2Html import getHtmlFromDescriptionsDict

@@ -29,9 +29,28 @@
import math

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QDialogButtonBox, QMessageBox
from PyQt4.QtGui import (QDialog,
QVBoxLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QComboBox,
QCheckBox,
QDialogButtonBox,
QMessageBox)

from processing.core.parameters import Parameter, ParameterBoolean, ParameterRaster, ParameterTable, ParameterVector, ParameterMultipleInput, ParameterNumber, ParameterString, ParameterTableField, ParameterExtent, ParameterFile
from processing.core.parameters import (Parameter,
ParameterBoolean,
ParameterRaster,
ParameterTable,
ParameterVector,
ParameterMultipleInput,
ParameterNumber,
ParameterString,
ParameterTableField,
ParameterExtent,
ParameterFile,
ParameterPoint)


class ModelerParameterDefinitionDialog(QDialog):
@@ -45,6 +64,7 @@ class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_TABLE_FIELD = 'Table field'
PARAMETER_EXTENT = 'Extent'
PARAMETER_FILE = 'File'
PARAMETER_POINT = 'Point'

# To add
PARAMETER_MULTIPLE = 'Multiple input'
@@ -60,6 +80,7 @@ class ModelerParameterDefinitionDialog(QDialog):
PARAMETER_TABLE,
PARAMETER_TABLE_FIELD,
PARAMETER_VECTOR,
PARAMETER_POINT
]

def __init__(self, alg, paramType=None, param=None):
@@ -188,6 +209,14 @@ def setupUi(self):
1 if self.param.isFolder else 0)
self.horizontalLayout3.addWidget(self.fileFolderCombo)
self.verticalLayout.addLayout(self.horizontalLayout3)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
isinstance(self.param, ParameterPoint):
self.horizontalLayout3.addWidget(QLabel(self.tr('Default value')))
self.defaultTextBox = QLineEdit()
if self.param is not None:
self.defaultTextBox.setText(self.param.default)
self.horizontalLayout3.addWidget(self.defaultTextBox)
self.verticalLayout.addLayout(self.horizontalLayout3)

self.horizontalLayout2.addWidget(QLabel(self.tr('Required')))
self.yesNoCombo = QComboBox()
@@ -292,6 +321,10 @@ def okPressed(self):
isinstance(self.param, ParameterFile):
isFolder = self.fileFolderCombo.currentIndex() == 1
self.param = ParameterFile(name, description, isFolder=isFolder)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_POINT or \
isinstance(self.param, ParameterPoint):
self.param = ParameterPoint(name, description,
unicode(self.defaultTextBox.text()))
self.param.optional = self.yesNoCombo.currentIndex() == 1
self.close()

@@ -26,20 +26,60 @@
__revision__ = '$Format:%H$'

from PyQt4.QtCore import Qt, QUrl, QMetaObject
from PyQt4.QtGui import QDialog, QDialogButtonBox, QLabel, QLineEdit, QFrame, QPushButton, QSizePolicy, QVBoxLayout, QHBoxLayout, QTabWidget, QWidget, QScrollArea, QComboBox, QTableWidgetItem, QMessageBox
from PyQt4.QtGui import (QDialog,
QDialogButtonBox,
QLabel,
QLineEdit,
QFrame,
QPushButton,
QSizePolicy,
QVBoxLayout,
QHBoxLayout,
QTabWidget,
QWidget,
QScrollArea,
QComboBox,
QTableWidgetItem,
QMessageBox)
from PyQt4.QtWebKit import QWebView

from processing.modeler.ModelerAlgorithm import ValueFromInput, \
ValueFromOutput, Algorithm, ModelerOutput
from processing.gui.CrsSelectionPanel import CrsSelectionPanel
from processing.gui.MultipleInputPanel import MultipleInputPanel
from processing.gui.FixedTablePanel import FixedTablePanel
from processing.gui.RangePanel import RangePanel
from processing.gui.GeometryPredicateSelectionPanel import \
GeometryPredicateSelectionPanel
from processing.core.parameters import (ParameterExtent,
ParameterRaster,
ParameterVector,
ParameterBoolean,
ParameterTable,
ParameterFixedTable,
ParameterMultipleInput,
ParameterSelection,
ParameterRange,
ParameterNumber,
ParameterString,
ParameterCrs,
ParameterTableField,
ParameterFile,
ParameterPoint,
ParameterGeometryPredicate)
from processing.core.outputs import (OutputRaster,
OutputVector,
OutputTable,
OutputHTML,
OutputFile,
OutputDirectory,
OutputNumber,
OutputString,
OutputExtent)

from processing.modeler.ModelerAlgorithm import (ValueFromInput,
ValueFromOutput,
Algorithm,
ModelerOutput)
from processing.modeler.MultilineTextPanel import MultilineTextPanel
from processing.core.parameters import ParameterExtent, ParameterRaster, ParameterVector, ParameterBoolean, ParameterTable, ParameterFixedTable, ParameterMultipleInput, ParameterSelection, ParameterRange, ParameterNumber, ParameterString, ParameterCrs, ParameterTableField, ParameterFile, ParameterGeometryPredicate
from processing.core.outputs import OutputRaster, OutputVector, OutputTable, OutputHTML, OutputFile, OutputDirectory, OutputNumber, OutputString, OutputExtent


class ModelerParametersDialog(QDialog):
@@ -109,7 +149,9 @@ def setupUi(self):
continue
desc = param.description
if isinstance(param, ParameterExtent):
desc += '(xmin, xmax, ymin, ymax)'
desc += self.tr('(xmin, xmax, ymin, ymax)')
if isinstance(param, ParameterPoint):
desc += self.tr('(x, y)')
label = QLabel(desc)
self.labels[param.name] = label
widget = self.getWidgetFromParameter(param)
@@ -335,6 +377,13 @@ def getWidgetFromParameter(self, param):
item.addItem(self.resolveValueDescription(ex), ex)
if not self.canUseAutoExtent():
item.setEditText(unicode(param.default))
elif isinstance(param, ParameterPoint):
item = QComboBox()
item.setEditable(True)
points = self.getAvailableValuesOfType(ParameterPoint)
for p in points:
item.addItem(self.resolveValueDescription(p), p)
item.setEditText(unicode(param.default))
elif isinstance(param, ParameterFile):
item = QComboBox()
item.setEditable(True)
@@ -427,7 +476,8 @@ def setPreviousValues(self):
ParameterNumber,
ParameterBoolean,
ParameterExtent,
ParameterFile
ParameterFile,
ParameterPoint
)):
self.setComboBoxValue(widget, value, param)
elif isinstance(param, ParameterString):
@@ -594,6 +644,29 @@ def setParamExtentValue(self, alg, param, widget):
alg.params[param.name] = value
return True

def setParamPointValue(self, alg, param, widget):
idx = widget.findText(widget.currentText())
if idx < 0:
s = unicode(widget.currentText()).strip()
if s:
try:
tokens = s.split(',')
if len(tokens) != 2:
return False
for token in tokens:
float(token)
except:
return False
elif param.optional:
s = None
else:
return False
alg.params[param.name] = [s]
else:
value = widget.itemData(widget.currentIndex())
alg.params[param.name] = value
return True

def setParamValue(self, alg, param, widget):
if isinstance(param, (ParameterRaster, ParameterVector,
ParameterTable)):
@@ -611,6 +684,8 @@ def setParamValue(self, alg, param, widget):
return self.setParamNumberValue(alg, param, widget)
elif isinstance(param, ParameterExtent):
return self.setParamExtentValue(alg, param, widget)
elif isinstance(param, ParameterPoint):
return self.setParamPointValue(alg, param, widget)
elif isinstance(param, ParameterFile):
return self.setParamFileValue(alg, param, widget)
elif isinstance(param, ParameterSelection):

0 comments on commit 317639f

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