mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Refactor provider actions and remove from AlgorithmProvider
This commit is contained in:
parent
117260dcf3
commit
651355d569
@ -38,6 +38,7 @@ from processing.gui.DeleteScriptAction import DeleteScriptAction
|
||||
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 @@ class RAlgorithmProvider(AlgorithmProvider):
|
||||
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 @@ class RAlgorithmProvider(AlgorithmProvider):
|
||||
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 @@ PROVIDERS = []
|
||||
|
||||
class Processing(object):
|
||||
|
||||
actions = {}
|
||||
|
||||
# All the registered context menu actions for the toolbox
|
||||
contextMenuActions = []
|
||||
|
||||
@ -81,7 +79,6 @@ class Processing(object):
|
||||
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 @@ class Processing(object):
|
||||
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.EditRenderingStylesDialog import EditRenderingStylesDialog
|
||||
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 @@ class TreeProviderItem(QTreeWidgetItem):
|
||||
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]
|
||||
|
37
python/plugins/processing/gui/ProviderActions.py
Normal file
37
python/plugins/processing/gui/ProviderActions.py
Normal file
@ -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.CreateNewModelAction import CreateNewModelAction
|
||||
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 @@ class ModelerAlgorithmProvider(AlgorithmProvider):
|
||||
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.gui.CreateNewScriptAction import CreateNewScriptAction
|
||||
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 @@ class ScriptAlgorithmProvider(AlgorithmProvider):
|
||||
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 @@ class ScriptAlgorithmProvider(AlgorithmProvider):
|
||||
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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user