Skip to content
Permalink
Browse files

[processing] cleaning and restructuring

This fixes some design errors (mainly the ModelerUtils class, which is not needed anymore to hold a copy of algs and providers in order to avoid circular dependencies) and removes unused code
  • Loading branch information
volaya committed Apr 28, 2016
1 parent b4b05ba commit e6b76c4d7bf2f07a1b5817261d41281f7ef88dc4
@@ -43,6 +43,19 @@
from processing.modeler.ModelerDialog import ModelerDialog
from processing.tools.system import tempFolder
from processing.gui.menus import removeMenus, initializeMenus, createMenus
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
from processing.modeler.ModelerOnlyAlgorithmProvider import ModelerOnlyAlgorithmProvider
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider
from processing.algs.grass.GrassAlgorithmProvider import GrassAlgorithmProvider
from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider
from processing.algs.lidar.LidarToolsAlgorithmProvider import LidarToolsAlgorithmProvider
from processing.algs.gdal.GdalOgrAlgorithmProvider import GdalOgrAlgorithmProvider
from processing.algs.otb.OTBAlgorithmProvider import OTBAlgorithmProvider
from processing.algs.r.RAlgorithmProvider import RAlgorithmProvider
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider


cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
@@ -541,6 +541,12 @@ def getAsCommand(self):
s = s[:-1] + ')'
return s

def displayName(self):
return self.i18n_name or self.name

def displayNames(self):
return self.name, self.i18n_name

def tr(self, string, context=''):
if context == '':
context = self.__class__.__name__
@@ -36,29 +36,14 @@
from qgis.core import QgsMessageLog

import processing
from processing.gui import AlgorithmClassification
from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.RenderingStyles import RenderingStyles
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.gui.AlgorithmExecutor import runalg
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
from processing.modeler.ModelerOnlyAlgorithmProvider import ModelerOnlyAlgorithmProvider
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider
from processing.algs.grass.GrassAlgorithmProvider import GrassAlgorithmProvider
from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider
from processing.algs.lidar.LidarToolsAlgorithmProvider import LidarToolsAlgorithmProvider
from processing.algs.gdal.GdalOgrAlgorithmProvider import GdalOgrAlgorithmProvider
from processing.algs.otb.OTBAlgorithmProvider import OTBAlgorithmProvider
from processing.algs.r.RAlgorithmProvider import RAlgorithmProvider
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider

from processing.tools import dataobjects


@@ -85,22 +70,21 @@ class Processing:
# All the registered context menu actions for the toolbox
contextMenuActions = []

modeler = ModelerAlgorithmProvider()

@staticmethod
def addProvider(provider, updateList=True):
def addProvider(provider):
"""Use this method to add algorithms from external providers.
"""

# Note: this might slow down the initialization process if
# there are many new providers added. Should think of a
# different solution
if provider.getName() in [p.getName for p in Processing.providers]:
return
try:
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.readSettings()
if updateList:
Processing.updateAlgsList()
provider.loadAlgorithms()
Processing.algs[provider.getName()] = {a.commandLineName(): a for a in provider.algs}
Processing.actions[provider.getName()] = provider.actions
Processing.contextMenuActions.extend(provider.contextMenuActions)
algListWatcher.providerAdded.emit(provider.getName())
except:
ProcessingLog.addToLog(
@@ -125,7 +109,7 @@ def removeProvider(provider):
# This try catch block is here to avoid problems if the
# plugin with a provider is unloaded after the Processing
# framework itself has been unloaded. It is a quick fix
# before I found out how to properly avoid that.
# before I find out how to properly avoid that.
pass

@staticmethod
@@ -139,27 +123,12 @@ def getProviderFromName(name):
@staticmethod
def initialize():
# Add the basic providers
Processing.addProvider(QGISAlgorithmProvider(), updateList=False)
Processing.addProvider(ModelerOnlyAlgorithmProvider(), updateList=False)
Processing.addProvider(GdalOgrAlgorithmProvider(), updateList=False)
Processing.addProvider(LidarToolsAlgorithmProvider(), updateList=False)
Processing.addProvider(OTBAlgorithmProvider(), updateList=False)
Processing.addProvider(RAlgorithmProvider(), updateList=False)
Processing.addProvider(SagaAlgorithmProvider(), updateList=False)
Processing.addProvider(GrassAlgorithmProvider(), updateList=False)
Processing.addProvider(Grass7AlgorithmProvider(), updateList=False)
Processing.addProvider(ScriptAlgorithmProvider(), updateList=False)
Processing.addProvider(TauDEMAlgorithmProvider(), updateList=False)
Processing.addProvider(PreconfiguredAlgorithmProvider(), updateList=False)
Processing.addProvider(Processing.modeler, updateList=False)
Processing.modeler.initializeSettings()

for c in AlgorithmProvider.__subclasses__():
Processing.addProvider(c())
# And initialize
AlgorithmClassification.loadClassification()
ProcessingConfig.initialize()
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
Processing.loadFromProviders()

@staticmethod
def updateAlgsList():
@@ -168,21 +137,10 @@ def updateAlgsList():
algorithm providers.
"""
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Processing.loadFromProviders()
for p in Processing.providers:
Processing.reloadProvider(p)
QApplication.restoreOverrideCursor()

@staticmethod
def loadFromProviders():
Processing.loadAlgorithms()
Processing.loadActions()
Processing.loadContextMenuActions()

@staticmethod
def updateProviders():
providers = [p for p in Processing.providers if p.getName() != "model"]
for provider in providers:
provider.loadAlgorithms()

@staticmethod
def reloadProvider(providerName):
for p in Processing.providers:
@@ -191,50 +149,6 @@ def reloadProvider(providerName):
Processing.algs[
p.getName()] = {a.commandLineName(): a for a in p.algs}

@staticmethod
def loadAlgorithms():
Processing.algs = {}
Processing.updateProviders()
providers = [p for p in Processing.providers if p.getName() != "model"]
for provider in providers:
providerAlgs = provider.algs
algs = {}
for alg in providerAlgs:
algs[alg.commandLineName()] = alg
Processing.algs[provider.getName()] = algs

provs = {}
for provider in Processing.providers:
provs[provider.getName()] = provider

ModelerUtils.allAlgs = Processing.algs
ModelerUtils.providers = provs

Processing.modeler.loadAlgorithms()

algs = {}
for alg in Processing.modeler.algs:
algs[alg.commandLineName()] = alg
Processing.algs[Processing.modeler.getName()] = algs

@staticmethod
def loadActions():
for provider in Processing.providers:
providerActions = provider.actions
actions = list()
for action in providerActions:
actions.append(action)
Processing.actions[provider.getName()] = actions

Processing.actions[provider.getName()] = actions

@staticmethod
def loadContextMenuActions():
Processing.contextMenuActions = []
for provider in Processing.providers:
providerActions = provider.contextMenuActions
for action in providerActions:
Processing.contextMenuActions.append(action)

@staticmethod
def getAlgorithm(name):

This file was deleted.

@@ -36,7 +36,6 @@
from qgis.core import QgsNetworkAccessManager

from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui import AlgorithmClassification

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
@@ -62,7 +61,7 @@ def __init__(self, alg):

self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)

self.setWindowTitle(AlgorithmClassification.getDisplayName(self.alg))
self.setWindowTitle(self.alg.displayName())

desktop = QDesktopWidget()
if desktop.physicalDpiX() > 96:
@@ -38,7 +38,6 @@
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig, settingsWatcher
from processing.gui.MessageDialog import MessageDialog
from processing.gui import AlgorithmClassification
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
@@ -344,7 +343,7 @@ def __init__(self, alg):
QTreeWidgetItem.__init__(self)
self.alg = alg
icon = alg.getIcon()
nameEn, name = AlgorithmClassification.getDisplayNames(alg)
nameEn, name = alg.displayNames()
name = name if name != '' else nameEn
self.setIcon(0, icon)
self.setToolTip(0, name)
@@ -17,7 +17,6 @@
***************************************************************************
"""


__author__ = 'Alexander Bruy'
__date__ = 'December 2012'
__copyright__ = '(C) 2012, Alexander Bruy'
@@ -39,7 +38,7 @@
from qgis.core import QgsApplication
from qgis.utils import iface

from processing.modeler.ModelerUtils import ModelerUtils
from processing.core.Processing import Processing
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.HelpEditionDialog import HelpEditionDialog
from processing.algs.r.RAlgorithm import RAlgorithm
@@ -63,8 +62,8 @@ def __init__(self, algType, alg):
super(ScriptEditorDialog, self).__init__(None)
self.setupUi(self)

self.setWindowFlags(Qt.WindowMinimizeButtonHint |
Qt.WindowMaximizeButtonHint |
self.setWindowFlags(Qt.WindowMinimizeButtonHint |
Qt.WindowMaximizeButtonHint |
Qt.WindowCloseButtonHint)
# Set icons
self.btnOpen.setIcon(
@@ -274,10 +273,10 @@ def setHasChanged(self, hasChanged):
def runAlgorithm(self):
if self.algType == self.SCRIPT_PYTHON:
alg = ScriptAlgorithm(None, unicode(self.editor.text()))
alg.provider = ModelerUtils.providers['script']
alg.provider = Processing.getProviderFromName('script')
if self.algType == self.SCRIPT_R:
alg = RAlgorithm(None, unicode(self.editor.text()))
alg.provider = ModelerUtils.providers['r']
alg.provider = Processing.getProviderFromName('r')

dlg = alg.getCustomParametersDialog()
if not dlg:

0 comments on commit e6b76c4

Please sign in to comment.
You can’t perform that action at this time.