Skip to content

Commit

Permalink
[processing] replace deprecated % operator with format()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and volaya committed Dec 1, 2016
1 parent 50a785b commit 3e7b262
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions python/plugins/processing/algs/qgis/RasterCalculator.py
Expand Up @@ -61,20 +61,19 @@ def defineCharacteristics(self):
class ParameterRasterCalculatorExpression(ParameterString):

def evaluateForModeler(self, value, model):
# print value
for i in list(model.inputs.values()):
param = i.param
if isinstance(param, ParameterRaster):
new = "%s@" % os.path.basename(param.value)
old = "%s@" % param.name
new = "{}@".format(os.path.basename(param.value))
old = "{}@".format(param.name)
value = value.replace(old, new)

for alg in list(model.algs.values()):
for out in alg.algorithm.outputs:
if isinstance(out, OutputRaster):
if out.value:
new = "%s@" % os.path.basename(out.value)
old = "%s:%s@" % (alg.name, out.name)
new = "{}@".format(os.path.basename(out.value))
old = "{}:{}@".format(alg.name, out.name)
value = value.replace(old, new)
return value

Expand Down Expand Up @@ -106,7 +105,7 @@ def processAlgorithm(self, progress):
for name, lyr in layersDict.items():
for n in xrange(lyr.bandCount()):
entry = QgsRasterCalculatorEntry()
entry.ref = '%s@%i' % (name, n + 1)
entry.ref = '{:s}@{:d}'.format(name, n + 1)
entry.raster = lyr
entry.bandNumber = n + 1
entries.append(entry)
Expand Down Expand Up @@ -149,7 +148,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
expression = algorithm.params[self.EXPRESSION]
for i in list(model.inputs.values()):
param = i.param
if isinstance(param, ParameterRaster) and "%s@" % param.name in expression:
if isinstance(param, ParameterRaster) and "{}@".format(param.name) in expression:
values.append(ValueFromInput(param.name))

if algorithm.name:
Expand All @@ -160,7 +159,7 @@ def processBeforeAddingToModeler(self, algorithm, model):
if alg.name not in dependent:
for out in alg.algorithm.outputs:
if (isinstance(out, OutputRaster)
and "%s:%s@" % (alg.name, out.name) in expression):
and "{}:{}@".format(alg.name, out.name) in expression):
values.append(ValueFromOutput(alg.name, out.name))

algorithm.params[self.LAYERS] = values
Expand Up @@ -28,10 +28,10 @@ def doubleClicked(item):

def addButtonText(text):
if any(c for c in text if c.islower()):
self.text.insertPlainText(" %s()" % text)
self.text.insertPlainText(" {}()".format(text))
self.text.moveCursor(QTextCursor.PreviousCharacter, QTextCursor.MoveAnchor)
else:
self.text.insertPlainText(" %s " % text)
self.text.insertPlainText(" {} ".format(text))
buttons = [b for b in self.buttonsGroupBox.children()if isinstance(b, QPushButton)]
for button in buttons:
button.clicked.connect(partial(addButtonText, button.text()))
Expand Down Expand Up @@ -61,22 +61,22 @@ def createWidget(self):
options = {}
for lyr in layers:
for n in xrange(lyr.bandCount()):
name = '%s@%i' % (lyr.name(), n + 1)
name = '{:s}@{:d}'.format(lyr.name(), n + 1)
options[name] = name
return self._panel(options)
elif self.dialogType == DIALOG_BATCH:
return QLineEdit()
else:
layers = self.dialog.getAvailableValuesOfType(ParameterRaster, OutputRaster)
options = {self.dialog.resolveValueDescription(lyr): "%s@1" % lyr for lyr in layers}
options = {self.dialog.resolveValueDescription(lyr): "{}@1".format(lyr) for lyr in layers}
return self._panel(options)

def refresh(self):
layers = dataobjects.getRasterLayers()
options = {}
for lyr in layers:
for n in xrange(lyr.bandCount()):
options[lyr.name()] = '%s@%i' % (lyr.name(), n + 1)
options[lyr.name()] = '{:s}@{:d}'.format(lyr.name(), n + 1)
self.widget.setList(options)

def setValue(self, value):
Expand Down

0 comments on commit 3e7b262

Please sign in to comment.