Skip to content
Permalink
Browse files
[processing] made postprocessing code more pythonic
  • Loading branch information
volaya committed Jun 10, 2014
1 parent 9ec1d46 commit 0009040ed54bf5579f8800a3e0a2ac1731856e22
@@ -50,10 +50,8 @@ def loadClassification():
lines.close()

@staticmethod
def classificationFile():
folder = os.path.join(os.path.dirname(__file__), 'help')
f = os.path.join(folder, 'algclasssification.txt')
return f
def classificationFile():
return os.path.join(os.path.join(os.path.dirname(__file__), 'algclasssification.txt')

@staticmethod
def getGroupsAndName(alg):
@@ -37,7 +37,7 @@
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.WrongHelpFileException import WrongHelpFileException
from processing.gui.Postprocessing import Postprocessing
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.gui.UnthreadedAlgorithmExecutor import \
UnthreadedAlgorithmExecutor
from processing.parameters.ParameterRaster import ParameterRaster
@@ -283,7 +283,7 @@ def finish(self):
keepOpen = ProcessingConfig.getSetting(
ProcessingConfig.KEEP_DIALOG_OPEN)
if self.iterateParam is None:
Postprocessing.handleAlgorithmResults(self.alg, self, not keepOpen)
handleAlgorithmResults(self.alg, self, not keepOpen)
self.executed = True
self.setInfo('Algorithm %s finished' % self.alg.name)
QApplication.restoreOverrideCursor()
@@ -29,7 +29,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from processing.core.ProcessingResults import ProcessingResults
from processing.gui.Postprocessing import Postprocessing
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.gui.FileSelectionPanel import FileSelectionPanel
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
from processing.gui.AlgorithmExecutionDialog import AlgorithmExecutionDialog
@@ -203,7 +203,7 @@ def accept(self):
if UnthreadedAlgorithmExecutor.runalg(alg, self) \
and not self.canceled:
if self.load[i]:
Postprocessing.handleAlgorithmResults(alg, self, False)
handleAlgorithmResults(alg, self, False)
else:
QApplication.restoreOverrideCursor()
return
@@ -39,45 +39,41 @@
from processing.outputs.OutputHTML import OutputHTML
from processing.tools import dataobjects


class Postprocessing:

@staticmethod
def handleAlgorithmResults(alg, progress, showResults=True):
wrongLayers = []
htmlResults = False
progress.setText('Loading resulting layers')
i = 0
for out in alg.outputs:
progress.setPercentage(100 * i / float(len(alg.outputs)))
if out.hidden or not out.open:
continue
if isinstance(out, (OutputRaster, OutputVector, OutputTable)):
try:
if out.value.startswith('memory:'):
layer = out.memoryLayer
QgsMapLayerRegistry.instance().addMapLayers([layer])
def handleAlgorithmResults(alg, progress, showResults=True):
wrongLayers = []
htmlResults = False
progress.setText('Loading resulting layers')
i = 0
for out in alg.outputs:
progress.setPercentage(100 * i / float(len(alg.outputs)))
if out.hidden or not out.open:
continue
if isinstance(out, (OutputRaster, OutputVector, OutputTable)):
try:
if out.value.startswith('memory:'):
layer = out.memoryLayer
QgsMapLayerRegistry.instance().addMapLayers([layer])
else:
if ProcessingConfig.getSetting(
ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):
name = os.path.basename(out.value)
else:
if ProcessingConfig.getSetting(
ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):
name = os.path.basename(out.value)
else:
name = out.description
dataobjects.load(out.value, name, alg.crs,
RenderingStyles.getStyle(alg.commandLineName(),
out.name))
except Exception, e:
wrongLayers.append(out)
elif isinstance(out, OutputHTML):
ProcessingResults.addResult(out.description, out.value)
htmlResults = True
i += 1
if wrongLayers:
QApplication.restoreOverrideCursor()
dlg = CouldNotLoadResultsDialog(wrongLayers, alg)
dlg.exec_()
name = out.description
dataobjects.load(out.value, name, alg.crs,
RenderingStyles.getStyle(alg.commandLineName(),
out.name))
except Exception, e:
wrongLayers.append(out)
elif isinstance(out, OutputHTML):
ProcessingResults.addResult(out.description, out.value)
htmlResults = True
i += 1
if wrongLayers:
QApplication.restoreOverrideCursor()
dlg = CouldNotLoadResultsDialog(wrongLayers, alg)
dlg.exec_()

if showResults and htmlResults and not wrongLayers:
QApplication.restoreOverrideCursor()
dlg = ResultsDialog()
dlg.exec_()
if showResults and htmlResults and not wrongLayers:
QApplication.restoreOverrideCursor()
dlg = ResultsDialog()
dlg.exec_()
@@ -32,7 +32,7 @@
from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
from processing.gui.Postprocessing import Postprocessing
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.tools import dataobjects
from processing.tools.system import *
from processing.tools import vector
@@ -87,9 +87,8 @@ def runalgIterating(alg, paramToIter, progress):
for out in alg.outputs:
outputs[out.name] = out.value

# now run all the algorithms
i = 1
for f in filelist:
# now run all the algorithms
for i,f in enumerate(filelist):
alg.setParameterValue(paramToIter, f)
for out in alg.outputs:
filename = outputs[out.name]
@@ -101,9 +100,7 @@ def runalgIterating(alg, paramToIter, progress):
+ str(len(filelist)) + '...')
progress.setPercentage(i * 100 / len(filelist))
if UnthreadedAlgorithmExecutor.runalg(alg, SilentProgress()):
Postprocessing.handleAlgorithmResults(alg, SilentProgress(),
False)
i += 1
handleAlgorithmResults(alg, SilentProgress(), False)
else:
return False

@@ -27,7 +27,7 @@

from qgis.core import *
from processing.core.Processing import Processing
from processing.gui.Postprocessing import Postprocessing
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.parameters.ParameterSelection import ParameterSelection


@@ -74,6 +74,4 @@ def runalg(algOrName, *args):


def runandload(name, *args):
return Processing.runAlgorithm(name,
Postprocessing.handleAlgorithmResults,
*args)
return Processing.runAlgorithm(name, handleAlgorithmResults, *args)

0 comments on commit 0009040

Please sign in to comment.