mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
[processing] additional mechanism to add scripts from 3rd party plugin
This commit is contained in:
parent
33fc3be15f
commit
2eebe0d314
@ -55,11 +55,9 @@ class ProcessingPlugin:
|
||||
|
||||
def __init__(self, iface):
|
||||
self.iface = iface
|
||||
|
||||
def initGui(self):
|
||||
|
||||
Processing.initialize()
|
||||
|
||||
def initGui(self):
|
||||
self.commander = None
|
||||
self.toolbox = ProcessingToolbox()
|
||||
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
|
||||
|
@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
__init__.py
|
||||
---------------------
|
||||
Date : May 2016
|
||||
Copyright : (C) 2016 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__ = 'May 2016'
|
||||
__copyright__ = '(C) 2016, Victor Olaya'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from processing.core.Processing import Processing
|
||||
|
||||
class ProcessingExampleScriptsPlugin:
|
||||
|
||||
def initGui(self):
|
||||
Processing.addScripts(self, os.path.dirname(__file__))
|
||||
|
||||
def unload(self):
|
||||
pass
|
31
python/plugins/processing/algs/examplescripts/__init__.py
Normal file
31
python/plugins/processing/algs/examplescripts/__init__.py
Normal file
@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
__init__.py
|
||||
---------------------
|
||||
Date : July 2013
|
||||
Copyright : (C) 2013 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. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from .ProcessingExampleScriptsPlugin import ProcessingExampleScriptsPlugin
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'July 2013'
|
||||
__copyright__ = '(C) 2013, Victor Olaya'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
|
||||
def classFactory(iface):
|
||||
return ProcessingExampleScriptsPlugin()
|
@ -0,0 +1,3 @@
|
||||
##text=string
|
||||
|
||||
print text
|
18
python/plugins/processing/algs/examplescripts/metadata.txt
Normal file
18
python/plugins/processing/algs/examplescripts/metadata.txt
Normal file
@ -0,0 +1,18 @@
|
||||
[general]
|
||||
name=Processing Example Scripts
|
||||
description=An example plugin that adds algorithms to Processing as plugins
|
||||
category=Analysis
|
||||
version=1.0
|
||||
qgisMinimumVersion=2.0
|
||||
|
||||
author=Victor Olaya
|
||||
email=volayaf@gmail.com
|
||||
|
||||
tags=analysis,processing
|
||||
|
||||
homepage=
|
||||
tracker=
|
||||
repository=
|
||||
|
||||
experimental=False
|
||||
deprecated=False
|
@ -222,6 +222,8 @@ class QGISAlgorithmProvider(AlgorithmProvider):
|
||||
from .ExecuteSQL import ExecuteSQL
|
||||
self.alglist.extend([ExecuteSQL()])
|
||||
|
||||
self.externalAlgs = [] #to store algs added by 3rd party plugins as scripts
|
||||
|
||||
folder = os.path.join(os.path.dirname(__file__), 'scripts')
|
||||
scripts = ScriptUtils.loadFromFolder(folder)
|
||||
for script in scripts:
|
||||
@ -246,7 +248,7 @@ class QGISAlgorithmProvider(AlgorithmProvider):
|
||||
return self._icon
|
||||
|
||||
def _loadAlgorithms(self):
|
||||
self.algs = self.alglist
|
||||
self.algs = list(self.alglist) + self.externalAlgs
|
||||
|
||||
def supportsNonFileBasedOutput(self):
|
||||
return True
|
||||
|
@ -17,6 +17,7 @@
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'August 2012'
|
||||
__copyright__ = '(C) 2012, Victor Olaya'
|
||||
@ -26,6 +27,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import sys
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from qgis.PyQt.QtCore import Qt, QCoreApplication, QObject, pyqtSignal
|
||||
@ -37,6 +39,9 @@ from qgis.core import QgsMessageLog
|
||||
|
||||
import processing
|
||||
from processing.core.AlgorithmProvider import AlgorithmProvider
|
||||
from processing.script.ScriptUtils import ScriptUtils
|
||||
from processing.gui import AlgorithmClassification
|
||||
from processing.modeler.ModelerUtils import ModelerUtils
|
||||
from processing.core.ProcessingConfig import ProcessingConfig
|
||||
from processing.core.GeoAlgorithm import GeoAlgorithm
|
||||
from processing.core.ProcessingLog import ProcessingLog
|
||||
@ -73,7 +78,7 @@ class Processing:
|
||||
contextMenuActions = []
|
||||
|
||||
@staticmethod
|
||||
def addProvider(provider, update=True):
|
||||
def addProvider(provider, updateList=True):
|
||||
"""Use this method to add algorithms from external providers.
|
||||
"""
|
||||
|
||||
@ -122,6 +127,8 @@ class Processing:
|
||||
|
||||
@staticmethod
|
||||
def initialize():
|
||||
if Processing.providers:
|
||||
return
|
||||
# Add the basic providers
|
||||
for c in AlgorithmProvider.__subclasses__():
|
||||
Processing.addProvider(c())
|
||||
@ -129,6 +136,23 @@ class Processing:
|
||||
ProcessingConfig.initialize()
|
||||
ProcessingConfig.readSettings()
|
||||
RenderingStyles.loadStyles()
|
||||
|
||||
@staticmethod
|
||||
def addScripts(folder):
|
||||
Processing.initialize()
|
||||
provider = Processing.getProviderFromName("qgis")
|
||||
scripts = ScriptUtils.loadFromFolder(folder)
|
||||
print scripts
|
||||
for script in scripts:
|
||||
script.allowEdit = False
|
||||
script._icon = provider._icon
|
||||
script.provider = provider
|
||||
provider.externalAlgs.extend(scripts)
|
||||
Processing.reloadProvider("qgis")
|
||||
|
||||
@staticmethod
|
||||
def removeScripts(folder):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def updateAlgsList():
|
||||
|
Loading…
x
Reference in New Issue
Block a user