Skip to content
Permalink
Browse files

[processing] additional mechanism to add scripts from 3rd party plugin

  • Loading branch information
volaya committed May 23, 2016
1 parent 33fc3be commit 2eebe0d3149a1c092e31208279574d0fa63e09a8
@@ -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
@@ -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
@@ -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 @@ def __init__(self):
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 @@ def getIcon(self):
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 @@
__revision__ = '$Format:%H$'

import sys
import os
import traceback

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

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,13 +127,32 @@ def getProviderFromName(name):

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

0 comments on commit 2eebe0d

Please sign in to comment.
You can’t perform that action at this time.