这是如何通过按Ctrl+ 打开“处理“加入属性”算法的示例1(您可以将其复制并粘贴到QGIS Python控制台中):
# Function to open the "Join attributes" algorithm's UI
# See http://gis.stackexchange.com/questions/156633/how-to-launch-processing-tool-user-interface-using-pyqgis
from processing.core.Processing import Processing
from processing.gui.CommanderWindow import CommanderWindow
cw = CommanderWindow(iface.mainWindow(), iface.mapCanvas())
def openAlgorithm():
alg = Processing.getAlgorithm("qgis:joinattributestable")
if alg is not None:
cw.runAlgorithm(alg)
# Assign "Ctrl+1" to openAlgorithm()
from PyQt4.QtGui import QShortcut, QKeySequence
from PyQt4.QtCore import Qt
shortcut = QShortcut(QKeySequence(Qt.ControlModifier + Qt.Key_1), iface.mainWindow())
shortcut.setContext(Qt.ApplicationShortcut)
shortcut.activated.connect(openAlgorithm)
而已!如果按Ctrl+ 1,将打开“加入属性”用户界面:
注意1:您可以通过在QGIS Python控制台中输入以下行来获得可用算法的名称:
import processing
processing.alglist()
注意2:有关密钥的完整列表,请参阅Qt4文档。
注意3:您可以调用shortcut.activated.disconnect(openAlgorithm)
来完成快捷方式和算法的UI之间的关联。