Now I would like to toggle them using a hotkey, but I really don’t have a clue on how I should approach this using Python. I feel like it should be something trivial for someone who is well-versed in Python, yet I don’t know where I should start, because I am a beginner…
Is there a Python template for toggling actions with a hotkey?
from krita import *
qdock = next((w for w in Krita.instance().dockers() if w.objectName() == 'sharedtooldocker'), None)
wobj = qdock.findChild(QComboBox,'')
if wobj:
if wobj.currentIndex() == 3:
Krita.instance().action('set_simple_brush_smoothing').trigger()
else:
Krita.instance().action('set_stabilizer_brush_smoothing').trigger()
For anyone reading this, just copy the script above and paste it in a text editor, such as Notepad++ and save the file as a Python file. Go to Tools > Scripts > Ten Scripts, click the … button and load the Python file. Then, under the keyboard shortcuts, assign a keyboard shortcut to the slot that corresponds to the Ten Scripts slot that holds the brush toggle.
@KnowZero can I use this to make any toggle between actions? So if I replace the action parts in the script:
.action(‘Insert Action name here’) will it work with those actions too?
There are different kinds of actions. The actions that are checkable, you can do a universal toggle by checking if the are isChecked().
Then there are actions like the above which change a property of a component, in this case the action changes the value of a QComboBox in the Tool Options docker. So what the code above does is check the combobox value to see if it is set to stabilizer, and based on that do a different action.
For these actions, you would have to write a condition like I did above. You can simplify it with the Python Developer Tools plugin which can generate code for you to get to the object you need and also give you the properties/values of that component
While other values are simply internal settings, and can only be checked via Krita.instance().readSetting()
Edit:
To demonstrate what I mean here is the same thing using the readSetting method:
from krita import *
if Krita.instance().readSetting('','LineSmoothingType','') == '3':
Krita.instance().action('set_simple_brush_smoothing').trigger()
else:
Krita.instance().action('set_stabilizer_brush_smoothing').trigger()
To get these, I suggest a text editor like KDE Kate and opening the kritarc file, then make then run the function and Kate will tell you there was a change. You can then view the difference to see what value was changed