Skip to content
Permalink
Browse files

Merge pull request #3038 from volaya/provider_add_remove

[processing] different approach for provider add/remove
  • Loading branch information
alexbruy committed Apr 27, 2016
2 parents c96f66e + bee4068 commit 87575bd843249c3dfd1f4ce0ef52a6dd8ca04f85
@@ -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 = {}
@@ -27,11 +27,17 @@

import os

from PyQt.QtCore import QPyNullVariant, QCoreApplication, QSettings
from PyQt.QtCore import QPyNullVariant, QCoreApplication, QSettings, QObject, pyqtSignal
from PyQt.QtGui import QIcon
from processing.tools.system import defaultOutputFolder
import processing.tools.dataobjects

class SettingsWatcher(QObject):

settingsChanged = pyqtSignal()

settingsWatcher = SettingsWatcher()


class ProcessingConfig:

@@ -48,8 +48,9 @@
from qgis.gui import QgsDoubleSpinBox
from qgis.gui import QgsSpinBox

from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingConfig import Setting
from processing.core.ProcessingConfig import (ProcessingConfig,
settingsWatcher,
Setting)
from processing.core.Processing import Processing
from processing.gui.menus import updateMenus
from processing.gui.menus import menusSettingsGroup
@@ -249,6 +250,7 @@ def accept(self):
return
setting.save()
Processing.updateAlgsList()
settingsWatcher.settingsChanged.emit()
updateMenus()

QDialog.accept(self)
@@ -34,9 +34,9 @@
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.core.ProcessingConfig import ProcessingConfig, settingsWatcher
from processing.gui.MessageDialog import MessageDialog
from processing.gui import AlgorithmClassification
from processing.gui.AlgorithmDialog import AlgorithmDialog
@@ -53,8 +53,6 @@

class ProcessingToolbox(BASE, WIDGET):

updateAlgList = True

def __init__(self):
super(ProcessingToolbox, self).__init__(None)
self.tipWasClosed = False
@@ -83,6 +81,10 @@ def openSettings(url):

self.fillTree()

algListWatcher.providerRemoved.connect(self.removeProvider)
algListWatcher.providerAdded.connect(self.addProvider)
settingsWatcher.settingsChanged.connect(self.fillTree)

def showDisabled(self):
self.txtDisabled.setVisible(False)
for providerName in self.disabledWithMatchingAlgs:
@@ -154,27 +156,26 @@ 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):
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 updateProvider(self, providerName, updateAlgsList=True):
if updateAlgsList:
self.updateAlgList = False
Processing.updateAlgsList()
self.updateAlgList = True
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 +305,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 87575bd

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