inkex.turtle module#

A Python path turtle for Inkscape extensions

class inkex.turtle.PathTurtle(home=(0, 0))[source]#

Bases: object

A Python path turtle

Changed in version 1.2: pTurtle has been renamed to PathTurtle.

forward(mag: float)[source]#

Move turtle forward by mag in the current direction.

backward(mag)[source]#

Move turtle backward by mag in the current direction.

right(deg)[source]#

Rotate turtle right by deg degrees.

Changed in inkex 1.2: The turtle now rotates right (previously left) when

calling this method.

left(deg)[source]#

Rotate turtle left by deg degrees.

Changed in inkex 1.2: The turtle now rotates left (previously right) when

calling this method.

penup()[source]#

Enable non-drawing / moving mode

pendown()[source]#

Enable drawing mode

pentoggle()[source]#

Switch between drawing and moving mode

home()[source]#

Move to home position

clean()[source]#

Delete current path

clear()[source]#

Delete current path and move to home

setpos(arg)[source]#

Move/draw to position, depending on the current state

getpos()[source]#

Returns the current position

setheading(deg)[source]#

Set the heading to deg degrees

getheading()[source]#

Returns the heading in degrees

sethome(arg)[source]#

Set home position

getPath()[source]#

Returns the current path

rtree(size, minimum, pt=False)[source]#

Generates a random tree

fd(mag: float)#

Move turtle forward by mag in the current direction.

bk(mag)#

Move turtle backward by mag in the current direction.

rt(deg)#

Rotate turtle right by deg degrees.

Changed in inkex 1.2: The turtle now rotates right (previously left) when

calling this method.

lt(deg)#

Rotate turtle left by deg degrees.

Changed in inkex 1.2: The turtle now rotates left (previously right) when

calling this method.

pu()#

Enable non-drawing / moving mode

pd()#

Enable drawing mode

inkex.turtle.pTurtle#

alias of inkex.turtle.PathTurtle

class inkex.turtle.PathBuilder(style: inkex.styles.Style)[source]#

Bases: object

This helper class can be used to construct a path and insert it into a document.

New in version 1.2.

add(command: Union[inkex.paths.interfaces.PathCommand, List[inkex.paths.interfaces.PathCommand]])[source]#

Add a Path command to the Helper

Parameters

command (Union[PathCommand, List[PathCommand]]) – A (list of) PathCommand(s) to be appended.

terminate()[source]#

Terminates current subpath. This method does nothing by default and is supposed to be overridden in subclasses.

append_next(sibling_before: inkex.elements._base.BaseElement)[source]#

Insert the resulting Path as inkex.elements._polygons.PathElement into the document tree.

Parameters

sibling_before (BaseElement) – The element the resulting path will be appended after.

Move_to(x, y)[source]#

Shorthand to insert an absolute move command: M x y.

Parameters
  • x (Float) – x coordinate to move to

  • y (Float) – y coordinate to move to

Line_to(x, y)[source]#

Shorthand to insert an absolute lineto command: L x y.

Parameters
  • x (Float) – x coordinate to draw a line to

  • y (Float) – y coordinate to draw a line to

class inkex.turtle.PathGroupBuilder(style)[source]#

Bases: inkex.turtle.PathBuilder

This helper class can be used to construct a group of paths that all have the same style.

New in version 1.2.

terminate()[source]#

Terminates the current Path, and appends it to the group if it is not empty.

append_next(sibling_before: inkex.elements._base.BaseElement)[source]#
Insert the resulting Path as inkex.elements._groups.Group into the

document tree.

Parameters

sibling_before (BaseElement) – The element the resulting group will be appended after.