Skip to content
Permalink
Browse files

[processing] indentation update

  • Loading branch information
alexbruy authored and volaya committed Dec 1, 2016
1 parent f002321 commit 50a785bdd63d4e8ab3238a91e109e51c31d32eda
@@ -86,7 +86,6 @@ def setValue(self, value):
return False
return False


self.addParameter(ParameterFieldsMapping(self.FIELDS_MAPPING,
self.tr('Fields mapping'),
self.INPUT_LAYER))
@@ -39,6 +39,7 @@
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.algs.qgis.ui.RasterCalculatorWidgets import LayersListWidgetWrapper, ExpressionWidgetWrapper


class RasterCalculator(GeoAlgorithm):

LAYERS = 'LAYERS'
@@ -52,11 +53,13 @@ def defineCharacteristics(self):
self.group, self.i18n_group = self.trAlgorithm('Raster')

self.addParameter(ParameterMultipleInput(self.LAYERS,
self.tr('Input layers'),
datatype=dataobjects.TYPE_RASTER,
optional=True,
metadata={'widget_wrapper': LayersListWidgetWrapper}))
self.tr('Input layers'),
datatype=dataobjects.TYPE_RASTER,
optional=True,
metadata={'widget_wrapper': LayersListWidgetWrapper}))

class ParameterRasterCalculatorExpression(ParameterString):

def evaluateForModeler(self, value, model):
# print value
for i in list(model.inputs.values()):
@@ -76,8 +79,8 @@ def evaluateForModeler(self, value, model):
return value

self.addParameter(ParameterRasterCalculatorExpression(self.EXPRESSION, self.tr('Expression'),
multiline=True,
metadata={'widget_wrapper': ExpressionWidgetWrapper}))
multiline=True,
metadata={'widget_wrapper': ExpressionWidgetWrapper}))
self.addParameter(ParameterNumber(self.CELLSIZE,
self.tr('Cellsize (use 0 or empty to set it automatically)'),
minValue=0.0, default=0.0, optional=True))
@@ -86,7 +89,6 @@ def evaluateForModeler(self, value, model):
optional=True))
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Output')))


def processAlgorithm(self, progress):
expression = self.getParameterValue(self.EXPRESSION)
layersValue = self.getParameterValue(self.LAYERS)
@@ -123,19 +125,20 @@ def processAlgorithm(self, progress):
bbox.combineExtentWith(lyr.extent())
else:
raise GeoAlgorithmExecutionException(self.tr("No layers selected"))

def _cellsize(layer):
return (layer.extent().xMaximum() - layer.extent().xMinimum()) / layer.width()
cellsize = self.getParameterValue(self.CELLSIZE) or min([_cellsize(lyr) for lyr in layersDict.values()])
width = math.floor((bbox.xMaximum() - bbox.xMinimum()) / cellsize)
height = math.floor((bbox.yMaximum() - bbox.yMinimum()) / cellsize)
driverName = GdalUtils.getFormatShortNameFromFilename(output)
calc = QgsRasterCalculator(expression,
output,
driverName,
bbox,
width,
height,
entries)
output,
driverName,
bbox,
width,
height,
entries)

res = calc.processCalculation()
if res == QgsRasterCalculator.ParserError:
@@ -20,37 +20,38 @@ class ExpressionWidget(BASE, WIDGET):
def __init__(self, options):
super(ExpressionWidget, self).__init__(None)
self.setupUi(self)

self.setList(options)

def doubleClicked(item):
self.text.insertPlainText(self.options[item.text()])

def addButtonText(text):
if any(c for c in text if c.islower()):
self.text.insertPlainText(" %s()" % text)
self.text.moveCursor(QTextCursor.PreviousCharacter, QTextCursor.MoveAnchor)
else:
self.text.insertPlainText(" %s " % text)
self.text.insertPlainText(" %s " % text)
buttons = [b for b in self.buttonsGroupBox.children()if isinstance(b, QPushButton)]
for button in buttons:
button.clicked.connect(partial(addButtonText, button.text()))
self.listWidget.itemDoubleClicked.connect(doubleClicked)

def setList(self, options):
self.options = options
self.listWidget.clear()
for opt in options.keys():
self.listWidget.addItem(opt)

def setValue(self, value):
self.text.setPlainText(value)

def value(self):
return self.text.toPlainText()


class ExpressionWidgetWrapper(WidgetWrapper):

def _panel(self, options):
return ExpressionWidget(options)

@@ -61,7 +62,7 @@ def createWidget(self):
for lyr in layers:
for n in xrange(lyr.bandCount()):
name = '%s@%i' % (lyr.name(), n + 1)
options[name] = name
options[name] = name
return self._panel(options)
elif self.dialogType == DIALOG_BATCH:
return QLineEdit()
@@ -109,7 +110,6 @@ def setValue(self, value):
if self.dialogType == DIALOG_BATCH:
return self.widget.setText(value)


def value(self):
if self.dialogType == DIALOG_STANDARD:
if self.param.datatype == dataobjects.TYPE_FILE:
@@ -130,6 +130,3 @@ def value(self):
if len(values) == 0 and not self.param.optional:
raise InvalidParameterValue()
return values



@@ -48,6 +48,7 @@
from processing.tools import dataobjects, vector
from processing.algs.help import shortHelp


class GeoAlgorithm(object):

def __init__(self):
@@ -132,10 +133,9 @@ def defineCharacteristics(self):
"""
pass


def getParametersPanel(self, parent):
return ParametersPanel(parent, self)
return ParametersPanel(parent, self)

def getCustomParametersDialog(self):
"""If the algorithm has a custom parameters dialog, it should
be returned here, ready to be executed.
@@ -185,12 +185,12 @@ def checkParameterValuesBeforeExecuting(self):
calling from the console.
"""
return None

def processBeforeAddingToModeler(self, alg, model):
"""Add here any task that has to be performed before adding an algorithm
to a model, such as changing the value of a parameter depending on value
of another one"""
pass
of another one"""
pass

# =========================================================

@@ -119,10 +119,10 @@ def initWidgets(self):
button.toggled.connect(self.buttonToggled)
widget = QWidget()
widget.setLayout(layout)

tooltips = self.alg.getParameterDescriptions()
widget.setToolTip(tooltips.get(param.name, param.description))

label = QLabel(desc)
# label.setToolTip(tooltip)
self.labels[param.name] = label
@@ -158,7 +158,7 @@ def setupUi(self):
label.setVisible(self.showAdvanced)
widget.setVisible(self.showAdvanced)
self.widgets[param.name] = widget

self.verticalLayout.addWidget(label)
self.verticalLayout.addWidget(widget)

0 comments on commit 50a785b

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