Python API questions

Wolthera griffinvalley at gmail.com
Fri May 31 14:06:38 BST 2019


1. To open a file as a layer without triggering dialogs, you will need
to open the file, add a new paintlayer node to the document you want
to add the file to, and copy the pixel data from one to the other.
Here you will need to make sure that the source and result images are
the same colorspace. If you are okay with triggering dialogs use the
"import_layer_as_paint_layer" action(as noted in 3).
2. Undo isn't implemented in python, there was never a proper design
for it conceived. Triggered actions will proly be added to the undo,
but for the rest it is better to clone the document.
3. Krita is not 100% python. Instead, what you can do is access
certain actions is to use application().action("action_name") (you can
get all the action names with
https://api.kde.org/extragear-api/graphics-apidocs/krita/libs/libkis/html/classKrita.html#a5cf481b65e4c0971777ceb9330c8a8e9
), then from the QAction object that gives you, use action.trigger().
The krita4.xmlgui in your resource folder gives the exact layout of
your menus with the actions as an xml file, using these names too.

On Fri, May 31, 2019 at 2:01 PM Thomas Werzmirzowsky <Werzi2001 at gmx.de> wrote:
>
> Hello everybody,
>
> I'm trying to write a simple Python plugin but fail to find the correct APIs. Basically I'm searching for the following:
> - Open a file as a layer (basically what the "Layer > Import/Export > Import Layer..." menu does)
> - I noticed that changes that my plugin does are not recorded in the "Undo History" and the canvas is not updated properly. So I guess I have to start/stop a transaction (or something like that)? Is that right and if so how to do it?
>
> Generally is there a way to find the API that is used by a menu item? Usually the stuff I want to do is a summary of different menu actions but I can't find the APIs for that.
>
> Thanks a lot and best regards
> Thomas



-- 
Wolthera


More information about the kimageshop mailing list