Skip to content

Commit 2eebe0d

Browse files
committed
[processing] additional mechanism to add scripts from 3rd party plugin
1 parent 33fc3be commit 2eebe0d

File tree

7 files changed

+119
-5
lines changed

7 files changed

+119
-5
lines changed

python/plugins/processing/ProcessingPlugin.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ class ProcessingPlugin:
5555

5656
def __init__(self, iface):
5757
self.iface = iface
58-
59-
def initGui(self):
60-
6158
Processing.initialize()
6259

60+
def initGui(self):
6361
self.commander = None
6462
self.toolbox = ProcessingToolbox()
6563
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
__init__.py
6+
---------------------
7+
Date : May 2016
8+
Copyright : (C) 2016 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Victor Olaya'
21+
__date__ = 'May 2016'
22+
__copyright__ = '(C) 2016, Victor Olaya'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
from processing.core.Processing import Processing
31+
32+
class ProcessingExampleScriptsPlugin:
33+
34+
def initGui(self):
35+
Processing.addScripts(self, os.path.dirname(__file__))
36+
37+
def unload(self):
38+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
__init__.py
6+
---------------------
7+
Date : July 2013
8+
Copyright : (C) 2013 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
from .ProcessingExampleScriptsPlugin import ProcessingExampleScriptsPlugin
20+
21+
__author__ = 'Victor Olaya'
22+
__date__ = 'July 2013'
23+
__copyright__ = '(C) 2013, Victor Olaya'
24+
25+
# This will get replaced with a git SHA1 when you do a git archive
26+
27+
__revision__ = '$Format:%H$'
28+
29+
30+
def classFactory(iface):
31+
return ProcessingExampleScriptsPlugin()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
##text=string
2+
3+
print text
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[general]
2+
name=Processing Example Scripts
3+
description=An example plugin that adds algorithms to Processing as plugins
4+
category=Analysis
5+
version=1.0
6+
qgisMinimumVersion=2.0
7+
8+
author=Victor Olaya
9+
email=volayaf@gmail.com
10+
11+
tags=analysis,processing
12+
13+
homepage=
14+
tracker=
15+
repository=
16+
17+
experimental=False
18+
deprecated=False

python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ def __init__(self):
222222
from .ExecuteSQL import ExecuteSQL
223223
self.alglist.extend([ExecuteSQL()])
224224

225+
self.externalAlgs = [] #to store algs added by 3rd party plugins as scripts
226+
225227
folder = os.path.join(os.path.dirname(__file__), 'scripts')
226228
scripts = ScriptUtils.loadFromFolder(folder)
227229
for script in scripts:
@@ -246,7 +248,7 @@ def getIcon(self):
246248
return self._icon
247249

248250
def _loadAlgorithms(self):
249-
self.algs = self.alglist
251+
self.algs = list(self.alglist) + self.externalAlgs
250252

251253
def supportsNonFileBasedOutput(self):
252254
return True

python/plugins/processing/core/Processing.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************
1818
"""
1919

20+
2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
2223
__copyright__ = '(C) 2012, Victor Olaya'
@@ -26,6 +27,7 @@
2627
__revision__ = '$Format:%H$'
2728

2829
import sys
30+
import os
2931
import traceback
3032

3133
from qgis.PyQt.QtCore import Qt, QCoreApplication, QObject, pyqtSignal
@@ -37,6 +39,9 @@
3739

3840
import processing
3941
from processing.core.AlgorithmProvider import AlgorithmProvider
42+
from processing.script.ScriptUtils import ScriptUtils
43+
from processing.gui import AlgorithmClassification
44+
from processing.modeler.ModelerUtils import ModelerUtils
4045
from processing.core.ProcessingConfig import ProcessingConfig
4146
from processing.core.GeoAlgorithm import GeoAlgorithm
4247
from processing.core.ProcessingLog import ProcessingLog
@@ -73,7 +78,7 @@ class Processing:
7378
contextMenuActions = []
7479

7580
@staticmethod
76-
def addProvider(provider, update=True):
81+
def addProvider(provider, updateList=True):
7782
"""Use this method to add algorithms from external providers.
7883
"""
7984

@@ -122,13 +127,32 @@ def getProviderFromName(name):
122127

123128
@staticmethod
124129
def initialize():
130+
if Processing.providers:
131+
return
125132
# Add the basic providers
126133
for c in AlgorithmProvider.__subclasses__():
127134
Processing.addProvider(c())
128135
# And initialize
129136
ProcessingConfig.initialize()
130137
ProcessingConfig.readSettings()
131138
RenderingStyles.loadStyles()
139+
140+
@staticmethod
141+
def addScripts(folder):
142+
Processing.initialize()
143+
provider = Processing.getProviderFromName("qgis")
144+
scripts = ScriptUtils.loadFromFolder(folder)
145+
print scripts
146+
for script in scripts:
147+
script.allowEdit = False
148+
script._icon = provider._icon
149+
script.provider = provider
150+
provider.externalAlgs.extend(scripts)
151+
Processing.reloadProvider("qgis")
152+
153+
@staticmethod
154+
def removeScripts(folder):
155+
pass
132156

133157
@staticmethod
134158
def updateAlgsList():

0 commit comments

Comments
 (0)