Class Krita
Build from Krita.h
Krita 4.0.0Krita 5.1.0

Krita is a singleton class that offers the root access to the Krita object hierarchy.

The Krita.instance() is aliased as two builtins: Scripter and Application.

Static methods

fromVariant(v: QVariant)QObject getAppDataLocation()str instance() krita_i18n(text: str)str krita_i18nc(context: str, text: str)str

Methods

action(name: str)QAction actions()list[QAction] activeDocument()Document activeWindow()Window addDockWidgetFactory(factory: DockWidgetFactoryBase) addExtension(extension: Extension) addProfile(profilePath: str)bool batchmode()bool colorDepths(colorModel: str)list[str] colorModels()list[str] createDocument(width: int, height: int, name: str, colorModel: str, colorDepth: str, profile: str, resolution: float)Document dockers()list[QDockWidget] documents()list[Document] extensions()list[Extension] filter(name: str)Filter filterStrategies()list[str] filters()list[str] icon(iconName: str)QIcon notifier()Notifier openDocument(filename: str)Document openWindow()Window profiles(colorModel: str, colorDepth: str)list[str] readSetting(group: str, name: str, defaultValue: str)str recentDocuments()list[str] resources(type: str)dict[str: Resource] setActiveDocument(value: Document) setBatchmode(value: bool) version()str views()list[View] windows()list[Window] writeSetting(group: str, name: str, value: str)

Member documentation

action(name: str)QAction
Krita 4.0.0

Parameters

name(no description provided)

Return

the action that has been registered under the given name, or 0 if no such action exists.

actions()list[QAction]
Krita 4.0.0

Return

return a list of all actions for the currently active mainWindow.

Krita 4.0.0

Return

the currently active document, if there is one.

Krita 4.0.0

Return

the currently active window or None if there is no window

Krita 4.0.0

Add the given docker factory to the application. For scripts loaded on startup, this means that every window will have one of the dockers created by the factory.

Parameters

factory

The factory object.

addExtension(extension: Extension)
Krita 4.0.0

add the given plugin to Krita. There will be a single instance of each Extension in the Krita process.

Parameters

extension

the extension to add.

addProfile(profilePath: str)bool
Krita 4.0.0

load the given profile into the profile registry.

Parameters

profilePath

the path to the profile.

Return

true if adding the profile succeeded.

batchmode()bool
Krita 4.0.0

determines whether the script is run in batch mode. If batchmode is true, scripts should now show messageboxes or dialog boxes.

Note that this separate from Document.setBatchmode(), which determines whether export/save option dialogs are shown.

Return

true if the script is run in batchmode

colorDepths(colorModel: str)list[str]
Krita 4.0.0

creates a list with the names of all color depths compatible with the given color model.

Parameters

colorModel

the id of a color model.

Return

a list of all color depths or a empty list if there is no such color depths.

colorModels()list[str]
Krita 4.0.0

creates a list with all color models id's registered.

Return

a list of all color models or a empty list if there is no such color models.

createDocument(width: int, height: int, name: str, colorModel: str, colorDepth: str, profile: str, resolution: float)Document
Krita 4.0.0Krita 4.1.0

creates a new document and image and registers the document with the Krita application.

Unless you explicitly call Document::close() the document will remain known to the Krita document registry. The document and its image will only be deleted when Krita exits.

The document will have one transparent layer.

To create a new document and show it, do something like:

from Krita import *def add_document_to_window(): d = Application.createDocument(100, 100, "Test", "RGBA", "U8", "", 120.0) Application.activeWindow().addView(d)add_document_to_window()

Parameters

width

the width in pixels

height

the height in pixels

name

the name of the image (not the filename of the document)

colorModel

A string describing the color model of the image:

  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel

colorDepth

A string describing the color depth of the image:

  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point

profile

The name of an icc profile that is known to Krita. If an empty string is passed, the default is taken.

resolution

the resolution in points per inch.

Return

the created document.

dockers()list[QDockWidget]
Krita 4.4.0

Return

a list of all the dockers

documents()list[Document]
Krita 4.0.0

Return

a list of all open Documents

extensions()list[Extension]
Krita 4.0.0

return a list with all registered extension objects.

Return

(no description provided)

filter(name: str)Filter
Krita 4.0.0

construct a Filter object with a default configuration.

Parameters

name

the name of the filter. Use Krita.instance().filters() to get a list of all possible filters.

Return

the filter or None if there is no such filter.

filterStrategies()list[str]
Krita 4.0.0

Retrieves all installed filter strategies. A filter strategy is used when transforming (scaling, shearing, rotating) an image to calculate the value of the new pixels. You can use th

Return

the id's of all available filters.

filters()list[str]
Krita 4.0.0

Filters are identified by an internal name. This function returns a list of all existing registered filters.

Return

a list of all registered filters

fromVariant(v: QVariant)QObject
Krita 4.0.0

Internal only: for use with mikro.py

Parameters

v(no description provided)

Return

(no description provided)

getAppDataLocation()str
Krita 5.1.0

Return

(no description provided)

icon(iconName: str)QIcon
Krita 4.0.0

This allows you to get icons from Krita's internal icons.

Parameters

iconName

name of the icon.

Return

the icon related to this name.

Krita 4.0.0

retrieve the singleton instance of the Application object.

Return

(no description provided)

krita_i18n(text: str)str
Krita 4.1.0

Parameters

text(no description provided)

Return

(no description provided)

krita_i18nc(context: str, text: str)str
Krita 4.4.0

Parameters

context(no description provided)
text(no description provided)

Return

(no description provided)

Krita 4.0.0

the Notifier singleton emits signals when documents are opened and closed, the configuration changes, views are opened and closed or windows are opened.

Return

the notifier object

openDocument(filename: str)Document
Krita 4.0.0

creates a new Document, registers it with the Krita application and loads the given file.

Parameters

filename

the file to open in the document

Return

the document

Krita 4.0.0

create a new main window. The window is not shown by default.

Return

(no description provided)

profiles(colorModel: str, colorDepth: str)list[str]
Krita 4.0.0

creates a list with the names of all color profiles compatible with the given color model and color depth.

Parameters

colorModel

A string describing the color model of the image:

  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel

colorDepth

A string describing the color depth of the image:

  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point

Return

a list with valid names

readSetting(group: str, name: str, defaultValue: str)str
Krita 4.0.0

read the given setting value from the kritarc file.

Parameters

group

The group the setting is part of. If empty, then the setting is read from the general group.

name

The name of the setting

defaultValue

The default value of the setting

Return

a string representing the setting.

recentDocuments()list[str]
Krita 4.0.0

return all recent documents registered in the RecentFiles group of the kritarc

Return

(no description provided)

resources(type: str)dict[str: Resource]
Krita 4.0.0

returns a list of Resource objects of the given type

Parameters

type

Valid types are:

  • pattern
  • gradient
  • brush
  • preset
  • palette
  • workspace

Return

(no description provided)

Krita 4.0.0

activates the first view that shows the given document

Parameters

value

the document we want to activate

setBatchmode(value: bool)
Krita 4.0.0

sets the batchmode to value; if true, scripts should not show dialogs or messageboxes.

Parameters

value(no description provided)
version()str
Krita 4.0.0

Determine the version of Krita

Usage: print(Application.version ())

Return

the version string including git sha1 if Krita was built from git

views()list[View]
Krita 4.0.0

Return

a list of all views. A Document can be shown in more than one view.

windows()list[Window]
Krita 4.0.0

Return

a list of all windows

writeSetting(group: str, name: str, value: str)
Krita 4.0.0

write the given setting under the given name to the kritarc file in the given settings group.

Parameters

group

The group the setting belongs to. If empty, then the setting is written in the general section

name

The name of the setting

value

The value of the setting. Script settings are always written as strings.