Skip to content

Commit e353d22

Browse files
committedOct 5, 2016
[processing] evaluate parameters before executing algorithm
This allows a better use of expressions
1 parent 01f3808 commit e353d22

File tree

8 files changed

+264
-422
lines changed

8 files changed

+264
-422
lines changed
 

‎python/plugins/processing/core/GeoAlgorithm.py

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ def execute(self, progress=SilentProgress(), model=None):
199199
self.setOutputCRS()
200200
self.resolveTemporaryOutputs()
201201
self.resolveDataObjects()
202-
self.resolveMinCoveringExtent()
202+
self.evaluateParameterValues()
203203
self.checkOutputFileExtensions()
204204
self.runPreExecutionScript(progress)
205205
self.processAlgorithm(progress)
206206
progress.setPercentage(100)
207207
self.convertUnsupportedFormats(progress)
208208
self.runPostExecutionScript(progress)
209209
except GeoAlgorithmExecutionException as gaee:
210-
lines = [self.tr('Uncaught error while executing algorithm')]
210+
lines = [self.tr('Error while executing algorithm')]
211211
lines.append(traceback.format_exc())
212212
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, gaee.msg)
213213
raise GeoAlgorithmExecutionException(gaee.msg, lines, gaee)
@@ -340,11 +340,9 @@ def checkOutputFileExtensions(self):
340340
if not os.path.isabs(out.value):
341341
continue
342342
if isinstance(out, OutputRaster):
343-
exts = \
344-
dataobjects.getSupportedOutputRasterLayerExtensions()
343+
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
345344
elif isinstance(out, OutputVector):
346-
exts = \
347-
dataobjects.getSupportedOutputVectorLayerExtensions()
345+
exts = dataobjects.getSupportedOutputVectorLayerExtensions()
348346
elif isinstance(out, OutputTable):
349347
exts = dataobjects.getSupportedOutputTableExtensions()
350348
elif isinstance(out, OutputHTML):
@@ -360,60 +358,12 @@ def checkOutputFileExtensions(self):
360358
out.value = out.value + '.' + exts[0]
361359

362360

363-
def canUseAutoExtent(self):
364-
for param in self.parameters:
365-
if isinstance(param, (ParameterRaster, ParameterVector)):
366-
return True
367-
if isinstance(param, ParameterMultipleInput):
368-
return True
369-
return False
370-
371-
def resolveMinCoveringExtent(self):
372-
for param in self.parameters:
373-
if isinstance(param, ParameterExtent):
374-
if param.value is None:
375-
param.value = self.getMinCoveringExtent()
376-
377-
def getMinCoveringExtent(self):
378-
first = True
379-
found = False
361+
def evaluateParameterValues(self):
380362
for param in self.parameters:
381-
if param.value:
382-
if isinstance(param, (ParameterRaster, ParameterVector)):
383-
if isinstance(param.value, (QgsRasterLayer,
384-
QgsVectorLayer)):
385-
layer = param.value
386-
else:
387-
layer = dataobjects.getObject(param.value)
388-
if layer:
389-
found = True
390-
self.addToRegion(layer, first)
391-
first = False
392-
elif isinstance(param, ParameterMultipleInput):
393-
layers = param.value.split(';')
394-
for layername in layers:
395-
layer = dataobjects.getObject(layername)
396-
if layer:
397-
found = True
398-
self.addToRegion(layer, first)
399-
first = False
400-
if found:
401-
return '{},{},{},{}'.format(
402-
self.xmin, self.xmax, self.ymin, self.ymax)
403-
else:
404-
return None
405-
406-
def addToRegion(self, layer, first):
407-
if first:
408-
self.xmin = layer.extent().xMinimum()
409-
self.xmax = layer.extent().xMaximum()
410-
self.ymin = layer.extent().yMinimum()
411-
self.ymax = layer.extent().yMaximum()
412-
else:
413-
self.xmin = min(self.xmin, layer.extent().xMinimum())
414-
self.xmax = max(self.xmax, layer.extent().xMaximum())
415-
self.ymin = min(self.ymin, layer.extent().yMinimum())
416-
self.ymax = max(self.ymax, layer.extent().yMaximum())
363+
try:
364+
param.evaluate(self)
365+
except ValueError, e:
366+
raise GeoAlgorithmExecutionException(str(e))
417367

418368
def resolveTemporaryOutputs(self):
419369
"""Sets temporary outputs (output.value = None) with a

‎python/plugins/processing/core/parameters.py

Lines changed: 161 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
from inspect import isclass
3434
from copy import deepcopy
3535

36-
36+
from qgis.utils import iface
3737
from qgis.PyQt.QtCore import QCoreApplication
38-
from qgis.core import QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsCoordinateReferenceSystem
38+
from qgis.core import (QgsRasterLayer, QgsVectorLayer, QgsMapLayer, QgsCoordinateReferenceSystem,
39+
QgsExpressionContext, QgsExpressionContextUtils, QgsExpression, QgsExpressionContextScope)
40+
3941
from processing.tools.vector import resolveFieldIndex, features
40-
from processing.tools.system import isWindows
4142
from processing.tools import dataobjects
4243

4344
def parseBool(s):
@@ -58,7 +59,47 @@ def _splitParameterOptions(line):
5859
def _createDescriptiveName(s):
5960
return s.replace('_', ' ')
6061

61-
class Parameter(object):
62+
def _expressionContext():
63+
context = QgsExpressionContext()
64+
context.appendScope(QgsExpressionContextUtils.globalScope())
65+
context.appendScope(QgsExpressionContextUtils.projectScope())
66+
processingScope = QgsExpressionContextScope()
67+
layers = dataobjects.getAllLayers()
68+
for layer in layers:
69+
name = layer.name()
70+
processingScope.setVariable('%s_minx' % name, layer.extent().xMinimum())
71+
processingScope.setVariable('%s_miny' % name, layer.extent().yMinimum())
72+
processingScope.setVariable('%s_maxx' % name, layer.extent().xMaximum())
73+
processingScope.setVariable('%s_maxy' % name, layer.extent().yMaximum())
74+
if isinstance(layer, QgsRasterLayer):
75+
cellsize = (layer.extent().xMaximum()
76+
- layer.extent().xMinimum()) / layer.width()
77+
processingScope.setVariable('%s_cellsize' % name, cellsize)
78+
79+
layers = dataobjects.getRasterLayers()
80+
for layer in layers:
81+
for i in range(layer.bandCount()):
82+
stats = layer.dataProvider().bandStatistics(i + 1)
83+
processingScope.setVariable('%s_band%i_avg' % (name, i + 1), stats.mean)
84+
processingScope.setVariable('%s_band%i_stddev' % (name, i + 1), stats.stdDev)
85+
processingScope.setVariable('%s_band%i_min' % (name, i + 1), stats.minimumValue)
86+
processingScope.setVariable('%s_band%i_max' % (name, i + 1), stats.maximumValue)
87+
88+
extent = iface.mapCanvas().extent()
89+
processingScope.setVariable('canvasextent_minx', extent.xMinimum())
90+
processingScope.setVariable('canvasextent_miny', extent.yMinimum())
91+
processingScope.setVariable('canvasextent_maxx', extent.xMaximum())
92+
processingScope.setVariable('canvasextent_maxy', extent.yMaximum())
93+
94+
extent = iface.mapCanvas().fullExtent()
95+
processingScope.setVariable('fullextent_minx', extent.xMinimum())
96+
processingScope.setVariable('fullextent_miny', extent.yMinimum())
97+
processingScope.setVariable('fullextent_maxx', extent.xMaximum())
98+
processingScope.setVariable('fullextent_maxy', extent.yMaximum())
99+
context.appendScope(processingScope)
100+
return context
101+
102+
class Parameter:
62103

63104
"""
64105
Base class for all parameters that a geoalgorithm might
@@ -148,6 +189,9 @@ def wrapper(self, dialog, row=0, col=0):
148189
wrapper = wrapper(self, dialog, row, col)
149190
# or a wrapper instance
150191
return wrapper
192+
193+
def evaluate(self, alg):
194+
pass
151195

152196
class ParameterBoolean(Parameter):
153197

@@ -330,6 +374,51 @@ def fromScriptCode(self, line):
330374
default = definition.strip()[len('extent') + 1:] or None
331375
return ParameterExtent(name, descName, default, isOptional)
332376

377+
def evaluate(self, alg):
378+
if self.optional and not bool(self.value):
379+
self.value = self.getMinCoveringExtent()
380+
381+
def getMinCoveringExtent(self, alg):
382+
first = True
383+
found = False
384+
for param in alg.parameters:
385+
if param.value:
386+
if isinstance(param, (ParameterRaster, ParameterVector)):
387+
if isinstance(param.value, (QgsRasterLayer,
388+
QgsVectorLayer)):
389+
layer = param.value
390+
else:
391+
layer = dataobjects.getObject(param.value)
392+
if layer:
393+
found = True
394+
self.addToRegion(layer, first)
395+
first = False
396+
elif isinstance(param, ParameterMultipleInput):
397+
layers = param.value.split(';')
398+
for layername in layers:
399+
layer = dataobjects.getObject(layername)
400+
if layer:
401+
found = True
402+
self.addToRegion(layer, first)
403+
first = False
404+
if found:
405+
return '{},{},{},{}'.format(
406+
self.xmin, self.xmax, self.ymin, self.ymax)
407+
else:
408+
return None
409+
410+
def addToRegion(self, layer, first):
411+
if first:
412+
self.xmin = layer.extent().xMinimum()
413+
self.xmax = layer.extent().xMaximum()
414+
self.ymin = layer.extent().yMinimum()
415+
self.ymax = layer.extent().yMaximum()
416+
else:
417+
self.xmin = min(self.xmin, layer.extent().xMinimum())
418+
self.xmax = max(self.xmax, layer.extent().xMaximum())
419+
self.ymin = min(self.ymin, layer.extent().yMinimum())
420+
self.ymax = max(self.ymax, layer.extent().yMaximum())
421+
333422

334423
class ParameterPoint(Parameter):
335424

@@ -715,21 +804,30 @@ def setValue(self, n):
715804
self.value = None
716805
return True
717806

718-
try:
719-
if float(n) - int(float(n)) == 0:
720-
value = int(float(n))
721-
else:
722-
value = float(n)
723-
if self.min is not None:
724-
if value < self.min:
725-
return False
726-
if self.max is not None:
727-
if value > self.max:
728-
return False
729-
self.value = value
730-
return True
731-
except:
732-
return False
807+
if isinstance(n, basestring):
808+
try:
809+
v = self._evaluate(n)
810+
float(v)
811+
self.value = n
812+
return True
813+
except:
814+
return False
815+
else:
816+
try:
817+
if float(n) - int(float(n)) == 0:
818+
value = int(float(n))
819+
else:
820+
value = float(n)
821+
if self.min is not None:
822+
if value < self.min:
823+
return False
824+
if self.max is not None:
825+
if value > self.max:
826+
return False
827+
self.value = value
828+
return True
829+
except:
830+
return False
733831

734832
def getAsScriptCode(self):
735833
param_type = ''
@@ -745,6 +843,31 @@ def fromScriptCode(self, line):
745843
if definition.lower().strip().startswith('number'):
746844
default = definition.strip()[len('number') + 1:] or None
747845
return ParameterNumber(name, descName, default=default, optional=isOptional)
846+
847+
def _evaluate(self, v):
848+
exp = QgsExpression(v)
849+
if exp.hasParserError():
850+
raise ValueError(self.tr("Error in parameter expression: ") + exp.parserErrorString())
851+
result = exp.evaluate(_expressionContext())
852+
if exp.hasEvalError():
853+
raise ValueError("Error evaluating parameter expression: " + exp.evalErrorString())
854+
return result
855+
856+
def evaluate(self, alg):
857+
if isinstance(self.value, basestring):
858+
self.value = self._evaluate(self.value)
859+
860+
def expressionContext(self):
861+
return _expressionContext()
862+
863+
def getValueAsCommandLineParameter(self):
864+
if self.value is None:
865+
return str(None)
866+
if isinstance(self.value, basestring):
867+
return '"%s"' % self.value
868+
return str(self.value)
869+
870+
748871

749872
class ParameterRange(Parameter):
750873

@@ -919,6 +1042,13 @@ def fromScriptCode(self, line):
9191042
return ParameterSelection(name, descName, options, optional=isOptional)
9201043

9211044

1045+
class ParameterEvaluationException(Exception):
1046+
1047+
def __init__(self, param, msg):
1048+
Exception.__init__(msg)
1049+
self.param = param
1050+
1051+
9221052
class ParameterString(Parameter):
9231053

9241054
default_metadata = {
@@ -976,6 +1106,18 @@ def fromScriptCode(self, line):
9761106
return ParameterString(name, descName, default, multiline=True, optional=isOptional)
9771107
else:
9781108
return ParameterString(name, descName, multiline=True, optional=isOptional)
1109+
1110+
def evaluate(self, alg):
1111+
exp = QgsExpression(self.value)
1112+
if exp.hasParserError():
1113+
raise ValueError(self.tr("Error in parameter expression: ") + exp.parserErrorString())
1114+
result = exp.evaluate(_expressionContext())
1115+
if exp.hasEvalError():
1116+
raise ValueError("Error evaluating parameter expression: " + exp.evalErrorString())
1117+
self.value = result
1118+
1119+
def expressionContext(self):
1120+
return _expressionContext()
9791121

9801122
class ParameterTable(ParameterDataObject):
9811123

‎python/plugins/processing/gui/AlgorithmDialog.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from qgis.PyQt.QtWidgets import QMessageBox, QApplication, QPushButton, QWidget, QVBoxLayout
3232
from qgis.PyQt.QtGui import QCursor, QColor, QPalette
3333

34-
from qgis.core import QgsMapLayerRegistry, QgsExpressionContext, QgsExpressionContextUtils, QgsExpression
34+
from qgis.core import QgsMapLayerRegistry
3535

3636
from processing.core.ProcessingLog import ProcessingLog
3737
from processing.core.ProcessingConfig import ProcessingConfig
@@ -62,8 +62,6 @@
6262
from processing.core.outputs import OutputVector
6363
from processing.core.outputs import OutputTable
6464

65-
from processing.tools import dataobjects
66-
6765

6866
class AlgorithmDialog(AlgorithmDialogBase):
6967

@@ -114,18 +112,6 @@ def setParamValues(self):
114112

115113
return True
116114

117-
def evaluateExpression(self, text):
118-
context = QgsExpressionContext()
119-
context.appendScope(QgsExpressionContextUtils.globalScope())
120-
context.appendScope(QgsExpressionContextUtils.projectScope())
121-
exp = QgsExpression(text)
122-
if exp.hasParserError():
123-
raise Exception(exp.parserErrorString())
124-
result = exp.evaluate(context)
125-
if exp.hasEvalError():
126-
raise ValueError(exp.evalErrorString())
127-
return result
128-
129115
def setParamValue(self, param, wrapper, alg=None):
130116
return param.setValue(wrapper.value())
131117

‎python/plugins/processing/gui/NumberInputDialog.py

Lines changed: 0 additions & 153 deletions
This file was deleted.

‎python/plugins/processing/gui/NumberInputPanel.py

Lines changed: 14 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -32,131 +32,44 @@
3232
from qgis.PyQt.QtCore import pyqtSignal
3333
from qgis.PyQt.QtWidgets import QDialog
3434

35-
from math import log10, floor
3635
from qgis.core import (QgsDataSourceUri,
3736
QgsCredentials,
38-
QgsExpressionContext,
39-
QgsExpressionContextUtils,
4037
QgsExpression,
41-
QgsRasterLayer,
42-
QgsExpressionContextScope)
38+
QgsRasterLayer)
4339
from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
4440
from qgis.utils import iface
45-
from processing.tools import dataobjects
4641

4742
pluginPath = os.path.split(os.path.dirname(__file__))[0]
4843
WIDGET, BASE = uic.loadUiType(
49-
os.path.join(pluginPath, 'ui', 'widgetNumberSelector.ui'))
44+
os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
5045

5146

5247
class NumberInputPanel(BASE, WIDGET):
5348

5449
hasChanged = pyqtSignal()
5550

56-
def __init__(self, number, minimum, maximum, isInteger):
51+
def __init__(self, param):
5752
super(NumberInputPanel, self).__init__(None)
5853
self.setupUi(self)
5954

60-
self.spnValue.setExpressionsEnabled(True)
61-
self.isInteger = isInteger
62-
if self.isInteger:
63-
self.spnValue.setDecimals(0)
64-
else:
65-
# Guess reasonable step value
66-
if (maximum == 0 or maximum) and (minimum == 0 or minimum):
67-
self.spnValue.setSingleStep(self.calculateStep(minimum, maximum))
68-
69-
if maximum == 0 or maximum:
70-
self.spnValue.setMaximum(maximum)
71-
else:
72-
self.spnValue.setMaximum(99999999)
73-
if minimum == 0 or minimum:
74-
self.spnValue.setMinimum(minimum)
75-
else:
76-
self.spnValue.setMinimum(-99999999)
77-
78-
# Set default value
79-
if number == 0 or number:
80-
self.spnValue.setValue(float(number))
81-
self.spnValue.setClearValue(float(number))
82-
elif minimum == 0 or minimum:
83-
self.spnValue.setValue(float(minimum))
84-
self.spnValue.setClearValue(float(minimum))
85-
else:
86-
self.spnValue.setValue(0)
87-
self.spnValue.setClearValue(0)
88-
89-
self.btnCalc.setFixedHeight(self.spnValue.height())
90-
91-
self.btnCalc.clicked.connect(self.showExpressionsBuilder)
92-
93-
self.spnValue.valueChanged.connect(lambda: self.hasChanged.emit())
55+
self.param = param
56+
self.text = param.default
57+
58+
self.btnSelect.clicked.connect(self.showExpressionsBuilder)
59+
self.leText.textChanged.connect(lambda: self.hasChanged.emit())
9460

9561
def showExpressionsBuilder(self):
96-
context = self.expressionContext()
97-
dlg = QgsExpressionBuilderDialog(None, self.spnValue.text(), self, 'generic', context)
62+
context = self.param.expressionContext()
63+
dlg = QgsExpressionBuilderDialog(None, self.leText.text(), self, 'generic', context)
9864
dlg.setWindowTitle(self.tr('Expression based input'))
9965
if dlg.exec_() == QDialog.Accepted:
10066
exp = QgsExpression(dlg.expressionText())
10167
if not exp.hasParserError():
102-
result = exp.evaluate(context)
103-
if not exp.hasEvalError():
104-
try:
105-
self.spnValue.setValue(float(result))
106-
except:
107-
pass
108-
109-
def expressionContext(self):
110-
context = QgsExpressionContext()
111-
context.appendScope(QgsExpressionContextUtils.globalScope())
112-
context.appendScope(QgsExpressionContextUtils.projectScope())
113-
processingScope = QgsExpressionContextScope()
114-
layers = dataobjects.getAllLayers()
115-
for layer in layers:
116-
name = layer.name()
117-
processingScope.setVariable('%s_minx' % name, layer.extent().xMinimum())
118-
processingScope.setVariable('%s_miny' % name, layer.extent().yMinimum())
119-
processingScope.setVariable('%s_maxx' % name, layer.extent().xMaximum())
120-
processingScope.setVariable('%s_maxy' % name, layer.extent().yMaximum())
121-
if isinstance(layer, QgsRasterLayer):
122-
cellsize = (layer.extent().xMaximum()
123-
- layer.extent().xMinimum()) / layer.width()
124-
processingScope.setVariable('%s_cellsize' % name, cellsize)
125-
126-
layers = dataobjects.getRasterLayers()
127-
for layer in layers:
128-
for i in range(layer.bandCount()):
129-
stats = layer.dataProvider().bandStatistics(i + 1)
130-
processingScope.setVariable('%s_band%i_avg' % (name, i + 1), stats.mean)
131-
processingScope.setVariable('%s_band%i_stddev' % (name, i + 1), stats.stdDev)
132-
processingScope.setVariable('%s_band%i_min' % (name, i + 1), stats.minimumValue)
133-
processingScope.setVariable('%s_band%i_max' % (name, i + 1), stats.maximumValue)
134-
135-
extent = iface.mapCanvas().extent()
136-
processingScope.setVariable('canvasextent_minx', extent.xMinimum())
137-
processingScope.setVariable('canvasextent_miny', extent.yMinimum())
138-
processingScope.setVariable('canvasextent_maxx', extent.xMaximum())
139-
processingScope.setVariable('canvasextent_maxy', extent.yMaximum())
140-
141-
extent = iface.mapCanvas().fullExtent()
142-
processingScope.setVariable('fullextent_minx', extent.xMinimum())
143-
processingScope.setVariable('fullextent_miny', extent.yMinimum())
144-
processingScope.setVariable('fullextent_maxx', extent.xMaximum())
145-
processingScope.setVariable('fullextent_maxy', extent.yMaximum())
146-
context.appendScope(processingScope)
147-
return context
68+
self.setValue(dlg.expressionText())
14869

70+
14971
def getValue(self):
150-
return self.spnValue.value()
72+
return self.leText.text()
15173

15274
def setValue(self, value):
153-
self.spnValue.setValue(value)
154-
155-
def calculateStep(self, minimum, maximum):
156-
valueRange = maximum - minimum
157-
if valueRange <= 1.0:
158-
step = valueRange / 10.0
159-
# round to 1 significant figure
160-
return round(step, -int(floor(log10(step))))
161-
else:
162-
return 1.0
75+
self.leText.setText(unicode(value))
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
NumberInputPanel.py
6+
---------------------
7+
Date : August 2016
8+
Copyright : (C) 2016 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Victor Olaya'
21+
__date__ = 'August 2016'
22+
__copyright__ = '(C) 2016, Victor Olaya'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
from qgis.PyQt import uic
31+
from qgis.PyQt.QtCore import pyqtSignal
32+
from qgis.PyQt.QtWidgets import QDialog
33+
34+
from qgis.core import (QgsDataSourceUri,
35+
QgsCredentials,
36+
QgsExpression,
37+
QgsRasterLayer)
38+
from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
39+
from qgis.utils import iface
40+
41+
pluginPath = os.path.split(os.path.dirname(__file__))[0]
42+
WIDGET, BASE = uic.loadUiType(
43+
os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
44+
45+
46+
class StringInputPanel(BASE, WIDGET):
47+
48+
hasChanged = pyqtSignal()
49+
50+
def __init__(self, param):
51+
super(StringInputPanel, self).__init__(None)
52+
self.setupUi(self)
53+
54+
self.param = param
55+
self.text = param.default
56+
57+
self.btnSelect.clicked.connect(self.showExpressionsBuilder)
58+
self.leText.textChanged.connect(lambda: self.hasChanged.emit())
59+
60+
def showExpressionsBuilder(self):
61+
context = self.param.expressionContext()
62+
dlg = QgsExpressionBuilderDialog(None, self.leText.text(), self, 'generic', context)
63+
dlg.setWindowTitle(self.tr('Expression based input'))
64+
if dlg.exec_() == QDialog.Accepted:
65+
exp = QgsExpression(dlg.expressionText())
66+
if not exp.hasParserError():
67+
self.setValue(dlg.expressionText())
68+
69+
70+
def getValue(self):
71+
return self.leText.text()
72+
73+
def setValue(self, value):
74+
self.leText.setText(unicode(value))

‎python/plugins/processing/gui/wrappers.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
5151
from processing.gui.FixedTablePanel import FixedTablePanel
5252
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
53+
from processing.gui.StringInputPanel import StringInputPanel
5354

5455

5556
DIALOG_STANDARD = 'standard'
@@ -442,8 +443,7 @@ class NumberWidgetWrapper(WidgetWrapper):
442443

443444
def createWidget(self):
444445
if self.dialogType in (DIALOG_STANDARD, DIALOG_BATCH):
445-
return NumberInputPanel(self.param.default, self.param.min, self.param.max,
446-
self.param.isInteger)
446+
return NumberInputPanel(self.param)
447447
else:
448448
widget = QComboBox()
449449
widget.setEditable(True)
@@ -605,9 +605,9 @@ def createWidget(self):
605605
if self.param.default:
606606
widget.setPlainText(self.param.default)
607607
else:
608-
widget = QLineEdit()
608+
widget = StringInputPanel(self.param)
609609
if self.param.default:
610-
widget.setText(self.param.default)
610+
widget.setValue(self.param.default)
611611
elif self.dialogType == DIALOG_BATCH:
612612
widget = QLineEdit()
613613
if self.param.default:
@@ -642,22 +642,10 @@ def value(self):
642642
if self.param.multiline:
643643
text = self.widget.toPlainText()
644644
else:
645-
text = self.widget.text()
646-
647-
if self.param.evaluateExpressions:
648-
try:
649-
text = self.evaluateExpression(text)
650-
except:
651-
pass
645+
text = self.widget.getValue()
652646
return text
653647
if self.dialogType == DIALOG_BATCH:
654648
text = self.widget.text()
655-
if self.param.evaluateExpressions:
656-
try:
657-
text = self.evaluateExpression(text)
658-
except:
659-
pass
660-
return text
661649
else:
662650
if self.param.multiline:
663651
value = self.widget.getValue()

‎python/plugins/processing/ui/widgetNumberSelector.ui

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.