Skip to content
Permalink
Browse files
Also refactor provider context menu actions and remove from Algorithm…
…Provider
  • Loading branch information
nyalldawson committed Apr 7, 2017
1 parent 651355d commit 42a614154caae1fdbdd1a4dea6868c552c25ab41
@@ -38,7 +38,8 @@
from processing.gui.CreateNewScriptAction import CreateNewScriptAction
from processing.script.WrongScriptException import WrongScriptException
from processing.gui.GetScriptsAndModels import GetRScriptsAction
from processing.gui.ProviderActions import ProviderActions
from processing.gui.ProviderActions import (ProviderActions,
ProviderContextMenuActions)
from processing.tools.system import isWindows

from .RUtils import RUtils
@@ -82,6 +83,7 @@ def load(self):
self.name(),
RUtils.R_USE64, self.tr('Use 64 bit version'), False))
ProviderActions.registerProviderActions(self, self.actions)
ProviderContextMenuActions.registerProviderContextMenuActions(self.contextMenuActions)
return True

def unload(self):
@@ -92,6 +94,7 @@ def unload(self):
ProcessingConfig.removeSetting(RUtils.R_LIBS_USER)
ProcessingConfig.removeSetting(RUtils.R_USE64)
ProviderActions.deregisterProviderActions(self)
ProviderContextMenuActions.deregisterProviderContextMenuActions(self.contextMenuActions)

def isActive(self):
return ProcessingConfig.getSetting('ACTIVATE_R')
@@ -39,4 +39,3 @@ class AlgorithmProvider(QgsProcessingProvider):

def __init__(self):
super().__init__()
self.contextMenuActions = []
@@ -66,9 +66,6 @@

class Processing(object):

# All the registered context menu actions for the toolbox
contextMenuActions = []

@staticmethod
def addProvider(provider):
"""Use this method to add algorithms from external providers.
@@ -79,7 +76,6 @@ def addProvider(provider):
if provider.load():
ProcessingConfig.readSettings()
provider.refreshAlgorithms()
Processing.contextMenuActions.extend(provider.contextMenuActions)
QgsApplication.processingRegistry().addProvider(provider)
PROVIDERS.append(provider)
except:
@@ -99,8 +95,6 @@ def removeProvider(provider):
contributes a provider.
"""
provider.unload()
for act in provider.contextMenuActions:
Processing.contextMenuActions.remove(act)
QgsApplication.processingRegistry().removeProvider(provider.id())

@staticmethod
@@ -47,7 +47,8 @@
from processing.gui.ConfigDialog import ConfigDialog
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import execute
from processing.gui.ProviderActions import ProviderActions
from processing.gui.ProviderActions import (ProviderActions,
ProviderContextMenuActions)

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
@@ -216,7 +217,7 @@ def showPopupMenu(self, point):

if isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
data = item.alg if isinstance(item, TreeAlgorithmItem) else item.action
actions = Processing.contextMenuActions
actions = ProviderContextMenuActions.actions
if len(actions) > 0:
popupmenu.addSeparator()
for action in actions:
@@ -27,11 +27,28 @@ class ProviderActions(object):

@staticmethod
def registerProviderActions(provider, actions):
""" Adds menu actions for a provider """
""" Adds actions for a provider """
ProviderActions.actions[provider.id()] = actions

@staticmethod
def deregisterProviderActions(provider):
""" Removes menu actions for a provider """
""" Removes actions for a provider """
if provider.id() in ProviderActions.actions:
del ProviderActions.actions[provider.id()]


class ProviderContextMenuActions(object):

# All the registered context menu actions for the toolbox
actions = []

@staticmethod
def registerProviderContextMenuActions(actions):
""" Adds context menu actions for a provider """
ProviderContextMenuActions.actions.extend(actions)

@staticmethod
def deregisterProviderContextMenuActions(actions):
""" Removes context menu actions for a provider """
for act in actions:
ProviderContextMenuActions.actions.remove(act)
@@ -40,7 +40,8 @@
from processing.modeler.DeleteModelAction import DeleteModelAction
from processing.modeler.AddModelFromFileAction import AddModelFromFileAction
from processing.gui.GetScriptsAndModels import GetModelsAction
from processing.gui.ProviderActions import ProviderActions
from processing.gui.ProviderActions import (ProviderActions,
ProviderContextMenuActions)

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

@@ -59,10 +60,12 @@ def load(self):
ModelerUtils.MODELS_FOLDER, self.tr('Models folder', 'ModelerAlgorithmProvider'),
ModelerUtils.defaultModelsFolder(), valuetype=Setting.MULTIPLE_FOLDERS))
ProviderActions.registerProviderActions(self, self.actions)
ProviderContextMenuActions.registerProviderContextMenuActions(self.contextMenuActions)
return True

def unload(self):
ProviderActions.deregisterProviderActions(self)
ProviderContextMenuActions.deregisterProviderContextMenuActions(self.contextMenuActions)

def modelsFolder(self):
return ModelerUtils.modelsFolders()[0]
@@ -32,6 +32,7 @@
from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.preconfigured.NewPreconfiguredAlgorithmAction import NewPreconfiguredAlgorithmAction
from processing.preconfigured.DeletePreconfiguredAlgorithmAction import DeletePreconfiguredAlgorithmAction
from processing.gui.ProviderActions import ProviderContextMenuActions


class PreconfiguredAlgorithmProvider(AlgorithmProvider):
@@ -54,6 +55,12 @@ def loadAlgorithms(self):
for a in self.algs:
self.addAlgorithm(a)

def load(self):
ProviderContextMenuActions.registerProviderContextMenuActions(self.contextMenuActions)

def unload(self):
ProviderContextMenuActions.deregisterProviderContextMenuActions(self.contextMenuActions)

def id(self):
return 'preconfigured'

@@ -37,7 +37,8 @@
from processing.script.ScriptUtils import ScriptUtils
from processing.script.AddScriptFromFileAction import AddScriptFromFileAction
from processing.gui.GetScriptsAndModels import GetScriptsAction
from processing.gui.ProviderActions import ProviderActions
from processing.gui.ProviderActions import (ProviderActions,
ProviderContextMenuActions)
from processing.script.CreateScriptCollectionPluginAction import CreateScriptCollectionPluginAction

pluginPath = os.path.split(os.path.dirname(__file__))[0]
@@ -65,11 +66,13 @@ def load(self):
self.tr('Scripts folder', 'ScriptAlgorithmProvider'),
ScriptUtils.defaultScriptsFolder(), valuetype=Setting.MULTIPLE_FOLDERS))
ProviderActions.registerProviderActions(self, self.actions)
ProviderContextMenuActions.registerProviderContextMenuActions(self.contextMenuActions)
return True

def unload(self):
ProcessingConfig.addSetting(ScriptUtils.SCRIPTS_FOLDER)
ProviderActions.deregisterProviderActions(self)
ProviderContextMenuActions.deregisterProviderContextMenuActions(self.contextMenuActions)

def icon(self):
return QgsApplication.getThemeIcon("/processingScript.svg")

0 comments on commit 42a6141

Please sign in to comment.