inkex.extensions module

A helper module for creating Inkscape effect extensions

This provides the basic generic types of extensions which most writers should use in their code. See below for the different types.

class inkex.extensions.CallExtension(*args, **kwargs)[source]

Bases: inkex.base.TempDirMixin, inkex.extensions.InputExtension

Call an external program to get the output

call(input_file, output_file)[source]

Call whatever programs are needed to get the desired result.

input_ext = 'svg'
load(stream)[source]

But load certainly is, we give a more exact message here

load_raw()[source]

Create the temporary directory

output_ext = 'svg'
class inkex.extensions.ColorExtension[source]

Bases: inkex.extensions.EffectExtension

A standard way to modify colours in an svg document.

_modify_color(name, color)[source]

Pre-process color value to filter out bad colors

_ref_cloned(old_id, new_id, style, name)[source]
effect()[source]

Apply some effects on the document or local context

modify_color(name, color)[source]

Replace this method with your colour modifier method

modify_opacity(name, opacity)[source]

Optional opacity modification

process_element(elem, gradients=None)[source]

Process one of the selected elements

process_elements(elem)[source]

Process multiple elements (gradients)

process_none = False
select_all: Tuple[Type[BaseElement], ...] = (<class 'inkex.elements._base.ShapeElement'>,)
class inkex.extensions.EffectExtension[source]

Bases: inkex.base.SvgThroughMixin, inkex.base.InkscapeExtension

Takes the SVG from Inkscape, modifies the selection or the document and returns an SVG to Inkscape.

class inkex.extensions.GenerateExtension[source]

Bases: inkex.extensions.EffectExtension

Does not need any SVG, but instead just outputs an SVG fragment which is inserted into Inkscape, centered on the selection.

container_label = ''
container_layer = False
container_transform()[source]

Generate the transformation for the container group, the default is to return the center position of the svg document or view port.

create_container()[source]

Return the container the generated elements will go into.

Default is a new layer or current layer depending on the container_layer flag.

effect()[source]

Apply some effects on the document or local context

generate()[source]

Return an SVG fragment to be inserted into the selected layer of the document OR yield multiple elements which will be grouped into a container group element which will be given an automatic label and transformation.

class inkex.extensions.InputExtension[source]

Bases: inkex.base.SvgOutputMixin, inkex.base.InkscapeExtension

Takes any type of file as input and outputs SVG which Inkscape can read.

Used in functions for Open

effect()[source]

Effect isn’t needed for a lot of Input extensions

load(stream)[source]

But load certainly is, we give a more exact message here

class inkex.extensions.OutputExtension[source]

Bases: inkex.base.SvgInputMixin, inkex.base.InkscapeExtension

Takes the SVG from Inkscape and outputs it to something that’s not an SVG.

Used in functions for Save As

effect()[source]

Effect isn’t needed for a lot of Output extensions

save(stream)[source]

But save certainly is, we give a more exact message here

class inkex.extensions.RasterOutputExtension[source]

Bases: inkex.base.InkscapeExtension

Takes a PNG from Inkscape and outputs it to another rather format.

document: Union[None, bytes, str, etree]
effect()[source]

Not needed since image isn’t being changed

file_io: Optional[IO]
load(stream)[source]

Takes the input stream and creates a document for parsing

save(stream)[source]

Implement raster image saving here from PIL

class inkex.extensions.TemplateExtension[source]

Bases: inkex.extensions.EffectExtension

Provide a standard way of creating templates.

arg_size(unit='px')[source]

Argument is a string of the form X[unit]xY[unit], default units apply when missing

effect()[source]

Creates a template, do not over-ride

get_size()[source]

Get the size of the new template (defaults to size options)

get_template()[source]

Can be over-ridden with custom svg loading here

set_namedview(width, height, unit)[source]

Setup the document namedview

size_rex = re.compile('([\\d.]*)(\\w\\w)?x([\\d.]*)(\\w\\w)?')
template_id = 'SVGRoot'
class inkex.extensions.TextExtension[source]

Bases: inkex.extensions.EffectExtension

A base effect for changing text in a document.

effect()[source]

Apply some effects on the document or local context

static map_char(char)[source]

Replaceable map_char method for processing each letter

newline = True
newpar = True
process_chardata(text)[source]

Replaceable chardata method for processing the text

process_element(node)[source]

Reverse the node text