Skip to content
Permalink
Browse files

[processing] separated alglist to its own module

  • Loading branch information
volaya committed May 19, 2016
1 parent 9a5c583 commit 33fc3be15f20ccb397640a785aecd27f496ca4bd
Showing with 172 additions and 120 deletions.
  1. +3 −4 python/plugins/processing/ProcessingPlugin.py
  2. +26 −38 python/plugins/processing/core/Processing.py
  3. +79 −0 python/plugins/processing/core/alglist.py
  4. +0 −13 python/plugins/processing/core/defaultproviders.py
  5. +3 −4 python/plugins/processing/gui/CommanderWindow.py
  6. +0 −8 python/plugins/processing/gui/ContextAction.py
  7. +3 −2 python/plugins/processing/gui/CreateNewScriptAction.py
  8. +3 −3 python/plugins/processing/gui/DeleteScriptAction.py
  9. +3 −3 python/plugins/processing/gui/EditScriptAction.py
  10. +7 −7 python/plugins/processing/gui/GetScriptsAndModels.py
  11. +9 −8 python/plugins/processing/gui/ProcessingToolbox.py
  12. +3 −3 python/plugins/processing/gui/ScriptEditorDialog.py
  13. +5 −4 python/plugins/processing/gui/menus.py
  14. +2 −1 python/plugins/processing/modeler/AddModelFromFileAction.py
  15. +2 −1 python/plugins/processing/modeler/CreateNewModelAction.py
  16. +2 −2 python/plugins/processing/modeler/DeleteModelAction.py
  17. +2 −2 python/plugins/processing/modeler/EditModelAction.py
  18. +4 −5 python/plugins/processing/modeler/ModelerAlgorithm.py
  19. +5 −5 python/plugins/processing/modeler/ModelerDialog.py
  20. +2 −2 python/plugins/processing/preconfigured/DeletePreconfiguredAlgorithmAction.py
  21. +2 −2 python/plugins/processing/preconfigured/PreconfiguredAlgorithm.py
  22. +4 −1 python/plugins/processing/preconfigured/PreconfiguredAlgorithmDialog.py
  23. +2 −1 python/plugins/processing/script/AddScriptFromFileAction.py
  24. +1 −1 python/plugins/processing/tools/general.py
@@ -43,8 +43,7 @@
from processing.modeler.ModelerDialog import ModelerDialog
from processing.tools.system import tempFolder
from processing.gui.menus import removeMenus, initializeMenus, createMenus
from processing.core.defaultproviders import loadDefaultProviders

from processing.core.alglist import algList


cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
@@ -58,7 +57,7 @@ def __init__(self, iface):
self.iface = iface

def initGui(self):
loadDefaultProviders()

Processing.initialize()

self.commander = None
@@ -163,7 +162,7 @@ def openModeler(self):
dlg = ModelerDialog()
dlg.exec_()
if dlg.update:
self.toolbox.updateProvider('model')
algList.reloadProvider('model')

def openResults(self):
dlg = ResultsDialog()
@@ -45,26 +45,28 @@
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.gui.AlgorithmExecutor import runalg
from processing.tools import dataobjects


class AlgListWatcher(QObject):

providerAdded = pyqtSignal(str)
providerRemoved = pyqtSignal(str)

algListWatcher = AlgListWatcher()

from processing.core.alglist import algList

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

class Processing:

listeners = []
providers = []

# A dictionary of algorithms. Keys are names of providers
# and values are list with all algorithms from that provider
algs = {}

# Same structure as algs
# Same structure as algs in algList
actions = {}

# All the registered context menu actions for the toolbox
@@ -75,17 +77,16 @@ def addProvider(provider, update=True):
"""Use this method to add algorithms from external providers.
"""

if provider.getName() in [p.getName for p in Processing.providers]:
if provider.getName() in [p.getName for p in algList.providers]:
return
try:
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.readSettings()
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())
algList.addProvider(provider)
except:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
@@ -103,8 +104,10 @@ def removeProvider(provider):
try:
provider.unload()
Processing.providers.remove(provider)
del Processing.algs[provider.getName()]
algListWatcher.providerRemoved.emit(provider.getName())
algList.remove(provider.getName())
del Processing.actions[provider.getName()]
for act in provider.contextMenuActions:
Processing.contextMenuActions.remove(act)
except:
# This try catch block is here to avoid problems if the
# plugin with a provider is unloaded after the Processing
@@ -115,10 +118,7 @@ def removeProvider(provider):
@staticmethod
def getProviderFromName(name):
"""Returns the provider with the given name."""
for provider in Processing.providers:
if provider.getName() == name:
return provider
return Processing.modeler
return algList.getProviderFromName(name)

@staticmethod
def initialize():
@@ -143,27 +143,15 @@ def updateAlgsList():

@staticmethod
def reloadProvider(providerName):
for p in Processing.providers:
if p.getName() == providerName:
p.loadAlgorithms()
Processing.algs[
p.getName()] = {a.commandLineName(): a for a in p.algs}

algList.reloadProvider(providerName)

@staticmethod
def getAlgorithm(name):
for provider in Processing.algs.values():
if name in provider:
return provider[name]
return None
return algList.getAlgorithm(name)

@staticmethod
def getAlgorithmFromFullName(name):
for provider in Processing.algs.values():
for alg in provider.values():
if alg.name == name:
return alg
return None
return algList.getAlgorithmFromFullName(name)

@staticmethod
def getObject(uri):
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
Processing.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from qgis.PyQt.QtCore import QObject, pyqtSignal

class AlgorithmList(QObject):

providerAdded = pyqtSignal(str)
providerRemoved = pyqtSignal(str)
providerUpdated = pyqtSignal(str)

# A dictionary of algorithms. Keys are names of providers
# and values are list with all algorithms from that provider
algs = {}

providers = []

def removeProvider(self, providerName):
for p in self.providers:
if p.getName() == providerName:
self.providers.remove(p)
break
self.algs.remove(providerName)
self.providerRemoved.emit(providerName)

def reloadProvider(self, providerName):
for p in self.providers:
if p.getName() == providerName:
p.loadAlgorithms()
self.algs[p.getName()] = {a.commandLineName(): a for a in p.algs}
self.providerUpdated.emit(p.getName())
break

def addProvider(self, provider):
self.providers.append(provider)
self.algs[provider.getName()] = {a.commandLineName(): a for a in provider.algs}
self.providerAdded.emit(provider.getName())

def getProviderFromName(self, name):
for provider in self.providers:
if provider.getName() == name:
return provider

def getAlgorithm(self, name):
for provider in self.algs.values():
if name in provider:
return provider[name]

def getAlgorithmFromFullName(self, name):
for provider in self.algs.values():
for alg in provider.values():
if alg.name == name:
return alg

algList = AlgorithmList()
@@ -26,19 +26,6 @@
__revision__ = '$Format:%H$'


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

def loadDefaultProviders():
# this is here just to "trigger" the above imports so providers are loaded
@@ -32,6 +32,7 @@
from qgis.PyQt.QtCore import QSortFilterProxyModel
from qgis.utils import iface
from processing.core.Processing import Processing
from processing.core.alglist import algList
from processing.gui.MessageDialog import MessageDialog
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.tools.system import userFolder, mkdir
@@ -99,9 +100,7 @@ def fillCombo(self):
self.combo.clear()

# Add algorithms
for providerName in Processing.algs.keys():
provider = Processing.algs[providerName]
algs = provider.values()
for algs in algList.algs.values():
for alg in algs:
self.combo.addItem('Processing algorithm: ' + alg.name)

@@ -111,7 +110,7 @@ def fillCombo(self):
types.FunctionType):
self.combo.addItem('Command: ' + command)

#Add menu entries
# Add menu entries
menuActions = []
actions = iface.mainWindow().menuBar().actions()
for action in actions:
@@ -35,14 +35,6 @@ def setData(self, itemData, toolbox):
self.itemData = itemData
self.toolbox = toolbox

def updateToolbox(self):
'''
Updates the list of algorithms and then the toolbox.
It only update the item corresponding to the provider of the algorithm.
To be called after the action is executed, if needed
'''
self.toolbox.updateProvider(self.alg.provider.getName())

def tr(self, string, context=''):
if context == '':
context = 'ContextAction'
@@ -31,6 +31,7 @@

from processing.gui.ToolboxAction import ToolboxAction
from processing.gui.ScriptEditorDialog import ScriptEditorDialog
from processing.core.alglist import algList

pluginPath = os.path.split(os.path.dirname(__file__))[0]

@@ -62,6 +63,6 @@ def execute(self):
dlg.exec_()
if dlg.update:
if self.scriptType == self.SCRIPT_PYTHON:
self.toolbox.updateProvider('script')
algList.reloadProvider('script')
elif self.scriptType == self.SCRIPT_R:
self.toolbox.updateProvider('r')
algList.reloadProvider('r')
@@ -33,7 +33,7 @@

from processing.algs.r.RAlgorithm import RAlgorithm
from processing.script.ScriptAlgorithm import ScriptAlgorithm

from processing.core.alglist import algList

class DeleteScriptAction(ContextAction):

@@ -60,6 +60,6 @@ def execute(self):
if reply == QMessageBox.Yes:
os.remove(self.itemData.descriptionFile)
if self.scriptType == self.SCRIPT_PYTHON:
self.toolbox.updateProvider('script')
algList.reloadProvider('script')
elif self.scriptType == self.SCRIPT_R:
self.toolbox.updateProvider('r')
algList.reloadProvider('r')
@@ -29,7 +29,7 @@
from processing.gui.ScriptEditorDialog import ScriptEditorDialog
from processing.algs.r.RAlgorithm import RAlgorithm
from processing.script.ScriptAlgorithm import ScriptAlgorithm

from processing.core.alglist import algList

class EditScriptAction(ContextAction):

@@ -52,6 +52,6 @@ def execute(self):
dlg.exec_()
if dlg.update:
if self.scriptType == ScriptEditorDialog.SCRIPT_PYTHON:
self.toolbox.updateProvider('script')
algList.reloadProvider('script')
elif self.scriptType == ScriptEditorDialog.SCRIPT_R:
self.toolbox.updateProvider('r')
algList.reloadProvider('r')
@@ -64,8 +64,8 @@ def getIcon(self):
def execute(self):
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.SCRIPTS)
dlg.exec_()
if dlg.updateToolbox:
self.toolbox.updateProvider('script')
if dlg.updateProvider:
algList.reloadProvider('script')


class GetRScriptsAction(ToolboxAction):
@@ -80,7 +80,7 @@ def getIcon(self):
def execute(self):
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.RSCRIPTS)
dlg.exec_()
if dlg.updateToolbox:
if dlg.updateProvider:
self.toolbox.updateProvider('r')


@@ -96,8 +96,8 @@ def getIcon(self):
def execute(self):
dlg = GetScriptsAndModelsDialog(GetScriptsAndModelsDialog.MODELS)
dlg.exec_()
if dlg.updateToolbox:
self.toolbox.updateProvider('model')
if dlg.updateProvider:
algList.reloadProvider('model')


class GetScriptsAndModelsDialog(BASE, WIDGET):
@@ -141,7 +141,7 @@ def __init__(self, resourceType):
self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg'))

self.lastSelectedItem = None
self.updateToolbox = False
self.updateProvider = False
self.populateTree()
self.buttonBox.accepted.connect(self.okPressed)
self.buttonBox.rejected.connect(self.cancelPressed)
@@ -305,7 +305,7 @@ def okPressed(self):
if os.path.exists(path):
os.remove(path)

self.updateToolbox = len(toDownload) + len(toDelete) > 0
self.updateProvider = len(toDownload) + len(toDelete) > 0
super(GetScriptsAndModelsDialog, self).accept()


0 comments on commit 33fc3be

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