Skip to content

Commit

Permalink
Also refactor provider context menu actions and remove from Algorithm…
Browse files Browse the repository at this point in the history
…Provider
  • Loading branch information
nyalldawson committed Apr 7, 2017
1 parent 651355d commit 42a6141
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/r/RAlgorithmProvider.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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')
Expand Down
1 change: 0 additions & 1 deletion python/plugins/processing/core/AlgorithmProvider.py
Expand Up @@ -39,4 +39,3 @@ class AlgorithmProvider(QgsProcessingProvider):

def __init__(self):
super().__init__()
self.contextMenuActions = []
6 changes: 0 additions & 6 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions python/plugins/processing/gui/ProviderActions.py
Expand Up @@ -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)
Expand Up @@ -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]

Expand All @@ -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]
Expand Down
Expand Up @@ -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):
Expand All @@ -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'

Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/script/ScriptAlgorithmProvider.py
Expand Up @@ -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]
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 42a6141

Please sign in to comment.