Skip to content
Permalink
Browse files
Refactor provider actions and remove from AlgorithmProvider
  • Loading branch information
nyalldawson committed Apr 7, 2017
1 parent 117260d commit 651355d569023c671f6c38065203d91c48115c02
@@ -38,6 +38,7 @@
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.tools.system import isWindows

from .RUtils import RUtils
@@ -52,6 +53,7 @@ class RAlgorithmProvider(AlgorithmProvider):
def __init__(self):
super().__init__()
self.algs = []
self.actions = []
self.actions.append(CreateNewScriptAction(
'Create new R script', CreateNewScriptAction.SCRIPT_R))
self.actions.append(GetRScriptsAction())
@@ -79,6 +81,7 @@ def load(self):
ProcessingConfig.addSetting(Setting(
self.name(),
RUtils.R_USE64, self.tr('Use 64 bit version'), False))
ProviderActions.registerProviderActions(self, self.actions)
return True

def unload(self):
@@ -88,6 +91,7 @@ def unload(self):
ProcessingConfig.removeSetting(RUtils.R_FOLDER)
ProcessingConfig.removeSetting(RUtils.R_LIBS_USER)
ProcessingConfig.removeSetting(RUtils.R_USE64)
ProviderActions.deregisterProviderActions(self)

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

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

class Processing(object):

actions = {}

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

@@ -81,7 +79,6 @@ def addProvider(provider):
if provider.load():
ProcessingConfig.readSettings()
provider.refreshAlgorithms()
Processing.actions[provider.id()] = provider.actions
Processing.contextMenuActions.extend(provider.contextMenuActions)
QgsApplication.processingRegistry().addProvider(provider)
PROVIDERS.append(provider)
@@ -102,8 +99,6 @@ def removeProvider(provider):
contributes a provider.
"""
provider.unload()
if provider.id() in Processing.actions:
del Processing.actions[provider.id()]
for act in provider.contextMenuActions:
Processing.contextMenuActions.remove(act)
QgsApplication.processingRegistry().removeProvider(provider.id())
@@ -47,6 +47,7 @@
from processing.gui.ConfigDialog import ConfigDialog
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import execute
from processing.gui.ProviderActions import ProviderActions

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
@@ -416,8 +417,8 @@ def populate(self):
groupItem.addChild(algItem)
count += 1

if self.provider.id() in Processing.actions:
actions = Processing.actions[self.provider.id()]
if self.provider.id() in ProviderActions.actions:
actions = ProviderActions.actions[self.provider.id()]
for action in actions:
if action.group in groups:
groupItem = groups[action.group]
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
ProviderActions.py
-------------------
Date : April 2017
Copyright : (C) 2017 by Nyall Dawson
Email : nyall dot dawson 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__ = 'Nyall Dawson'
__date__ = 'April 2017'
__copyright__ = '(C) 2017, Nyall Dason'


class ProviderActions(object):
actions = {}

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

@staticmethod
def deregisterProviderActions(provider):
""" Removes menu actions for a provider """
if provider.id() in ProviderActions.actions:
del ProviderActions.actions[provider.id()]
@@ -40,6 +40,7 @@
from processing.modeler.DeleteModelAction import DeleteModelAction
from processing.modeler.AddModelFromFileAction import AddModelFromFileAction
from processing.gui.GetScriptsAndModels import GetModelsAction
from processing.gui.ProviderActions import ProviderActions

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

@@ -57,8 +58,12 @@ def load(self):
ProcessingConfig.addSetting(Setting(self.name(),
ModelerUtils.MODELS_FOLDER, self.tr('Models folder', 'ModelerAlgorithmProvider'),
ModelerUtils.defaultModelsFolder(), valuetype=Setting.MULTIPLE_FOLDERS))
ProviderActions.registerProviderActions(self, self.actions)
return True

def unload(self):
ProviderActions.deregisterProviderActions(self)

def modelsFolder(self):
return ModelerUtils.modelsFolders()[0]

@@ -37,6 +37,7 @@
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.script.CreateScriptCollectionPluginAction import CreateScriptCollectionPluginAction

pluginPath = os.path.split(os.path.dirname(__file__))[0]
@@ -48,11 +49,11 @@ def __init__(self):
super().__init__()
self.algs = []
self.folder_algorithms = []
self.actions.extend([CreateNewScriptAction('Create new script',
CreateNewScriptAction.SCRIPT_PYTHON),
AddScriptFromFileAction(),
GetScriptsAction(),
CreateScriptCollectionPluginAction()])
self.actions = [CreateNewScriptAction('Create new script',
CreateNewScriptAction.SCRIPT_PYTHON),
AddScriptFromFileAction(),
GetScriptsAction(),
CreateScriptCollectionPluginAction()]
self.contextMenuActions = \
[EditScriptAction(EditScriptAction.SCRIPT_PYTHON),
DeleteScriptAction(DeleteScriptAction.SCRIPT_PYTHON)]
@@ -63,10 +64,12 @@ def load(self):
ScriptUtils.SCRIPTS_FOLDER,
self.tr('Scripts folder', 'ScriptAlgorithmProvider'),
ScriptUtils.defaultScriptsFolder(), valuetype=Setting.MULTIPLE_FOLDERS))
ProviderActions.registerProviderActions(self, self.actions)
return True

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

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

0 comments on commit 651355d

Please sign in to comment.