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.EffectExtension[source]#

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

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

_abc_impl = <_abc._abc_data object>#
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#
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.

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.

New in version 1.1.

effect()[source]#

Apply some effects on the document or local context

_abc_impl = <_abc._abc_data object>#
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.TempDirMixin, 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

preprocess(types_to_path=None, unlink_clones=True)[source]#

Preprocess the SVG into an export-friendly document by converting certain objects to path beforehand.

Parameters
  • types_to_path (List[str], optional) – List of element types to convert to path. Defaults to all text elements and all non-path shape elements.

  • unlink_clones (bool, optional) – If clones should be unlinked. Defaults to True.

Returns

_description_

Return type

_type_

class inkex.extensions.RasterOutputExtension[source]#

Bases: inkex.base.InkscapeExtension

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

New in version 1.1.

load(stream)[source]#

Takes the input stream and creates a document for parsing

effect()[source]#

Not needed since image isn’t being changed

save(stream)[source]#

Implement raster image saving here from PIL

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

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

Call an external program to get the output

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

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

load_raw()[source]#

Create the temporary directory

call(input_file, output_file)[source]#

Call whatever programs are needed to get the desired result.

class inkex.extensions.TemplateExtension[source]#

Bases: inkex.extensions.EffectExtension

Provide a standard way of creating templates.

size_rex = re.compile('([\\d.]*)(\\w\\w)?x([\\d.]*)(\\w\\w)?')#
template_id = 'SVGRoot'#
get_template(**kwargs)[source]#

Can be over-ridden with custom svg loading here

arg_size(unit='px')[source]#

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

get_size()[source]#

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

effect()[source]#

Creates a template, do not over-ride

set_namedview(width, height, unit)[source]#

Setup the document namedview

_abc_impl = <_abc._abc_data object>#
class inkex.extensions.ColorExtension[source]#

Bases: inkex.extensions.EffectExtension

A standard way to modify colours in an svg document.

process_none = False#
select_all: Tuple[Type[IBaseElement], ...] = (<class 'inkex.elements._base.ShapeElement'>,)#
pass_rgba = False#

If true, color and opacity are processed together (as RGBA color) by modify_color().

If false (default), they are processed independently by modify_color and modify_opacity.

New in version 1.2.

effect()[source]#

Apply some effects on the document or local context

process_elements(elem)[source]#

Process multiple elements (gradients)

process_element(elem, gradients=None)[source]#

Process one of the selected elements

_ref_cloned(old_id, new_id, element, name)[source]#
_modify_color(name, color)[source]#

Pre-process color value to filter out bad colors

modify_color(name, color)[source]#

Replace this method with your colour modifier method

modify_opacity(name, opacity)[source]#

Optional opacity modification

_abc_impl = <_abc._abc_data object>#
class inkex.extensions.TextExtension[source]#

Bases: inkex.extensions.EffectExtension

A base effect for changing text in a document.

newline = True#
newpar = True#
effect()[source]#

Apply some effects on the document or local context

process_element(node)[source]#

Reverse the node text

_abc_impl = <_abc._abc_data object>#
process_chardata(text)[source]#

Replaceable chardata method for processing the text

static map_char(char)[source]#

Replaceable map_char method for processing each letter