Skip to content

Commit

Permalink
[processing] add actions when provider is registered / activated
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 25, 2018
1 parent 7ee4bb7 commit 34c2d32
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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()
Expand All @@ -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()):
Expand Down Expand Up @@ -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'):
Expand Down

4 comments on commit 34c2d32

@slarosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Contributor Author

@nirvn nirvn commented on 34c2d32 Jan 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson , screenshot?

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.