Skip to content

Commit 0dd3fcb

Browse files
committed
Add processing algorithms to locator bar
Inspired by the ghost of processing's commander
1 parent cb579bb commit 0dd3fcb

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

python/plugins/processing/ProcessingPlugin.py

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from processing.gui.HistoryDialog import HistoryDialog
4343
from processing.gui.ConfigDialog import ConfigOptionsPage
4444
from processing.gui.ResultsDock import ResultsDock
45+
from processing.gui.AlgorithmLocatorFilter import AlgorithmLocatorFilter
4546
from processing.modeler.ModelerDialog import ModelerDialog
4647
from processing.tools.system import tempFolder
4748
from processing.gui.menus import removeMenus, initializeMenus, createMenus
@@ -71,6 +72,8 @@ def __init__(self, iface):
7172
self.options_factory = ProcessingOptionsFactory()
7273
self.options_factory.setTitle(self.tr('Processing'))
7374
iface.registerOptionsWidgetFactory(self.options_factory)
75+
self.locator_filter = AlgorithmLocatorFilter()
76+
iface.registerLocatorFilter(self.locator_filter)
7477
Processing.initialize()
7578

7679
def initGui(self):
@@ -149,6 +152,7 @@ def unload(self):
149152
self.iface.unregisterMainWindowAction(self.resultsAction)
150153

151154
self.iface.unregisterOptionsWidgetFactory(self.options_factory)
155+
self.iface.deregisterLocatorFilter(self.locator_filter)
152156

153157
removeMenus()
154158
Processing.deinitialize()
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
AlgorithmLocatorFilter.py
6+
-------------------------
7+
Date : May 2017
8+
Copyright : (C) 2017 by Nyall Dawson
9+
Email : nyall dot dawson at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Nyall Dawson'
21+
__date__ = 'May 2017'
22+
__copyright__ = '(C) 2017, Nyall Dawson'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
29+
from qgis.core import (QgsApplication,
30+
QgsProcessingAlgorithm)
31+
from qgis.gui import (QgsLocatorFilter,
32+
QgsLocatorResult)
33+
from processing.gui.MessageDialog import MessageDialog
34+
from processing.gui.AlgorithmDialog import AlgorithmDialog
35+
from qgis.utils import iface
36+
37+
class AlgorithmLocatorFilter(QgsLocatorFilter):
38+
39+
def __init__(self, parent=None):
40+
super(AlgorithmLocatorFilter, self).__init__(parent)
41+
42+
def fetchResults(self,string,context,feedback):
43+
for a in QgsApplication.processingRegistry().algorithms():
44+
if feedback.isCanceled():
45+
return
46+
if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox:
47+
continue
48+
49+
if string.lower() in a.displayName().lower() or [t for t in a.tags() if string.lower() in t.lower()]:
50+
result = QgsLocatorResult()
51+
result.filter = self
52+
result.displayString = a.displayName()
53+
result.icon = a.icon()
54+
result.userData = a.id()
55+
self.resultFetched.emit(result)
56+
57+
def triggerResult(self, result):
58+
a = QgsApplication.processingRegistry().algorithmById(result.userData)
59+
if a:
60+
alg = a.getCopy()
61+
message = alg.checkBeforeOpeningParametersDialog()
62+
if message:
63+
dlg = MessageDialog()
64+
dlg.setTitle(self.tr('Missing dependency'))
65+
dlg.setMessage(message)
66+
dlg.exec_()
67+
return
68+
dlg = alg.getCustomParametersDialog()
69+
if not dlg:
70+
dlg = AlgorithmDialog(alg)
71+
canvas = iface.mapCanvas()
72+
prevMapTool = canvas.mapTool()
73+
dlg.show()
74+
dlg.exec_()
75+
if canvas.mapTool() != prevMapTool:
76+
try:
77+
canvas.mapTool().reset()
78+
except:
79+
pass
80+
canvas.setMapTool(prevMapTool)

0 commit comments

Comments
 (0)