Skip to content
Permalink
Browse files

[processing] different approach for provider add/remove

  • Loading branch information
volaya committed Apr 27, 2016
1 parent 8a9cb05 commit f33749ab9d281f17366db6052a5231d677f623d2
@@ -62,7 +62,6 @@ def initGui(self):
self.toolbox = ProcessingToolbox()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.toolbox)
self.toolbox.hide()
Processing.addAlgListListener(self.toolbox)

self.menu = QMenu(self.iface.mainWindow().menuBar())
self.menu.setObjectName('processing')
@@ -147,7 +146,6 @@ def openCommander(self):
self.commander = CommanderWindow(
self.iface.mainWindow(),
self.iface.mapCanvas())
Processing.addAlgListListener(self.commander)
self.commander.prepareGui()
self.commander.show()

@@ -28,7 +28,7 @@
import sys
import traceback

from PyQt.QtCore import Qt, QCoreApplication
from PyQt.QtCore import Qt, QCoreApplication, QObject, pyqtSignal
from PyQt.QtWidgets import QApplication
from PyQt.QtGui import QCursor

@@ -61,6 +61,12 @@

from processing.tools import dataobjects

class AlgListWatcher(QObject):

providerAdded = pyqtSignal(str)
providerRemoved = pyqtSignal(str)

algListWatcher = AlgListWatcher()

class Processing:

@@ -93,6 +99,7 @@ def addProvider(provider, updateList=True):
ProcessingConfig.readSettings()
if updateList:
Processing.updateAlgsList()
algListWatcher.providerAdded.emit(provider.getName())
except:
ProcessingLog.addToLog(
ProcessingLog.LOG_ERROR,
@@ -111,7 +118,7 @@ def removeProvider(provider):
provider.unload()
Processing.providers.remove(provider)
del Processing.algs[provider.getName()]
Processing.fireAlgsListHasChanged()
algListWatcher.providerRemoved.emit(provider.getName())
except:
# This try catch block is here to avoid problems if the
# plugin with a provider is unloaded after the Processing
@@ -151,8 +158,6 @@ def initialize():
ProcessingConfig.readSettings()
RenderingStyles.loadStyles()
Processing.loadFromProviders()
# Inform registered listeners that all providers' algorithms have been loaded
Processing.fireAlgsListHasChanged()

@staticmethod
def updateAlgsList():
@@ -162,7 +167,6 @@ def updateAlgsList():
"""
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
Processing.loadFromProviders()
Processing.fireAlgsListHasChanged()
QApplication.restoreOverrideCursor()

@staticmethod
@@ -177,28 +181,6 @@ def updateProviders():
for provider in providers:
provider.loadAlgorithms()

@staticmethod
def addAlgListListener(listener):
"""
Listener should implement a algsListHasChanged() method.
Whenever the list of algorithms changes, that method will be
called for all registered listeners.
"""
Processing.listeners.append(listener)

@staticmethod
def removeAlgListListener(listener):
try:
Processing.listeners.remove(listener)
except:
pass

@staticmethod
def fireAlgsListHasChanged():
for listener in Processing.listeners:
listener.algsListHasChanged()

@staticmethod
def loadAlgorithms():
Processing.algs = {}
@@ -34,7 +34,7 @@
from qgis.utils import iface

from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.Processing import Processing
from processing.core.Processing import Processing, algListWatcher
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
from processing.gui.MessageDialog import MessageDialog
@@ -83,6 +83,9 @@ def openSettings(url):

self.fillTree()

algListWatcher.providerRemoved.connect(self.removeProvider)
algListWatcher.providerAdded.connect(self.addProvider)

def showDisabled(self):
self.txtDisabled.setVisible(False)
for providerName in self.disabledWithMatchingAlgs:
@@ -154,27 +157,31 @@ def activateProvider(self, providerName):
QMessageBox.warning(self, "Activate provider",
"The provider has been activated, but it might need additional configuration.")

def algsListHasChanged(self):
if self.updateAlgList:
self.fillTree()
self.textChanged()

def updateProvider(self, providerName, updateAlgsList=True):
if updateAlgsList:
self.updateAlgList = False
Processing.updateAlgsList()
self.updateAlgList = True
item = self._providerItem(providerName)
if item is not None:
item.refresh()
item.sortChildren(0, Qt.AscendingOrder)
for i in xrange(item.childCount()):
item.child(i).sortChildren(0, Qt.AscendingOrder)
self.addRecentAlgorithms(True)

def removeProvider(self, providerName):
item = self._providerItem(providerName)
if item is not None:
self.algorithmTree.invisibleRootItem().removeChild(item)

def _providerItem(self, providerName):
for i in xrange(self.algorithmTree.invisibleRootItem().childCount()):
child = self.algorithmTree.invisibleRootItem().child(i)
if isinstance(child, TreeProviderItem):
if child.providerName == providerName:
child.refresh()
# sort categories and items in categories
child.sortChildren(0, Qt.AscendingOrder)
for i in xrange(child.childCount()):
child.child(i).sortChildren(0, Qt.AscendingOrder)
break
self.addRecentAlgorithms(True)
return child

def showPopupMenu(self, point):
item = self.algorithmTree.itemAt(point)
@@ -304,6 +311,24 @@ def addRecentAlgorithms(self, updating):

self.algorithmTree.setWordWrap(True)

def addProvider(self, providerName):
name = 'ACTIVATE_' + providerName.upper().replace(' ', '_')
providerItem = TreeProviderItem(providerName, None, self)
if ProcessingConfig.getSetting(name):
providerItem.setHidden(providerItem.childCount() == 0)
else:
providerItem = TreeProviderItem(providerName, None, self)
providerItem.setHidden(True)
self.disabledProviderItems[providerName] = providerItem

for i in xrange(self.algorithmTree.invisibleRootItem().childCount()):
child = self.algorithmTree.invisibleRootItem().child(i)
if isinstance(child, TreeProviderItem):
if child.text(0) > providerItem.text(0):
break
self.algorithmTree.insertTopLevelItem(i, providerItem)


def fillTreeUsingProviders(self):
self.algorithmTree.clear()
self.disabledProviderItems = {}

0 comments on commit f33749a

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