Skip to content
Permalink
Browse files
[processing][API] rename runalg() and runandload() to improve
readability
  • Loading branch information
alexbruy committed Mar 22, 2017
1 parent e1a0110 commit 1a46ddbf2875d96008d12914497ddf6b4740fcab
@@ -384,8 +384,8 @@ def checkGrass7IsInstalled(ignorePreviousState=False):
if Grass7Utils.isGrass7Installed:
return
try:
from processing import runalg
result = runalg(
from processing import run
result = run(
'grass7:v.voronoi',
points(),
False,
@@ -68,7 +68,7 @@ def processAlgorithm(self, feedback):

# Delaunay triangulation from input point layer
feedback.setProgressText(self.tr('Creating Delaunay triangles...'))
delone_triangles = processing.runalg("qgis:delaunaytriangulation", layer, None)['OUTPUT']
delone_triangles = processing.run("qgis:delaunaytriangulation", layer, None)['OUTPUT']
delaunay_layer = processing.getObject(delone_triangles)

# Get max edge length from Delaunay triangles
@@ -107,8 +107,8 @@ def processAlgorithm(self, feedback):

# Dissolve all Delaunay triangles
feedback.setProgressText(self.tr('Dissolving Delaunay triangles...'))
dissolved = processing.runalg("qgis:dissolve", delaunay_layer,
True, None, None)['OUTPUT']
dissolved = processing.run("qgis:dissolve", delaunay_layer,
True, None, None)['OUTPUT']
dissolved_layer = processing.getObject(dissolved)

# Save result
@@ -524,7 +524,7 @@ def getAsCommand(self):
console.
"""

s = 'processing.runalg("' + self.commandLineName() + '",'
s = 'processing.run("' + self.commandLineName() + '",'
for param in self.parameters:
s += param.getValueAsCommandLineParameter() + ','
for out in self.outputs:
@@ -69,7 +69,7 @@ def addToLog(msgtype, msg):
with codecs.open(ProcessingLog.logFilename(), 'a',
encoding='utf-8') as logfile:
logfile.write(line)
algname = msg[len('processing.runalg("'):]
algname = msg[len('processing.run("'):]
algname = algname[:algname.index('"')]
if algname not in ProcessingLog.recentAlgs:
ProcessingLog.recentAlgs.append(algname)
@@ -160,7 +160,7 @@ def getValueAsCommandLineParameter(self):
"""
Returns the value of this parameter as it should have been
entered in the console if calling an algorithm using the
processing.runalg() method.
processing.run() method.
"""
return str(self.value)

@@ -114,7 +114,7 @@ def executeAlgorithm(self):
if isinstance(item, TreeLogEntryItem):
if item.isAlg:
script = 'import processing\n'
script += item.entry.text.replace('runalg(', 'runandload(')
script += item.entry.text.replace('run(', 'runAndLoadResults(')
exec(script)

def changeText(self):
@@ -133,7 +133,7 @@ def parseParameters(command):
def createTest(text):
definition = {}

tokens = list(parseParameters(text[len('processing.runalg('):-1]))
tokens = list(parseParameters(text[len('processing.run('):-1]))
cmdname = tokens[0]
alg = Processing.getAlgorithm(cmdname)

@@ -152,7 +152,7 @@ def _toString(v):
params.append(safeName(self.outputs[out.name].description).lower())
else:
params.append(str(None))
s.append("outputs_%s=processing.runalg('%s', %s)" % (self.name, self.consoleName, ",".join(params)))
s.append("outputs_%s=processing.run('%s', %s)" % (self.name, self.consoleName, ",".join(params)))
return s


@@ -5,12 +5,12 @@

import processing

result = processing.runalg("qgis:selectbyattribute",
INPUT_LAYER,
"id2",
0,
"2")
result = processing.run("qgis:selectbyattribute",
INPUT_LAYER,
"id2",
0,
"2")

processing.runalg("qgis:saveselectedfeatures",
result["OUTPUT"],
OUTPUT_LAYER)
processing.run("qgis:saveselectedfeatures",
result["OUTPUT"],
OUTPUT_LAYER)
@@ -99,7 +99,7 @@ def algorithmHelp(name):
print('Algorithm "{}" not found.'.format(name))


def runalg(algOrName, *args, **kwargs):
def run(algOrName, *args, **kwargs):
"""Executes given algorithm and returns its outputs as dictionary
object.
"""
@@ -108,7 +108,7 @@ def runalg(algOrName, *args, **kwargs):
return alg.getOutputValuesAsDictionary()


def runandload(name, *args, **kwargs):
def runAndLoadResults(name, *args, **kwargs):
"""Executes given algorithm and load its results into QGIS project
when possible.
"""
@@ -89,7 +89,7 @@ def baseHelpForAlgorithm(alg, folder):
f.write('Console usage\n')
f.write('-------------\n')
f.write('\n::\n\n')
cmd = " processing.runalg('{}', ".format(alg.commandLineName())
cmd = " processing.run('{}', ".format(alg.commandLineName())
for p in alg.parameters:
cmd += '{}, '.format(p.name.lower().strip())

0 comments on commit 1a46ddb

Please sign in to comment.