Additional functionality when selecting brush tool

Hello everyone,

I’d like to set up my Krita environment so pressing ‘b’ for the brush tool always disables the erase mode and turns off Snap to Assistants. I did start down the path of creating a Python script for this, but I got lost in the API and I’d really appreciate any help. Thanks so much.

:slight_smile: Hello @Wintermute and welcome to the forum!

I moved your topic into an area where people with the needed knowledge are around, assuming it is in your interest.

Michelist

1 Like

You can combine actions to achieve it.

from krita import *

app = Krita.instance()
app.action("KritaShape/KisToolBrush").trigger()
erase_action = app.action("erase_action")
if erase_action.isChecked:
    erase_action.trigger()
toggle_assistant = app.action("toggle_assistant")
if toggle_assistant.isChecked():
    toggle_assistant.trigger()

For developing scripts this plug-in may help you.

2 Likes

Thank you for the help!

I added parenthesis after erase_action.isChecked: and that part works great.

However, the toggle_assistant isChecked() only seems to work the first time the script is run. Depending on which lines I change, it will work again (once). It’s hard for me to figure out what’s going on – maybe the toggle_assistant action is cached or accessing an older version in memory? The eraser action works every time like a charm.

My second mistake. Action “toggle_assistant” is not checkable.
You can also iterate over QObject to get its check state.

toggle_assistant = app.action("toggle_assistant")
try:
    qdock = next(
        (w for w in Krita.instance().dockers() if w.objectName() == "sharedtooldocker"),
        None,
    )
    pobj = qdock.findChild(QWidget, "KritaShape/KisToolBrushoption widget")
    checkbox = pobj.children()[21]
    if checkbox.isChecked():
        toggle_assistant.trigger()
except:
    pass

This requires ensuring that current tool is brush tool, otherwise will not found widget we need.

This method is not very reliable and will fail after Krita GUI updated. This is done using “Inspector” in Plugin Developer Tools. You can improve it by using a non-index query.

1 Like

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.