Hello everyone, hope all is well
Since my proposal for a plugin to handle slots for brushes I was thinking what would take (if possible) to make this plugin. I followed the available tutorials and manual entries about Plugin Development, as well reading the libkis Krita API Documentation.
So here is what I stumble into:
Details about my endeavor
From what I understood a Krita plugin only has a function called (either directly or by capturing a Signal), if ‘triggered’:
- Trough a menu entry (Tools/Scripts)
- Trough a shortcut
- Via a docker interaction (e.g.: a button)
Then I learned of the Signals from the class Notifier. This let me to pursue the idea of connecting to Krita’s “native” signals.
One of my ideas was for the plugin to check the current brush preset. However this would only be possible when the user ‘activated’ the plugin with a shorcut.
For a constant check I imagined two possibilities:
- Setting a timer and updating the current brush every timeout.
- Trying to get a signal for when a brush was selected, if possible.
About the item 1: I don’t know how bad (performance-wise) running a timer and checking the brush every timeout could it be. However, it seemed kind of a crude or ‘hacking’ way of doing it.
Then I tried item 2. Thanks to the awesome Python Plugin Developer Tools by @KnowZero I discovered how to interacting directly with the window dockers.
The docker Brushes Preset with its ResourceChooser QWidget caught my attention, especially the public signals: resourceClicked and resourceSelected.
While connecting to resourceClicked resulted in nothing (maybe it’s not being emitted?), connecting to resourceSelected gave a Python Script Error.
TL;DR:
Can a plugin connect to Krita’s ‘Internal’ Signals?
Just copy and paste the code bellow in the Scripter, then click in any brush in the Brush Docker.
from krita import *
def hello():
print('hello')
qwin = Krita.instance().activeWindow().qwindow()
obj = qwin.findChild(QWidget, 'ResourceChooser')
obj.resourceSelected.connect(hello)
#Disconnect the 'resourceSelected' Signal
#obj.resourceSelected.disconnect()
- Am I wrong to try something like this? Are plugins meant to interact this way with Krita?
If so, would be valid to request the Python API to include a KoResource C++ type? - Is using a timer the proper way to constantly check the current brush, and would be too costing?
Cheers.






so I can clearly see when the function run properly.