Skip to content
Permalink
Browse files

[processing] add actions when provider is registered / activated

  • Loading branch information
nirvn committed Jan 25, 2018
1 parent 7ee4bb7 commit 34c2d32b3e54daa3437d3aaa6559f2b7e9ae699a
Showing with 24 additions and 14 deletions.
  1. +24 −14 python/plugins/processing/gui/ProcessingToolbox.py
@@ -96,6 +96,8 @@ def openSettings(url):
# connect to existing providers
for p in QgsApplication.processingRegistry().providers():
p.algorithmsLoaded.connect(self.updateProvider)
if p.isActive():
self.addProviderActions(p)

QgsApplication.processingRegistry().providerRemoved.connect(self.removeProvider)
QgsApplication.processingRegistry().providerAdded.connect(self.addProvider)
@@ -165,6 +167,24 @@ def _filterItem(self, item, text):
item.setHidden(True)
return False

def addProviderActions(self, provider):
if provider.id() in ProviderActions.actions:
toolbarButton = QToolButton()
toolbarButton.setObjectName('provideraction_' + provider.id())
toolbarButton.setIcon(provider.icon())
toolbarButton.setToolTip(provider.name())
toolbarButton.setPopupMode(QToolButton.InstantPopup)

actions = ProviderActions.actions[provider.id()]
menu = QMenu(provider.name(), self)
for action in actions:
action.setData(self)
act = QAction(action.i18n_name, menu)
act.triggered.connect(action.execute)
menu.addAction(act)
toolbarButton.setMenu(menu)
self.processingToolbar.addWidget(toolbarButton)

def activateProvider(self, id):
provider = QgsApplication.processingRegistry().providerById(id)
if not provider.canBeActivated():
@@ -175,6 +195,7 @@ def activateProvider(self, id):
try:
# not part of the base class - only some providers have a setActive member
provider.setActive(True)
self.addProviderActions(provider)
self.fillTree()
self.textChanged()
self.showDisabled()
@@ -196,6 +217,9 @@ def removeProvider(self, provider_id):
item = self._providerItem(provider_id)
if item is not None:
self.algorithmTree.invisibleRootItem().removeChild(item)
button = self.findChild(QToolButton, 'provideraction-' + provider_id)
if button:
self.processingToolbar.removeChild(button)

def _providerItem(self, provider_id):
for i in range(self.algorithmTree.invisibleRootItem().childCount()):
@@ -416,20 +440,6 @@ def addAlgorithmsFromProvider(self, provider, parent):
groupItem.addChild(algItem)
count += 1

if provider.id() in ProviderActions.actions:
actions = ProviderActions.actions[provider.id()]
toolbarButton = QToolButton()
toolbarButton.setIcon(provider.icon())
toolbarButton.setToolTip(provider.name())
toolbarButton.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(provider.name(), self)
for action in actions:
act = QAction(action.name, menu)
act.triggered.connect(action.execute)
menu.addAction(act)
toolbarButton.setMenu(menu)
self.processingToolbar.addWidget(toolbarButton)

text = provider.name()

if not provider.id() in ('qgis', 'native', '3d'):

4 comments on commit 34c2d32

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa replied Jan 25, 2018

thank you!

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Jan 26, 2018

@nirvn strangely these actions don't have the correct size - they have a different size to the rest of the toolbar (you may need to set a different icon size for your install to see this)

@nirvn

This comment has been minimized.

Copy link
Contributor Author

@nirvn nirvn replied Jan 26, 2018

@nyalldawson , screenshot?

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Jan 26, 2018

@nirvn looks just like a small model and script button next to correct size other buttons :p

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