mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Merge pull request #3038 from volaya/provider_add_remove
[processing] different approach for provider add/remove
This commit is contained in:
commit
87575bd843
@ -62,7 +62,6 @@ class ProcessingPlugin:
|
||||
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 @@ class ProcessingPlugin:
|
||||
self.commander = CommanderWindow(
|
||||
self.iface.mainWindow(),
|
||||
self.iface.mapCanvas())
|
||||
Processing.addAlgListListener(self.commander)
|
||||
self.commander.prepareGui()
|
||||
self.commander.show()
|
||||
|
||||
|
@ -28,7 +28,7 @@ __revision__ = '$Format:%H$'
|
||||
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.preconfigured.PreconfiguredAlgorithmProvider import Preconfigure
|
||||
|
||||
from processing.tools import dataobjects
|
||||
|
||||
class AlgListWatcher(QObject):
|
||||
|
||||
providerAdded = pyqtSignal(str)
|
||||
providerRemoved = pyqtSignal(str)
|
||||
|
||||
algListWatcher = AlgListWatcher()
|
||||
|
||||
class Processing:
|
||||
|
||||
@ -93,6 +99,7 @@ class Processing:
|
||||
ProcessingConfig.readSettings()
|
||||
if updateList:
|
||||
Processing.updateAlgsList()
|
||||
algListWatcher.providerAdded.emit(provider.getName())
|
||||
except:
|
||||
ProcessingLog.addToLog(
|
||||
ProcessingLog.LOG_ERROR,
|
||||
@ -111,7 +118,7 @@ class Processing:
|
||||
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 @@ class Processing:
|
||||
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 @@ class Processing:
|
||||
"""
|
||||
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||
Processing.loadFromProviders()
|
||||
Processing.fireAlgsListHasChanged()
|
||||
QApplication.restoreOverrideCursor()
|
||||
|
||||
@staticmethod
|
||||
@ -177,28 +181,6 @@ class Processing:
|
||||
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 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
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 PyQt.QtGui import (QIcon,
|
||||
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 @@ class ConfigDialog(BASE, WIDGET):
|
||||
return
|
||||
setting.save()
|
||||
Processing.updateAlgsList()
|
||||
settingsWatcher.settingsChanged.emit()
|
||||
updateMenus()
|
||||
|
||||
QDialog.accept(self)
|
||||
|
@ -34,9 +34,9 @@ from PyQt.QtWidgets import QMenu, QAction, QTreeWidgetItem, QLabel, QMessageBox
|
||||
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 @@ WIDGET, BASE = uic.loadUiType(
|
||||
|
||||
class ProcessingToolbox(BASE, WIDGET):
|
||||
|
||||
updateAlgList = True
|
||||
|
||||
def __init__(self):
|
||||
super(ProcessingToolbox, self).__init__(None)
|
||||
self.tipWasClosed = False
|
||||
@ -83,6 +81,10 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
|
||||
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 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
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 updateProvider(self, providerName, updateAlgsList=True):
|
||||
if updateAlgsList:
|
||||
self.updateAlgList = False
|
||||
Processing.updateAlgsList()
|
||||
self.updateAlgList = 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 +305,24 @@ class ProcessingToolbox(BASE, WIDGET):
|
||||
|
||||
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 = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user