Skip to content

Commit

Permalink
[processing] additional mechanism to add scripts from 3rd party plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed May 23, 2016
1 parent 33fc3be commit 2eebe0d
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 5 deletions.
4 changes: 1 addition & 3 deletions python/plugins/processing/ProcessingPlugin.py
Expand Up @@ -55,11 +55,9 @@ class ProcessingPlugin:


def __init__(self, iface): def __init__(self, iface):
self.iface = iface self.iface = iface

def initGui(self):

Processing.initialize() Processing.initialize()


def initGui(self):
self.commander = None self.commander = None
self.toolbox = ProcessingToolbox() self.toolbox = ProcessingToolbox()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox) self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
Expand Down
@@ -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 changes: 31 additions & 0 deletions python/plugins/processing/algs/examplescripts/__init__.py
@@ -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 changes: 18 additions & 0 deletions python/plugins/processing/algs/examplescripts/metadata.txt
@@ -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
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -222,6 +222,8 @@ def __init__(self):
from .ExecuteSQL import ExecuteSQL from .ExecuteSQL import ExecuteSQL
self.alglist.extend([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') folder = os.path.join(os.path.dirname(__file__), 'scripts')
scripts = ScriptUtils.loadFromFolder(folder) scripts = ScriptUtils.loadFromFolder(folder)
for script in scripts: for script in scripts:
Expand All @@ -246,7 +248,7 @@ def getIcon(self):
return self._icon return self._icon


def _loadAlgorithms(self): def _loadAlgorithms(self):
self.algs = self.alglist self.algs = list(self.alglist) + self.externalAlgs


def supportsNonFileBasedOutput(self): def supportsNonFileBasedOutput(self):
return True return True
26 changes: 25 additions & 1 deletion python/plugins/processing/core/Processing.py
Expand Up @@ -17,6 +17,7 @@
*************************************************************************** ***************************************************************************
""" """



__author__ = 'Victor Olaya' __author__ = 'Victor Olaya'
__date__ = 'August 2012' __date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya' __copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -26,6 +27,7 @@
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'


import sys import sys
import os
import traceback import traceback


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


import processing import processing
from processing.core.AlgorithmProvider import AlgorithmProvider 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.ProcessingConfig import ProcessingConfig
from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
Expand Down Expand Up @@ -73,7 +78,7 @@ class Processing:
contextMenuActions = [] contextMenuActions = []


@staticmethod @staticmethod
def addProvider(provider, update=True): def addProvider(provider, updateList=True):
"""Use this method to add algorithms from external providers. """Use this method to add algorithms from external providers.
""" """


Expand Down Expand Up @@ -122,13 +127,32 @@ def getProviderFromName(name):


@staticmethod @staticmethod
def initialize(): def initialize():
if Processing.providers:
return
# Add the basic providers # Add the basic providers
for c in AlgorithmProvider.__subclasses__(): for c in AlgorithmProvider.__subclasses__():
Processing.addProvider(c()) Processing.addProvider(c())
# And initialize # And initialize
ProcessingConfig.initialize() ProcessingConfig.initialize()
ProcessingConfig.readSettings() ProcessingConfig.readSettings()
RenderingStyles.loadStyles() 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 @staticmethod
def updateAlgsList(): def updateAlgsList():
Expand Down

0 comments on commit 2eebe0d

Please sign in to comment.