Skip to content

Commit

Permalink
Merge pull request #6423 from nyalldawson/proc_auto_select_alg
Browse files Browse the repository at this point in the history
[processing] Some toolbox ux tweaks
  • Loading branch information
alexbruy committed Feb 23, 2018
2 parents a5399de + 62cd1ed commit 673421b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -71,6 +71,7 @@ def __init__(self):
self.processingToolbar.setIconSize(iface.iconSize(True))

self.searchBox.textChanged.connect(self.textChanged)
self.searchBox.returnPressed.connect(self.activateCurrent)
self.algorithmTree.customContextMenuRequested.connect(
self.showPopupMenu)
self.algorithmTree.doubleClicked.connect(self.executeAlgorithm)
Expand Down Expand Up @@ -136,6 +137,12 @@ def textChanged(self):
showTip = ProcessingConfig.getSetting(ProcessingConfig.SHOW_PROVIDERS_TOOLTIP)
if showTip:
self.txtDisabled.setVisible(bool(self.disabledWithMatchingAlgs))

if self.algorithmTree.currentItem() is None or self.algorithmTree.currentItem().isHidden():
# if previously selected item was hidden, auto select the first visible algorithm
first_visible = self._findFirstVisibleAlgorithm(self.algorithmTree.invisibleRootItem())
if first_visible is not None:
self.algorithmTree.setCurrentItem(first_visible)
else:
self.algorithmTree.collapseAll()
self.algorithmTree.invisibleRootItem().child(0).setExpanded(True)
Expand Down Expand Up @@ -166,6 +173,27 @@ def _filterItem(self, item, text):
item.setHidden(True)
return False

def _findFirstVisibleAlgorithm(self, item):
"""
Returns the first visible algorithm in the tree widget
"""
if item is None:
return None
if item.childCount() > 0:
for i in range(item.childCount()):
child = item.child(i)
first_visible = self._findFirstVisibleAlgorithm(child)
if first_visible is not None:
return first_visible
return None
elif isinstance(item, TreeAlgorithmItem):
if not item.isHidden():
return item
else:
return None
else:
return None

def addProviderActions(self, provider):
if provider.id() in ProviderActions.actions:
toolbarButton = QToolButton()
Expand Down Expand Up @@ -269,6 +297,9 @@ def editRenderingStyles(self):
dlg = EditRenderingStylesDialog(alg)
dlg.exec_()

def activateCurrent(self):
self.executeAlgorithm()

def executeAlgorithmAsBatchProcess(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
Expand Down

0 comments on commit 673421b

Please sign in to comment.