Discovering which toolbox tool is active?

Is there an API to query the name of the currently selected toolbox action?

I’ve tried calling like Krita.instance().action('ZoomTool').isChecked() (with ‘ZoomTool’ replaced with the action name of each tool in the toolbox) but it always returns False, as does .isCheckable().

Another idea was connecting to the triggered signal of each tool, but I don’t know when or how my extension should register the listeners.

kinda… installing off-road programming tires.


from krita import Krita

from PyQt5.QtWidgets import QWidget, QToolButton


def find_tool_box(qwindow):
    for qobj in qwindow.findChildren(QWidget):
        if qobj.metaObject().className() == "KoToolBox":
            return qobj


def find_active_tool(qtoolbox):
    for qobj in qtoolbox.findChildren(QToolButton):
        if qobj.metaObject().className() == "KoToolBoxButton":
            if qobj.isChecked():
                return qobj


def find_my_current_tool():
    app = Krita.instance()
    qwindow = app.activeWindow().qwindow()
    tool_box = find_tool_box(qwindow)
    tool = find_active_tool(tool_box)
    return tool


tool = find_my_current_tool()
name = tool.objectName()
checked = tool.isChecked()
print("tool: {tool}, tool.objectName: {name}, checked: {checked}".format(**locals()))

/AkiR

2 Likes

Perfect, thank you!

This was the script I made, it’s super basic: https://github.com/dyaso/toggle_ruler_layer

1 Like