mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] made postprocessing code more pythonic
This commit is contained in:
parent
9ec1d46540
commit
0009040ed5
@ -50,10 +50,8 @@ class AlgorithmDecorator:
|
||||
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 PyQt4 import QtCore, QtGui, QtWebKit
|
||||
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 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
|
||||
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 import QtGui
|
||||
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 @@ class BatchProcessingDialog(AlgorithmExecutionDialog):
|
||||
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.core.ProcessingResults import ProcessingResults
|
||||
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.SilentProgress import SilentProgress
|
||||
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 @@ class UnthreadedAlgorithmExecutor:
|
||||
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 @@ class UnthreadedAlgorithmExecutor:
|
||||
+ 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 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user