### Basic Krita Extension Example Source: https://apidoc.krita.maou-maou.fr/kapi-class-Extension.html This example demonstrates how to create a simple Krita extension that displays a message box with the Krita version when an action is triggered. It shows the basic structure of an Extension class, including __init__, setup, and createActions. ```python import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * from krita import * class HelloExtension(Extension): def __init__(self, parent): super().__init__(parent) def hello(self): QMessageBox.information(QWidget(), "Test", "Hello! This is Krita " + Application.version()) def setup(self): qDebug("Hello Setup") def createActions(self, window): action = window.createAction("hello") action.triggered.connect(self.hello) Scripter.addExtension(HelloExtension(Krita.instance())) ``` -------------------------------- ### Update Document Guides Configuration Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Shows how to get, modify, and set the guides configuration for a Krita document. This involves updating guide color, line type, visibility, lock status, snap behavior, and horizontal guides. ```python # get document (create one or get active one for example) newDoc = Krita.instance().createDocument(500, 500, "Test", "RGBA", "U8", "", 300) # retrieve document guides configuration newDocGuides = newDoc.guidesConfig() # update properties newDocGuides.setColor(QColor('#ff00ff')) newDocGuides.setLineType('dotted') newDocGuides.setVisible(True) newDocGuides.setLocked(True) newDocGuides.setSnap(True) newDocGuides.setHorizontalGuides([100,200]) # set guides configuration to document newDoc.setGuidesConfig(newDocGuides) ``` -------------------------------- ### setHorizontalGuides Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Replaces all existing horizontal guides with a new list of guide positions. This method is deprecated and `guidesConfig()` should be used instead. ```APIDOC ## setHorizontalGuides ### Description Replaces all existing horizontal guides with the entries in the list. Deprecated in Krita 6.0.0, use `guidesConfig()` instead. ### Method `setHorizontalGuides(lines: list[float])` ### Parameters #### Path Parameters - **lines** (list[float]) - Description: A list of floats containing the new guides. ``` -------------------------------- ### setVerticalGuides Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Replaces all existing vertical guides with a new list of guide positions. This method is deprecated and `guidesConfig()` should be used instead. ```APIDOC ## setVerticalGuides ### Description Replaces all existing vertical guides with the entries in the list. Deprecated in Krita 6.0.0, use `guidesConfig()` instead. ### Method `setVerticalGuides(lines: list[float])` ### Parameters #### Path Parameters - **lines** (list[float]) - Description: A list of floats containing the new guides. ``` -------------------------------- ### Set Foreground Color Example Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Demonstrates how to get the current foreground color, modify its components, and set it back. This color is nominally per canvas/view but in practice per mainwindow. ```python color = Application.activeWindow().activeView().foreGroundColor() components = color.components() components[0] = 1.0 components[1] = 0.6 components[2] = 0.7 color.setComponents(components) Application.activeWindow().activeView().setForeGroundColor(color) ``` -------------------------------- ### widget Source: https://apidoc.krita.maou-maou.fr/kapi-class-IntParseSpinBox.html Get the internal KisIntParseSpinBox as a QWidget, allowing it to be added to a UI. ```APIDOC ## widget() -> QSpinBox ### Description Get the internal KisIntParseSpinBox as a QWidget, so it may be added to a UI. ### Return - **QSpinBox**: The internal KisIntParseSpinBox as a QWidget. ``` -------------------------------- ### verticalGuides Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html DEPRECATED: Retrieves the vertical guide lines. Use guidesConfig() instead. ```APIDOC ## verticalGuides() ### Description DEPRECATED - use guidesConfig() instead. The vertical guide lines. ### Method (Not specified, likely a method call) ### Return - list[float] - a list of vertical guides. ``` -------------------------------- ### setGuidesConfig Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Applies a GuidesConfig object to set or modify the guides properties of a document. This enables customization of guide color, line type, visibility, locked status, snap behavior, and specific horizontal guide positions. ```APIDOC ## setGuidesConfig ### Description Applies a GuidesConfig object to set or modify the guides properties of a document. ### Method `setGuidesConfig(guidesConfig: GuidesConfig)` ### Parameters #### Path Parameters - **guidesConfig** (GuidesConfig) - Description: A GuidesConfig object to apply for guides configuration. Used to modify or set guides properties on a document. ### Request Example ```python # Example usage: newDoc = Krita.instance().createDocument(500, 500, "Test", "RGBA", "U8", "", 300) newDocGuides = newDoc.guidesConfig() newDocGuides.setColor(QColor('#ff00ff')) newDocGuides.setLineType('dotted') newDocGuides.setVisible(True) newDocGuides.setLocked(True) newDocGuides.setSnap(True) newDocGuides.setHorizontalGuides([100, 200]) newDoc.setGuidesConfig(newDocGuides) ``` ``` -------------------------------- ### Creating and Registering a Custom Docker Source: https://apidoc.krita.maou-maou.fr/kapi-class-DockWidget.html Example of how to define a custom Docker by subclassing DockWidget and registering its factory with Krita's application. ```python class HelloDocker(DockWidget): def __init__(self): super().__init__() label = QLabel("Hello", self) self.setWidget(label) self.label = label self.setWindowTitle("Hello Docker") def canvasChanged(self, canvas): self.label.setText("Hellodocker: canvas changed"); Application.addDockWidgetFactory(DockWidgetFactory("hello", DockWidgetFactoryBase.DockRight, HelloDocker)) ``` -------------------------------- ### Extension Source: https://apidoc.krita.maou-maou.fr Interface for creating Krita extensions, allowing custom actions and setup. ```APIDOC ## Class Extension ### Description Interface for Krita extensions. ### Members - **createActions** (method) - **setup** (method) ### Implemented +Krita 4.0.0 ``` -------------------------------- ### GuidesConfig Methods Source: https://apidoc.krita.maou-maou.fr/kapi-class-GuidesConfig.html This section details the various methods available to interact with Krita's guide configurations, including setting and retrieving properties like color, line type, visibility, and locking status. ```APIDOC ## color() ### Description Gets the current color applied to all guides. ### Return - QColor: The color applied for all guides. --- ## fromXml(xmlContent: str) ### Description Loads guide definitions from an XML document. ### Parameters - **xmlContent** (str) - Required - The XML content provided as a string. ### Return - bool: True if the XML content is valid and guides have been loaded, otherwise False. --- ## hasGuides() ### Description Indicates if there are any guides defined. ### Return - bool: True if at least one guide is defined, otherwise False. --- ## hasSamePositionAs(guideConfig: GuidesConfig) ### Description Indicates if the position of the current guides configuration matches another guide configuration. ### Parameters - **guideConfig** (GuidesConfig) - Required - The other GuidesConfig object to compare against. ### Return - bool: True if the positions are the same. --- ## horizontalGuides() ### Description Retrieves the positions of the horizontal guides. ### Return - list[float]: A list of the horizontal positions of the guides. --- ## lineType() ### Description Gets the line type applied for all guides. ### Return - str: The line type. Can be: "solid", "dashed", or "dot". --- ## locked() ### Description Returns the lock status of the guides. ### Return - bool: True if the guides are locked, otherwise False. --- ## removeAllGuides() ### Description Removes all defined guides. --- ## setColor(color: QColor) ### Description Defines the color for the guides. ### Parameters - **color** (QColor) - Required - The color to apply. --- ## setHorizontalGuides(lines: list[float]) ### Description Sets the horizontal guides. ### Parameters - **lines** (list[float]) - Required - A list of the horizontal positions of guides to set. --- ## setLineType(lineType: str) ### Description Defines the line type for the guides. ### Parameters - **lineType** (str) - Required - The line type to use for guides. Can be: "solid", "dashed", or "dot". --- ## setLocked(value: bool) ### Description Sets the lock status for the guides. ### Parameters - **value** (bool) - Required - True to set guides locked, otherwise False. --- ## setSnap(value: bool) ### Description Sets the snap status for the guides. ### Parameters - **value** (bool) - Required - True to set snap to guides active, otherwise False. --- ## setVerticalGuides(lines: list[float]) ### Description Sets the vertical guides. ### Parameters - **lines** (list[float]) - Required - A list of the vertical positions of guides to set. --- ## setVisible(value: bool) ### Description Sets the visibility status for the guides. ### Parameters - **value** (bool) - Required - True to set guides visible, otherwise False. --- ## snap() ### Description Returns the snap status of the guides. ### Return - bool: True if snap to guides is active, otherwise False. --- ## toXml() ### Description Saves the guide definitions as an XML document. ### Return - str: A string containing the XML content. --- ## verticalGuides() ### Description Retrieves the positions of the vertical guides. ### Return - list[float]: A list of the vertical positions of the guides. --- ## visible() ### Description Returns the visibility status of the guides. ### Return - bool: True if the guides are visible, otherwise False. --- ``` -------------------------------- ### setGuidesVisible Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Sets the visibility of guides on the current document. This method is deprecated and `guidesConfig()` should be used instead. ```APIDOC ## setGuidesVisible ### Description Sets the visibility of guides on the current document. Deprecated in Krita 6.0.0, use `guidesConfig()` instead. ### Method `setGuidesVisible(visible: bool)` ### Parameters #### Path Parameters - **visible** (bool) - Description: Whether or not the guides are visible. ``` -------------------------------- ### playBackStartTime Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Retrieves the start time of the current playback range within the document. ```APIDOC ## playBackStartTime() ### Description Gets the start time of the current playback. ### Return An integer representing the start time of the current playback. ``` -------------------------------- ### clear() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Scratchpad.html Clears the entire scratchpad content using the color that was set during its setup. ```APIDOC ## clear() ### Description Clears out the scratchpad with the color specified during setup. ``` -------------------------------- ### Get Resource Data as QByteArray Source: https://apidoc.krita.maou-maou.fr/kapi-class-Resource.html Retrieves the resource's data as a QByteArray. This is useful for reading the raw content of a resource. ```python resource.data() ``` -------------------------------- ### Implementing and Adding a Custom Dock Widget Source: https://apidoc.krita.maou-maou.fr/kapi-class-DockWidgetFactoryBase.html Example of how to define a custom dock widget and register it with Krita. This involves creating a class that inherits from DockWidget and then using Application.addDockWidgetFactory to make it available. ```python class HelloDocker(DockWidget): def __init__(self): super().__init__() label = QLabel("Hello", self) self.setWidget(label) self.label = label def canvasChanged(self, canvas): self.label.setText("Hellodocker: canvas changed"); Application.addDockWidgetFactory(DockWidgetFactory("hello", DockWidgetFactoryBase.DockRight, HelloDocker)) ``` -------------------------------- ### setGuidesLocked Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Sets the locked status for guides on the current document. This method is deprecated and `guidesConfig()` should be used instead. ```APIDOC ## setGuidesLocked ### Description Sets the locked status for guides on the current document. Deprecated in Krita 6.0.0, use `guidesConfig()` instead. ### Method `setGuidesLocked(locked: bool)` ### Parameters #### Path Parameters - **locked** (bool) - Description: Whether or not to lock the guides on this document. ``` -------------------------------- ### Create and Initialize Colorize Mask Source: https://apidoc.krita.maou-maou.fr/kapi-class-ColorizeMask.html Demonstrates creating a document, adding a paint layer, and initializing a ColorizeMask with custom keystroke colors and settings. ```python window = Krita.instance().activeWindow() doc = Krita.instance().createDocument(10, 3, "Test", "RGBA", "U8", "", 120.0) window.addView(doc) root = doc.rootNode() node = doc.createNode("layer", "paintLayer") root.addChildNode(node, None) nodeData = QByteArray.fromBase64(b"AAAAAAAAAAAAAAAAEQYMBhEGDP8RBgz/EQYMAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARBgz5EQYM/xEGDAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQYMAhEGDAkRBgwCAAAAAAAAAAAAAAAA") node.setPixelData(nodeData,0,0,10,3) cols = [ ManagedColor('RGBA','U8',''), ManagedColor('RGBA','U8','') ] cols[0].setComponents([0.65490198135376, 0.345098048448563, 0.474509805440903, 1.0]) cols[1].setComponents([0.52549022436142, 0.666666686534882, 1.0, 1.0]) keys = [ QByteArray.fromBase64(b"/48AAAAAAAAAAAAAAAAAAAAAAACmCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), QByteArray.fromBase64(b"AAAAAAAAAACO9ocAAAAAAAAAAAAAAAAAAAAAAMD/uQAAAAAAAAAAAAAAAAAAAAAAGoMTAAAAAAAAAAAA") ] mask = doc.createColorizeMask('c1') node.addChildNode(mask,None) mask.setEditKeyStrokes(True) mask.setUseEdgeDetection(True) mask.setEdgeDetectionSize(4.0) mask.setCleanUpAmount(70.0) mask.setLimitToDeviceBounds(True) mask.initializeKeyStrokeColors(cols) for col,key in zip(cols,keys): mask.setKeyStrokePixelData(key,col,0,0,20,3) mask.updateMask() mask.setEditKeyStrokes(False) mask.setShowOutput(True) ``` -------------------------------- ### flipOptionsMode() Source: https://apidoc.krita.maou-maou.fr/kapi-class-AngleSelector.html Gets the current mode for displaying flip options. The default mode is 'Buttons'. ```APIDOC ## flipOptionsMode() ### Description Gets the mode in which the flip options should be shown. The default is Buttons. ### Return The mode in which the flip options should be shown (string). ``` -------------------------------- ### Create and Display a New Document Source: https://apidoc.krita.maou-maou.fr/kapi-class-Krita.html Demonstrates how to create a new document with specified dimensions and properties, and then display it in an active window. The document is registered with the Krita application and will persist until Krita exits unless explicitly closed. ```python 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() ``` -------------------------------- ### name() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Channel.html Gets the name of the channel. ```APIDOC ## name() ### Description Gets the name of the channel. ### Return str - the name of the channel. ``` -------------------------------- ### Print Current Brush Preset and Settings Source: https://apidoc.krita.maou-maou.fr/kapi-class-Preset.html This snippet demonstrates how to access the current brush preset, create a Preset object, and print its XML representation. It requires importing the Krita module. ```python from krita import * view = Krita.instance().activeWindow().activeView() preset = Preset(view.currentBrushPreset()) print(preset.toXML()) ``` -------------------------------- ### name() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Resource.html Gets the user-visible name of the resource. ```APIDOC ## name() ### Description The user-visible name of the resource. ### Return (no description provided) ``` -------------------------------- ### ColorizeMask Methods Source: https://apidoc.krita.maou-maou.fr/kapi-class-ColorizeMask.html This section details the various methods available for interacting with the ColorizeMask object, including setting and getting properties, managing keystrokes, and updating the mask. ```APIDOC ## ColorizeMask Methods This section details the various methods available for interacting with the ColorizeMask object, including setting and getting properties, managing keystrokes, and updating the mask. ### `cleanUpAmount()` Returns a float value between 0.0 and 100.0 representing the cleanup amount. 0.0 means no cleanup is performed, while 100.0 is the most aggressive. ### `edgeDetectionSize()` Returns a float value representing the edge detection size in pixels. ### `editKeyStrokes()` Returns a boolean indicating whether the edit keystrokes mode is enabled. This mode allows modification of keystrokes on the active Colorize Mask. ### `initializeKeyStrokeColors(colors: list[ManagedColor], transparentIndex: int = 1)` Sets the colors to be used for the Colorize Mask's keystrokes. **Parameters:** - `colors`: A list of `ManagedColor` objects to use for the keystrokes. - `transparentIndex`: The index of the color to be marked as transparent (defaults to 1). ### `keyStrokePixelData(color: ManagedColor, x: int, y: int, w: int, h: int)` Reads a specified rectangle from the keystroke image data and returns it as a `QByteArray`. The pixel data is ordered row-first, starting from the top-left. **Parameters:** - `color`: The `ManagedColor` to get keystroke pixel data from. - `x`: The x-coordinate from where to start reading. - `y`: The y-coordinate from where to start reading. - `w`: The width (number of columns) to read. - `h`: The height (number of rows) to read. **Returns:** A `QByteArray` containing the pixel data. This array may be empty. ### `keyStrokesColors()` Returns a list of `ManagedColor` objects representing the colors used in the Colorize Mask's keystrokes. ### `limitToDeviceBounds()` Returns a boolean indicating whether the limit to device bounds feature is enabled. ### `removeKeyStroke(color: ManagedColor)` Removes a specified `ManagedColor` from the Colorize Mask's keystrokes. **Parameters:** - `color`: The `ManagedColor` to be removed. ### `resetCache()` Resets the internal cache of the Colorize Mask. ### `setCleanUpAmount(value: float)` Sets the cleanup amount for the Colorize Mask. This attempts to handle messy strokes that overlap line art incorrectly. **Parameters:** - `value`: A float value from 0.0 to 100.00, where 0.0 is no cleanup and 100.00 is the most aggressive. ### `setEdgeDetectionSize(value: float)` Sets the edge detection size. This value should ideally be the thinnest line on the image. **Parameters:** - `value`: A float value representing the edge size to detect in pixels. ### `setEditKeyStrokes(enabled: bool)` Toggles the Colorize Mask's edit keystrokes mode. **Parameters:** - `enabled`: A boolean value to enable or disable edit keystrokes mode. ### `setKeyStrokePixelData(value: QByteArray, color: ManagedColor, x: int, y: int, w: int, h: int)` Sets the pixel data for a specific keystroke color within a given rectangle. **Parameters:** - `value`: A `QByteArray` containing the pixel data. - `color`: The `ManagedColor` to associate the pixel data with. - `x`: The x-coordinate of the rectangle. - `y`: The y-coordinate of the rectangle. - `w`: The width of the rectangle. - `h`: The height of the rectangle. **Returns:** A boolean indicating success or failure. ### `setLimitToDeviceBounds(value: bool)` Enables or disables the limit to device bounds feature. **Parameters:** - `value`: A boolean value to enable or disable the feature. ### `setShowOutput(enabled: bool)` Enables or disables the display of the Colorize Mask's output. **Parameters:** - `enabled`: A boolean value to enable or disable showing the output. ### `setUseEdgeDetection(value: bool)` Enables or disables edge detection for the Colorize Mask. **Parameters:** - `value`: A boolean value to enable or disable edge detection. ### `showOutput()` Returns a boolean indicating whether the Colorize Mask's output is currently being shown. ### `transparencyIndex()` Returns the integer index of the color designated as transparent. ### `updateMask(force: bool = False)` Updates the Colorize Mask. The `force` parameter can be used to force an update even if no changes are detected. **Parameters:** - `force`: A boolean value to force the update (defaults to `False`). ### `useEdgeDetection()` Returns a boolean indicating whether edge detection is currently enabled for the Colorize Mask. ### `type()` Returns the type of the mask as a string. This method is re-implemented from a base class. ``` -------------------------------- ### Get Current Brush Preset Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the currently selected brush preset as a Resource object. ```python currentBrushPreset() ``` -------------------------------- ### Create and Apply a Selection Source: https://apidoc.krita.maou-maou.fr/kapi-class-Selection.html This snippet demonstrates how to create a new selection, define its area, and apply it to a node using the 'select' and 'cut' methods. ```python from krita import * d = Application.activeDocument() n = d.activeNode() r = n.bounds() s = Selection() s.select(r.width() / 3, r.height() / 3, r.width() / 3, r.height() / 3, 255) s.cut(n) ``` -------------------------------- ### collapsed Source: https://apidoc.krita.maou-maou.fr/kapi-class-Node.html Gets the collapsed state of the node. ```APIDOC ## collapsed() ➞ bool ### Description Returns the collapsed state of this node. ### Return - **bool** - The collapsed state of the node. ``` -------------------------------- ### fillPattern(transform: QTransform = QTransform()) Source: https://apidoc.krita.maou-maou.fr/kapi-class-Scratchpad.html Fills the scratchpad with the current pattern, with an optional transform to adjust scale and rotation. ```APIDOC ## fillPattern(transform: QTransform = QTransform()) ### Description Fills the entire scratchpad with the current pattern. ### Parameters - **transform** (QTransform) - Optional. A QTransform that allows defining the pattern's scale and rotation properties. Defaults to an identity transform. ``` -------------------------------- ### name Source: https://apidoc.krita.maou-maou.fr/kapi-class-Filter.html Gets the internal name of the filter. ```APIDOC ## name ### Description Get the internal name of this filter. ### Method name ### Return - **str** - the name. ``` -------------------------------- ### filename() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Resource.html Gets the filename of the resource, if it is associated with a file. ```APIDOC ## filename() ### Description The filename of the resource, if present. Not all resources are loaded from files. ### Return (no description provided) ``` -------------------------------- ### Iterate and Print Resource Names Source: https://apidoc.krita.maou-maou.fr/kapi-class-Resource.html This snippet demonstrates how to access all presets from the Application's resources and print the name of each preset. It requires the Application object to be available. ```python allPresets = Application.resources("preset") for preset in allPresets: print(preset.name()) ``` -------------------------------- ### Get Resource Name Source: https://apidoc.krita.maou-maou.fr/kapi-class-Resource.html Retrieves the user-visible name of the resource. ```python resource.name() ``` -------------------------------- ### openWindow Source: https://apidoc.krita.maou-maou.fr/kapi-class-Krita.html Creates a new main window for the Krita application. The window is not shown by default. ```APIDOC ## openWindow ### Description Creates a new main window for the Krita application. The window is not shown by default. ### Return #### Success Response - **window** (Window) - The newly created window. ``` -------------------------------- ### increasingDirection() Source: https://apidoc.krita.maou-maou.fr/kapi-class-AngleSelector.html Gets the direction in which the angle increases in the angle gauge. ```APIDOC ## increasingDirection() ### Description Gets the direction in which the angle increases in the angle gauge. ### Return The direction in which the angle increases (string). ``` -------------------------------- ### PresetChooser Constructor Source: https://apidoc.krita.maou-maou.fr/kapi-class-PresetChooser.html Initializes a new instance of the PresetChooser widget. The parent QWidget is optional. ```APIDOC ## PresetChooser Constructor ### Description Initializes a new instance of the PresetChooser widget. ### Parameters - **parent** (QWidget) - Optional - The parent widget for this PresetChooser instance. ### Return (no description provided) ``` -------------------------------- ### preferredCenter() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Canvas.html Gets the image pixel that is currently centered in the view. ```APIDOC ## preferredCenter() ### Description Returns the position of the image pixel that is placed in the center of the current view. ### Return - QPointF: The coordinates of the center image pixel. ``` -------------------------------- ### Get Window Object Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the Window object associated with this view. ```python window() ``` -------------------------------- ### Swatch Constructor (copy with parent) Source: https://apidoc.krita.maou-maou.fr/kapi-class-Swatch.html Constructs a Swatch object by copying another Swatch, optionally with a parent QObject. ```APIDOC ## Swatch(rhs: Swatch, parent: QObject = None) ### Description Constructs a new Swatch object by copying an existing Swatch, with an optional parent QObject. ### Parameters #### Path Parameters - **rhs** (Swatch) - (no description provided) - **parent** (QObject) - (no description provided) ### Return (no description provided) ``` -------------------------------- ### createAction(id: str, text: str = "", menuLocation: str = "tools/scripts") Source: https://apidoc.krita.maou-maou.fr/kapi-class-Window.html Creates a QAction object and adds it to the window's action manager. Actions can be placed in specific menu locations. ```APIDOC ## createAction(id: str, text: str = "", menuLocation: str = "tools/scripts") ### Description Creates a QAction object and adds it to the action manager for this Window. ### Method N/A (Method call) ### Parameters #### Path Parameters - **id** (str) - Required - The unique id for the action. This will be used to propertize the action if any .action file is present. - **text** (str) - Optional - The user-visible text of the action. If empty, the text from the .action file is used. - **menuLocation** (str) - Optional - A /-separated string that describes which menu the action should be placed in. Default is "tools/scripts". ### Return QAction: The newly created action. ``` -------------------------------- ### Get Selected Nodes Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns a list of the currently selected nodes. ```python selectedNodes() ``` -------------------------------- ### Get Document Object Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the Document object that this view is displaying. ```python document() ``` -------------------------------- ### loadScratchpadImage(image: QImage) Source: https://apidoc.krita.maou-maou.fr/kapi-class-Scratchpad.html Loads a QImage object into the scratchpad. ```APIDOC ## loadScratchpadImage(image: QImage) ### Description Loads image data into the scratchpad. ### Parameters - **image** (QImage) - The image object to load. ``` -------------------------------- ### Get Palette Comment Source: https://apidoc.krita.maou-maou.fr/kapi-class-Palette.html Retrieves the comment or description associated with the palette. ```python comment() ➞ str ``` -------------------------------- ### Create and Modify a ManagedColor (Yellow) Source: https://apidoc.krita.maou-maou.fr/kapi-class-ManagedColor.html Demonstrates how to create a ManagedColor object for yellow, set its components, and convert it to a QColor for the canvas. ```python colorYellow = ManagedColor("RGBA", "U8", "") QVector yellowComponents = colorYellow.components() yellowComponents[0] = 1.0 yellowComponents[1] = 1.0 yellowComponents[2] = 0 yellowComponents[3] = 1.0 colorYellow.setComponents(yellowComponents) QColor yellow = colorYellow.colorForCanvas(canvas) ``` -------------------------------- ### activate() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Window.html Activates this Krita window. This brings the window to the front and makes it the active window. ```APIDOC ## activate() ### Description Activates this Krita window. ### Method N/A (Method call) ### Parameters None ``` -------------------------------- ### bounds Source: https://apidoc.krita.maou-maou.fr/kapi-class-Node.html Gets the exact bounds of the node's paint device. ```APIDOC ## bounds() ➞ QRect ### Description Returns the exact bounds of the node's paint device. ### Return - **QRect** - The bounds, or an empty QRect if the node has no paint device or is empty. ``` -------------------------------- ### Palette Constructor Source: https://apidoc.krita.maou-maou.fr/kapi-class-Palette.html Initializes a Palette object with a given resource. This is the constructor for the Palette class. ```APIDOC ## Palette(resource: Resource) ### Description Initializes a Palette object with a given resource. ### Parameters - **resource** (Resource) - (no description provided) ### Return (no description provided) ``` -------------------------------- ### Get Color Depth Source: https://apidoc.krita.maou-maou.fr/kapi-class-ManagedColor.html Retrieves the color depth of the ManagedColor object. ```python colorDepth() -> str ``` -------------------------------- ### isLastValid Source: https://apidoc.krita.maou-maou.fr/kapi-class-IntParseSpinBox.html Get if the last expression entered into the spinbox is a valid one. ```APIDOC ## isLastValid() -> bool ### Description Get if the last expression entered is a valid one. ### Return - **bool**: true if the last expression entered is valid, false otherwise. ``` -------------------------------- ### Create Thumbnail Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Generates a thumbnail of the document with specified width and height. If the requested size exceeds limits, a null QImage may be created. ```python thumbnail_image = newDoc.thumbnail(w=200, h=150) ``` -------------------------------- ### setFullClipRangeStartTime Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Sets the start time for the full clip range of the animation. ```APIDOC ## setFullClipRangeStartTime(startTime: int) ### Description Set start time of animation ### Parameters #### Path Parameters * **startTime** (int) - Required - (no description provided) ``` -------------------------------- ### PaletteView Constructor Source: https://apidoc.krita.maou-maou.fr/kapi-class-PaletteView.html Initializes a new instance of the PaletteView class. It can optionally take a QWidget as a parent. ```APIDOC ## PaletteView(parent: QWidget = None) ### Description Initializes a new instance of the PaletteView class. ### Parameters #### Path Parameters - **parent** (QWidget) - Optional - The parent widget for this PaletteView instance. ``` -------------------------------- ### flakeToImageTransform Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Gets the transformation of the image relative to the view without rotation and mirroring. ```APIDOC ## flakeToImageTransform ### Description Gets the transformation of the image relative to the view, excluding rotation and mirroring. ### Method GET ### Endpoint `/view/flakeToImageTransform` ### Return #### Success Response (200) - **transform** (QTransform) - The transformation matrix. ### Response Example ```json { "transform": { "a": 1.0, "b": 0.0, "c": 0.0, "d": 1.0, "e": 0.0, "f": 0.0 } } ``` ``` -------------------------------- ### openDocument Source: https://apidoc.krita.maou-maou.fr/kapi-class-Krita.html Creates a new document, registers it with the Krita application, and loads the specified file. ```APIDOC ## openDocument ### Description Creates a new document, registers it with the Krita application, and loads the specified file. ### Parameters #### Path Parameters - **filename** (str) - Required - The file to open in the document. ### Return #### Success Response - **document** (Document) - The opened document. ``` -------------------------------- ### flakeToDocumentTransform Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Gets the transformation of the document relative to the view without rotation and mirroring. ```APIDOC ## flakeToDocumentTransform ### Description Gets the transformation of the document relative to the view, excluding rotation and mirroring. ### Method GET ### Endpoint `/view/flaketodocumenttransform` ### Return #### Success Response (200) - **transform** (QTransform) - The transformation matrix. ### Response Example ```json { "transform": { "a": 1.0, "b": 0.0, "c": 0.0, "d": 1.0, "e": 0.0, "f": 0.0 } } ``` ``` -------------------------------- ### flakeToCanvasTransform Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Gets the transformation of the canvas relative to the view without rotation and mirroring. ```APIDOC ## flakeToCanvasTransform ### Description Gets the transformation of the canvas relative to the view, excluding rotation and mirroring. ### Method GET ### Endpoint `/view/flaketocanvastransform` ### Return #### Success Response (200) - **transform** (QTransform) - The transformation matrix. ### Response Example ```json { "transform": { "a": 1.0, "b": 0.0, "c": 0.0, "d": 1.0, "e": 0.0, "f": 0.0 } } ``` ``` -------------------------------- ### Preset Class Constructor Source: https://apidoc.krita.maou-maou.fr/kapi-class-Preset.html Initializes a Preset object with a given Resource object. This is used to create a Preset instance from an existing resource. ```python Preset(resource: Resource) ``` -------------------------------- ### Get Selection Y Coordinate Source: https://apidoc.krita.maou-maou.fr/kapi-class-Selection.html The 'y' method returns the y-coordinate of the top-left corner of the selection. ```python y() ➞ int ``` -------------------------------- ### windows Source: https://apidoc.krita.maou-maou.fr/kapi-class-Krita.html Returns a list of all open windows in Krita. ```APIDOC ## windows ### Description Returns a list of all windows. ### Return * list[Window] - A list of all windows. ``` -------------------------------- ### Get Current Pattern Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the currently selected pattern as a Resource object. ```python currentPattern() ``` -------------------------------- ### instance Source: https://apidoc.krita.maou-maou.fr/kapi-class-Krita.html Retrieves the singleton instance of the Krita Application object. ```APIDOC ## instance ### Description Retrieves the singleton instance of the Krita Application object. ### Return #### Success Response - **instance** (Application) - The singleton instance of the Krita Application object. ``` -------------------------------- ### Get Current Gradient Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the currently selected gradient as a Resource object. ```python currentGradient() ``` -------------------------------- ### Get Brush Size Value Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the current brush size in pixels. ```python brushSize() ``` -------------------------------- ### Preset Constructor Source: https://apidoc.krita.maou-maou.fr/kapi-class-Preset.html Initializes a Preset object with a given Resource. This is used to create a Preset object from an existing brush preset. ```APIDOC ## Preset Constructor ### Description Initializes a Preset object with a given Resource. This is used to create a Preset object from an existing brush preset. ### Parameters * **resource** (Resource) - No description provided. ### Return (No description provided) ``` -------------------------------- ### scalingFilter() Source: https://apidoc.krita.maou-maou.fr/kapi-class-FileLayer.html Gets the current scaling filter used for the referenced file in the FileLayer. ```APIDOC ## scalingFilter() ### Description Returns the filter with which the file referenced is scaled. ### Method scalingFilter() ### Return (no description provided) ``` -------------------------------- ### prefix() Source: https://apidoc.krita.maou-maou.fr/kapi-class-AngleSelector.html Gets the prefix string displayed before the angle value in the spin box. ```APIDOC ## prefix() ### Description Gets the prefix shown in the spin box. ### Return The prefix shown in the spin box (string). ``` -------------------------------- ### GridConfig Methods Source: https://apidoc.krita.maou-maou.fr/kapi-class-GridConfig.html This section provides documentation for the methods of the GridConfig class, detailing their functionality, parameters, and return values. These methods allow users to interact with and modify Krita's grid settings. ```APIDOC ## angleAspectLocked() ### Description Returns status of "Aspect locked" property for angles values (mean, left and right angles values are linked to keep ratio). AngleAspectLocked value is used for grid type "isometric" and "isometric_legacy". ### Return If locked, return True. --- ## angleLeft() ### Description Returns left angle (in degrees) of isometric grid for document. AngleLeft value is used for grid type "isometric". ### Return A positive decimal value, in range [0.00 - 89.00] --- ## angleLeftActive() ### Description Returns if left angle grid is active. Spacing value is used for grid type "isometric". ### Return A boolean which indicate if left angle grid is active or not --- ## angleRight() ### Description Returns right angle (in degrees) of isometric grid for document. AngleRight value is used for grid type "isometric". ### Return A positive decimal value, in range [0.00 - 89.00] --- ## angleRightActive() ### Description Returns if right angle grid is active. Spacing value is used for grid type "isometric". ### Return A boolean which indicate if right angle grid is active or not --- ## cellSize() ### Description Returns grid cell border size (in pixels) for document. Cell spacing value is used for grid type "isometric". ### Return A positive integer value, in range [10 - 1000] --- ## cellSpacing() ### Description Returns grid cell spacing (in pixels) for document. Cell spacing value is used for grid type "isometric_legacy". ### Return A positive integer value, minimum value is 10 --- ## colorMain() ### Description Returns grid main line color ### Return The color for grid main line --- ## colorSubdivision() ### Description Returns grid subdivision line color. ColorSubdivision value is used for grid type "rectangular". ### Return The color for grid subdivision line --- ## colorVertical() ### Description Returns grid vertical line color. ColorSubdivision value is used for grid type "isometric". ### Return The color for grid vertical line --- ## fromXml(xmlContent: str) ### Description Load grid definition from an XML document ### Parameters xmlContent| xml content provided as a string ### Return True if xml content is valid and grid has been loaded, otherwise False --- ## lineTypeMain() ### Description Returns grid main line type ### Return The main line type for grid in current document Can be: - "solid" - "dashed" - "dotted" --- ## lineTypeSubdivision() ### Description Returns grid subdivision line type ### Return The subdivision line type for grid in current document Can be: - "solid" - "dashed" - "dotted". LineTypeSubdivision value is used for grid type "rectangular". --- ## lineTypeVertical() ### Description Returns grid vertical line type ### Return The vertical line type for grid in current document Can be: - "solid" - "dashed" - "dotted" - "none". LineTypeVertical value is used for grid type "isometric". --- ## offset() ### Description Returns grid offset (in pixels, from origin) for document. ### Return A QPoint that define X and Y offset. --- ## offsetAspectLocked() ### Description Returns status of "Aspect locked" property for offset values (X and Y values are linked to keep ratio) --- ## setAngleAspectLocked(angleAspectLocked: bool) ### Description Sets the status of the "Aspect locked" property for angles. --- ## setAngleLeft(angleLeft: float) ### Description Sets the left angle (in degrees) for the isometric grid. --- ## setAngleLeftActive(active: bool) ### Description Activates or deactivates the left angle grid. --- ## setAngleRight(angleRight: float) ### Description Sets the right angle (in degrees) for the isometric grid. --- ## setAngleRightActive(active: bool) ### Description Activates or deactivates the right angle grid. --- ## setCellSize(cellSize: int) ### Description Sets the grid cell border size in pixels. --- ## setCellSpacing(cellSpacing: int) ### Description Sets the grid cell spacing in pixels. --- ## setColorMain(colorMain: QColor) ### Description Sets the grid main line color. --- ## setColorSubdivision(colorSubdivision: QColor) ### Description Sets the grid subdivision line color. --- ## setColorVertical(colorVertical: QColor) ### Description Sets the grid vertical line color. --- ## setLineTypeMain(lineType: str) ### Description Sets the grid main line type. --- ## setLineTypeSubdivision(lineType: str) ### Description Sets the grid subdivision line type. --- ## setLineTypeVertical(lineType: str) ### Description Sets the grid vertical line type. --- ## setOffset(offset: QPoint) ### Description Sets the grid offset in pixels from the origin. --- ## setOffsetAspectLocked(offsetAspectLocked: bool) ### Description Sets the status of the "Aspect locked" property for offset values. --- ## setSnap(snap: bool) ### Description Enables or disables snapping to the grid. --- ## setSpacing(spacing: QPoint) ### Description Sets the grid spacing using a QPoint for X and Y values. --- ## setSpacingActiveHorizontal(active: bool) ### Description Activates or deactivates horizontal spacing for the grid. --- ## setSpacingActiveVertical(active: bool) ### Description Activates or deactivates vertical spacing for the grid. --- ## setSpacingAspectLocked(spacingAspectLocked: bool) ### Description Sets the status of the "Aspect locked" property for spacing values. --- ## setSubdivision(subdivision: int) ### Description Sets the grid subdivision value. --- ## setType(gridType: str) ### Description Sets the type of the grid. --- ## setVisible(visible: bool) ### Description Sets the visibility of the grid. --- ## snap() ### Description Returns the current snap status of the grid. ### Return True if snapping is enabled, False otherwise. --- ## spacing() ### Description Returns the grid spacing (in pixels) for document. ### Return A QPoint that defines X and Y spacing. --- ## spacingActiveHorizontal() ### Description Returns if horizontal spacing is active for the grid. ### Return True if horizontal spacing is active, False otherwise. --- ## spacingActiveVertical() ### Description Returns if vertical spacing is active for the grid. ### Return True if vertical spacing is active, False otherwise. --- ## spacingAspectLocked() ### Description Returns the status of the "Aspect locked" property for spacing values. --- ## subdivision() ### Description Returns the grid subdivision value. --- ## toXml() ### Description Converts the current grid configuration to an XML string. ### Return A string containing the XML representation of the grid configuration. --- ## type() ### Description Returns the current type of the grid. --- ## visible() ### Description Returns the visibility status of the grid. ### Return True if the grid is visible, False otherwise. ``` -------------------------------- ### Create and Add a Fill Layer Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html This snippet demonstrates how to create a fill layer with a specific pattern, configure it, and add it to the document's root node. It also refreshes the document's projection after the layer is added. ```python from krita import * d = Krita.instance().activeDocument() i = InfoObject() i.setProperty("pattern", "Cross01.pat") s = Selection() s.select(0, 0, d.width(), d.height(), 255) n = d.createFillLayer("test", "pattern", i, s) r = d.rootNode() c = r.childNodes() r.addChildNode(n, c[0]) d.refreshProjection() ``` -------------------------------- ### minimum() Source: https://apidoc.krita.maou-maou.fr/kapi-class-AngleSelector.html Gets the minimum value allowed for the angle. The default minimum is 0. ```APIDOC ## minimum() ### Description Gets the minimum value for the angle. The default is 0. ### Return The minimum value for the angle (float). ``` -------------------------------- ### Create and Add Paint Layer Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Demonstrates creating a new paint layer and adding it as a child to the root node of a document. This is useful for programmatically structuring layers within a Krita document. ```python d = Application.createDocument(1000, 1000, "Test", "RGBA", "U8", "", 120.0) root = d.rootNode() print(root.childNodes()) l2 = d.createNode("layer2", "paintLayer") print(l2) root.addChildNode(l2, None) print(root.childNodes()) ``` -------------------------------- ### maximum() Source: https://apidoc.krita.maou-maou.fr/kapi-class-AngleSelector.html Gets the maximum value allowed for the angle. The default maximum is 360. ```APIDOC ## maximum() ### Description Gets the maximum value for the angle. The default is 360. ### Return The maximum value for the angle (float). ``` -------------------------------- ### Scratchpad Constructor Source: https://apidoc.krita.maou-maou.fr/kapi-class-Scratchpad.html Initializes a new instance of the Scratchpad class. It requires a View object and a default color, with an optional parent widget. ```APIDOC ## Scratchpad(view: View, defaultColor: QColor, parent: QWidget = None) ### Description Initializes a new instance of the Scratchpad class. ### Parameters - **view** (View) - No description provided. - **defaultColor** (QColor) - No description provided. - **parent** (QWidget) - Optional parent widget. ``` -------------------------------- ### Swatch Constructor (copy) Source: https://apidoc.krita.maou-maou.fr/kapi-class-Swatch.html Constructs a Swatch object by copying another Swatch. ```APIDOC ## Swatch(rhs: Swatch) ### Description Constructs a new Swatch object by copying an existing Swatch. ### Parameters #### Path Parameters - **rhs** (Swatch) - (no description provided) ### Return (no description provided) ``` -------------------------------- ### fillForeground() Source: https://apidoc.krita.maou-maou.fr/kapi-class-Scratchpad.html Fills the entire scratchpad area with the current foreground color. ```APIDOC ## fillForeground() ### Description Fills the entire scratchpad with the current foreground color. ``` -------------------------------- ### Get Pattern Size Value Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the current pattern size value for the brush. ```python patternSize() ``` -------------------------------- ### Get Painting Opacity Value Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the current painting opacity value for the brush. ```python paintingOpacity() ``` -------------------------------- ### useFlatSpinBox(newUseFlatSpinBox: bool) Source: https://apidoc.krita.maou-maou.fr/kapi-class-AngleSelector.html Sets whether the spin box should have a flat appearance (no border or background). ```APIDOC ## useFlatSpinBox(newUseFlatSpinBox: bool) ### Description Sets whether the spin box should be flat. ### Parameters - **newUseFlatSpinBox** (bool) - True to use a flat spin box, false otherwise. ``` -------------------------------- ### thumbnail Source: https://apidoc.krita.maou-maou.fr/kapi-class-Document.html Creates a thumbnail of the document with the specified dimensions. If the requested size is too large, a null QImage is returned. ```APIDOC ## thumbnail ### Description Creates a thumbnail of the given dimensions. If the requested size is too big a null QImage is created. ### Method `thumbnail(w: int, h: int) ➞ QImage` ### Parameters #### Path Parameters - **w** (int) - Description: (no description provided) - **h** (int) - Description: (no description provided) ### Return - **QImage** - A QImage representing the layer contents. ``` -------------------------------- ### Get Painting Flow Value Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the current painting flow value for the brush. ```python paintingFlow() ``` -------------------------------- ### Get Selection Width Source: https://apidoc.krita.maou-maou.fr/kapi-class-Selection.html The 'width' method returns the current width of the selection in pixels. ```python width() ➞ int ``` -------------------------------- ### currentPreset() Source: https://apidoc.krita.maou-maou.fr/kapi-class-PresetChooser.html Retrieves the currently selected preset. ```APIDOC ## currentPreset() ### Description Returns a Resource wrapper around the currently selected preset. ### Return - **Resource** - A wrapper around the currently selected preset. ``` -------------------------------- ### Get Selection Height Source: https://apidoc.krita.maou-maou.fr/kapi-class-Selection.html The 'height' method returns the current height of the selection in pixels. ```python height() ➞ int ``` -------------------------------- ### Get Current Blending Mode Source: https://apidoc.krita.maou-maou.fr/kapi-class-View.html Returns the current blending mode identifier for the brush. ```python currentBlendingMode() ```