Krita
Libkis is a QObject-based wrapper around Krita's internal libraries. The wrapper can be used from C++ plugins that do not need the advanced and volatile internal libraries of Krita, or can be bound to scripting languages like Python or Javascript.
All classes are based on QObject, so QMetaObject introspection can be used to discover properties, slots and signals and automatically expose all functionality to the client.
Note that all objects that are created are wrapper objects that are owned by the scripting environment or the plugin.
Using the functionality in this library, either through a scripting environment like Python or Javascript, or directly from C++, you can, among other things achieve the following functionality:
- Open, save, export, rename files.
- Access the layers and masks in a file
- Read and write pixel data
- Add menu items, toolbar items and docker palettes
The reference implementation of scripting in Krita is implemented in Python 3. All examples in the documentation for scripting will be provided using Python, although the api documentation is generated from C++ header files and shows c++ syntax for arguments.
Autostarting Scripts
Autostarting scripts or script-based plugins are scripts that Krita loads on startup. You can add autostarting scripts to Krita by placing them in the pykrita folder in the resources folder: go to settings/ manage resources and press the Open Resources Folder to open your local resources folder.
Scripts are identified by a file that ends in a .desktop
extension that contain information about the script itself. For example:
The Python code itself should be placed in the pykrita/hello folder. Your Python plugin needs to be a module, so needs to have a __init__.py
file:
Krita is a Qt-based application. In principle, you can use any Python binding to Qt as long as it's using exactly the same version of Qt that Krita uses. In our examples we will be using PyQt.
The easiest access to the Krita api is by simply importing the "krita" module. This automatically adds two built-ins: Scripter and Application.
This is an alias for Krita.instance(), which is the first place from which to access the running Krita instance.
The Krita Object Model
The starting point is the
- See also
- Krita class, which provides a singleton object for easy reference. From the Krita class, a hierarchy is provided where you can access windows, lviews, documents, nodes and channels.
You can access the Krita class as
Krita.instance() Application Scripter
For ease of use.
The Document class is provided to allow access to the images Krita has loaded. Note: internally, Krita distinguishes between images and documents.
A document contains an image and knows the filename of the image, the image itself only knows about the layers and masks it contains. The generic name for layers and masks is node.
A Node can be a group layer, a file layer, a vector layer, a filter layer, a generator layer, a clone layer, a paint layer or a transform mask, a selection mask, a transparency mask or a colorize mask. You can change some properties of Nodes, but not all of them.
The Window class is provided to allow access to the windows and views Krita has open. A given Document can be shown in more than one View, and in more than one Window. You can open and close windows and views.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 23:42:22 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.