mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-27 00:07:16 -05:00
Add processing algorithms to locator bar
Inspired by the ghost of processing's commander
This commit is contained in:
parent
cb579bb9b6
commit
0dd3fcb6e4
4
python/plugins/processing/ProcessingPlugin.py
Normal file → Executable file
4
python/plugins/processing/ProcessingPlugin.py
Normal file → Executable file
@ -42,6 +42,7 @@ from processing.gui.ProcessingToolbox import ProcessingToolbox
|
||||
from processing.gui.HistoryDialog import HistoryDialog
|
||||
from processing.gui.ConfigDialog import ConfigOptionsPage
|
||||
from processing.gui.ResultsDock import ResultsDock
|
||||
from processing.gui.AlgorithmLocatorFilter import AlgorithmLocatorFilter
|
||||
from processing.modeler.ModelerDialog import ModelerDialog
|
||||
from processing.tools.system import tempFolder
|
||||
from processing.gui.menus import removeMenus, initializeMenus, createMenus
|
||||
@ -71,6 +72,8 @@ class ProcessingPlugin(object):
|
||||
self.options_factory = ProcessingOptionsFactory()
|
||||
self.options_factory.setTitle(self.tr('Processing'))
|
||||
iface.registerOptionsWidgetFactory(self.options_factory)
|
||||
self.locator_filter = AlgorithmLocatorFilter()
|
||||
iface.registerLocatorFilter(self.locator_filter)
|
||||
Processing.initialize()
|
||||
|
||||
def initGui(self):
|
||||
@ -149,6 +152,7 @@ class ProcessingPlugin(object):
|
||||
self.iface.unregisterMainWindowAction(self.resultsAction)
|
||||
|
||||
self.iface.unregisterOptionsWidgetFactory(self.options_factory)
|
||||
self.iface.deregisterLocatorFilter(self.locator_filter)
|
||||
|
||||
removeMenus()
|
||||
Processing.deinitialize()
|
||||
|
||||
80
python/plugins/processing/gui/AlgorithmLocatorFilter.py
Executable file
80
python/plugins/processing/gui/AlgorithmLocatorFilter.py
Executable file
@ -0,0 +1,80 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
AlgorithmLocatorFilter.py
|
||||
-------------------------
|
||||
Date : May 2017
|
||||
Copyright : (C) 2017 by Nyall Dawson
|
||||
Email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = 'Nyall Dawson'
|
||||
__date__ = 'May 2017'
|
||||
__copyright__ = '(C) 2017, Nyall Dawson'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsProcessingAlgorithm)
|
||||
from qgis.gui import (QgsLocatorFilter,
|
||||
QgsLocatorResult)
|
||||
from processing.gui.MessageDialog import MessageDialog
|
||||
from processing.gui.AlgorithmDialog import AlgorithmDialog
|
||||
from qgis.utils import iface
|
||||
|
||||
class AlgorithmLocatorFilter(QgsLocatorFilter):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(AlgorithmLocatorFilter, self).__init__(parent)
|
||||
|
||||
def fetchResults(self,string,context,feedback):
|
||||
for a in QgsApplication.processingRegistry().algorithms():
|
||||
if feedback.isCanceled():
|
||||
return
|
||||
if a.flags() & QgsProcessingAlgorithm.FlagHideFromToolbox:
|
||||
continue
|
||||
|
||||
if string.lower() in a.displayName().lower() or [t for t in a.tags() if string.lower() in t.lower()]:
|
||||
result = QgsLocatorResult()
|
||||
result.filter = self
|
||||
result.displayString = a.displayName()
|
||||
result.icon = a.icon()
|
||||
result.userData = a.id()
|
||||
self.resultFetched.emit(result)
|
||||
|
||||
def triggerResult(self, result):
|
||||
a = QgsApplication.processingRegistry().algorithmById(result.userData)
|
||||
if a:
|
||||
alg = a.getCopy()
|
||||
message = alg.checkBeforeOpeningParametersDialog()
|
||||
if message:
|
||||
dlg = MessageDialog()
|
||||
dlg.setTitle(self.tr('Missing dependency'))
|
||||
dlg.setMessage(message)
|
||||
dlg.exec_()
|
||||
return
|
||||
dlg = alg.getCustomParametersDialog()
|
||||
if not dlg:
|
||||
dlg = AlgorithmDialog(alg)
|
||||
canvas = iface.mapCanvas()
|
||||
prevMapTool = canvas.mapTool()
|
||||
dlg.show()
|
||||
dlg.exec_()
|
||||
if canvas.mapTool() != prevMapTool:
|
||||
try:
|
||||
canvas.mapTool().reset()
|
||||
except:
|
||||
pass
|
||||
canvas.setMapTool(prevMapTool)
|
||||
Loading…
x
Reference in New Issue
Block a user