Skip to content

Commit

Permalink
[processing] indentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and volaya committed Dec 1, 2016
1 parent f002321 commit 50a785b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
1 change: 0 additions & 1 deletion python/plugins/processing/algs/qgis/FieldsMapper.py
Expand Up @@ -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))
Expand Down
29 changes: 16 additions & 13 deletions python/plugins/processing/algs/qgis/RasterCalculator.py
Expand Up @@ -39,6 +39,7 @@
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.algs.qgis.ui.RasterCalculatorWidgets import LayersListWidgetWrapper, ExpressionWidgetWrapper


class RasterCalculator(GeoAlgorithm):

LAYERS = 'LAYERS'
Expand All @@ -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()):
Expand All @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 10 additions & 13 deletions python/plugins/processing/algs/qgis/ui/RasterCalculatorWidgets.py
Expand Up @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -130,6 +130,3 @@ def value(self):
if len(values) == 0 and not self.param.optional:
raise InvalidParameterValue()
return values



12 changes: 6 additions & 6 deletions python/plugins/processing/core/GeoAlgorithm.py
Expand Up @@ -48,6 +48,7 @@
from processing.tools import dataobjects, vector
from processing.algs.help import shortHelp


class GeoAlgorithm(object):

def __init__(self):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

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

Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -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
Expand Down
Expand Up @@ -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)

Expand Down

0 comments on commit 50a785b

Please sign in to comment.