Get/set foreground color

Win10, Krita 5.2.3.

New to plugin development. I’ve got a plugin setup, added some custom actions, set some hotkeys in settings, tested a popup msg, works great.

However I’m stuck with the first thing I want to try, getting/setting the foreground color. I’ve looked in the docs (krita api search results) and none of the pages seem relevant. I must be missing something here, as there is an action for setting the foreground color (through a dialog).

If I could get/set the foreground color I would then make hotkeys to rotate the hue in either direction, and increase/decrease saturation. The hotkey “strength” for the WG color selector seemingly cannot be adjusted, and there is a UI bug where it won’t rotate the hue near red more than once when only using the hotkeys.

I was thinking of using Autohotkey to manually move the cursor back and forth to the sliders to make small adjustments but this feels very janky. I already had a bunch of hotkeys to get around the windows alt key menu issue (used space instead), so it was very nice to see someone thankfully solved that particular issue (lets hope it stays solved). I might still do the AHK way but at least I have a plugin setup now.

Hi

Foreground and background colors are available through view.

An example to print current foreground color, and modify it

from krita import * 

v = Krita.instance().activeWindow().activeView()
if v:
    color = v.foregroundColor()
    print(color.colorForCanvas(v.canvas()).name())
    
    color = QColor("#ff8822")
    
    v.setForeGroundColor(ManagedColor.fromQColor(color, v.canvas()))

Grum999

3 Likes