Skip to content

Commit 673421b

Browse files
authored
Merge pull request #6423 from nyalldawson/proc_auto_select_alg
[processing] Some toolbox ux tweaks
2 parents a5399de + 62cd1ed commit 673421b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

python/plugins/processing/gui/ProcessingToolbox.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def __init__(self):
7171
self.processingToolbar.setIconSize(iface.iconSize(True))
7272

7373
self.searchBox.textChanged.connect(self.textChanged)
74+
self.searchBox.returnPressed.connect(self.activateCurrent)
7475
self.algorithmTree.customContextMenuRequested.connect(
7576
self.showPopupMenu)
7677
self.algorithmTree.doubleClicked.connect(self.executeAlgorithm)
@@ -136,6 +137,12 @@ def textChanged(self):
136137
showTip = ProcessingConfig.getSetting(ProcessingConfig.SHOW_PROVIDERS_TOOLTIP)
137138
if showTip:
138139
self.txtDisabled.setVisible(bool(self.disabledWithMatchingAlgs))
140+
141+
if self.algorithmTree.currentItem() is None or self.algorithmTree.currentItem().isHidden():
142+
# if previously selected item was hidden, auto select the first visible algorithm
143+
first_visible = self._findFirstVisibleAlgorithm(self.algorithmTree.invisibleRootItem())
144+
if first_visible is not None:
145+
self.algorithmTree.setCurrentItem(first_visible)
139146
else:
140147
self.algorithmTree.collapseAll()
141148
self.algorithmTree.invisibleRootItem().child(0).setExpanded(True)
@@ -166,6 +173,27 @@ def _filterItem(self, item, text):
166173
item.setHidden(True)
167174
return False
168175

176+
def _findFirstVisibleAlgorithm(self, item):
177+
"""
178+
Returns the first visible algorithm in the tree widget
179+
"""
180+
if item is None:
181+
return None
182+
if item.childCount() > 0:
183+
for i in range(item.childCount()):
184+
child = item.child(i)
185+
first_visible = self._findFirstVisibleAlgorithm(child)
186+
if first_visible is not None:
187+
return first_visible
188+
return None
189+
elif isinstance(item, TreeAlgorithmItem):
190+
if not item.isHidden():
191+
return item
192+
else:
193+
return None
194+
else:
195+
return None
196+
169197
def addProviderActions(self, provider):
170198
if provider.id() in ProviderActions.actions:
171199
toolbarButton = QToolButton()
@@ -269,6 +297,9 @@ def editRenderingStyles(self):
269297
dlg = EditRenderingStylesDialog(alg)
270298
dlg.exec_()
271299

300+
def activateCurrent(self):
301+
self.executeAlgorithm()
302+
272303
def executeAlgorithmAsBatchProcess(self):
273304
item = self.algorithmTree.currentItem()
274305
if isinstance(item, TreeAlgorithmItem):

0 commit comments

Comments
 (0)