Skip to content

Add Python Painting API

First commit is just a squashed and rebased version of Samuel Simplicio's updated version of Scott Petrovic's Python Painting API code. It adds functions to paint a line, rectangle, ellipse, polygon, or path on a Node.

On top of that, I've done some minor cleanup, improved the undo name to "Scripted Brush Stroke", and prevented the functions from crashing when called on layers that can't be painted on. As a side effect of the last point, there's a new API function Node.paintAbility() which is used to check if a node is paintable.

Test Plan

  1. Before recompiling, delete the _build/plugins/extensions/pykrita/sip/_tmp folder so it will be regenerated, otherwise running the script will cause Krita to crash with a "Chimera" crash like the one noted in the previous MR.
  2. Run this script that's modified slightly from the previous MRs:
from krita import *

activeDocument = Krita.instance().activeDocument()
activeNode = activeDocument.activeNode()
print(activeNode.paintAbility())

# paint a line
pointOne = QPoint(0,0)
pointTwo = QPoint(900, 700)
activeNode.paintLine(pointOne, pointTwo)

# paint a rectangle
paintRect = QRectF(100, 100, 500, 200)
activeNode.paintRectangle(paintRect)

# paint ellipse
paintRect = QRectF(400, 100, 200, 600)
activeNode.paintEllipse(paintRect)

# paint polygon
polyPoints = []
polyPoints.append( QPointF(20,20) )
polyPoints.append( QPointF(120,820) )
polyPoints.append( QPointF(920,120) )
activeNode.paintPolygon(polyPoints)

# paint path
path = QPainterPath()
path.moveTo(500, 500)
path.cubicTo(699, 0,  650, 650,  999, 999)
path.cubicTo(0, 99,  50, 50,  0, 0)
activeNode.paintPath(path)

# paint along a text outline path because why not
path = QPainterPath()
font = qApp.font()
font.setPointSize(40)
path.addText(QPointF(50,50), font, "Krita: Digital Painting, Creative Freedom")
activeNode.paintPath(path)

Formalities Checklist

  • I confirmed this builds.
  • I confirmed Krita ran and the relevant functions work.
  • I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
  • I made sure my commits build individually and have good descriptions as per KDE guidelines.
  • I made sure my code conforms to the standards set in the HACKING file.
  • I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
  • Does the patch add a user-visible feature? If yes, is there a documentation MR ready for it at Krita Documentation Repository?

Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.

Merge request reports