访问文字工具(当前层)

时间:2019-01-29 10:28:39

标签: pyqt5 qgis

从QGIS 3开始,有两个顶点工具:当前层和新层:所有层。 通常,我可以使用下面的代码访问所有操作。 但是现在我找不到并激活顶点工具(当前层)。 即使不搜索其标题! 我不知道如何添加“不存在”的动作。 有什么想法吗?

def findAction(objName):
    try:
        toolbars = iface.mainWindow().findChildren(QToolBar)
        for toolbar in toolbars:
            for action in toolbar.actions():
                if isinstance(action, QWidgetAction):
                    if action.defaultWidget() and action.defaultWidget().actions():
                        dwa = action.defaultWidget().actions()
                        for a in dwa:
                            if IsSearchedAction(a,objName):
                                print ("a",a.objectName())
                                return a
                else:
                    if IsSearchedAction(action, objName): 
                        print ("action",action.objectName())
                        return action
        menubar = iface.mainWindow().menuBar()
        for action in menubar.actions():
            if action.menu():
                for action in action.menu().actions():
                    print("menu")
                    if action.menu():
                        for a in action.menu().actions():
                            if IsSearchedAction(a, objName): return a
                    else:
                        if IsSearchedAction(action, objName): return action
            else:
                if IsSearchedAction(action, objName): return action
        return None
    except Exception as e:
        print (e)

def IsSearchedAction(action, objname):
    objname = objname.lower()
    caption = action.text()
    caption = caption.replace("&", "")
    caption = caption.replace(".", "")
    caption = caption.strip()
    caption= caption.lower()
    return action.objectName().lower() == objname or caption == objname

print (iface.mapCanvas().mapTool().action().objectName())
action ="mActionVertexToolActiveLayer"
action ="mActionMeasure"
action ="mActionSelectFeatures"
action ="mActionVertexToolActiveLayer"#not found
print(findAction(action))

0 个答案:

没有答案