|
|
| (14 intermediate revisions by 4 users not shown) |
| Line 1: |
Line 1: |
| [[Category:Extensions]] | | [[Category:Extensions]] |
|
| |
|
| These modules are provided as part of Inkscape and can be found in /usr/share/inkscape/extensions on GNU/Linux, ... on Windows, and ... on Mac OS X along with the extensions bundled with Inkscape. They can be <code>import</code>ed from an extension just like any other python module.
| | This page contained API documentation for various modules in inkex. A more complete API documentation is available in the [https://inkscape.gitlab.io/extensions/documentation/source/index.html documentation of the extensions repository.] |
| | |
| == inkex.py ==
| |
| | |
| This module encapsulates the basic behavior of a script extension, allowing the author to concentrate on manipulating the SVG data. It relies on [http://lxml.de/tutorial.html <code>lxml.etree</code>] to work with the XML tree. inkex.py was originally designed to provide the Effect (filter) extension type, but has been used for Input/Output extensions simply by overriding additional class methods.
| |
| | |
| === Functions ===
| |
| inkex.py provides the following functions:
| |
| ;<code>errormsg( msg )</code>
| |
| : End-user visible error message, it should always be used with translation: <code>inkex.errormsg(_("This extension requires two selected paths"))</code>
| |
| ;<code>addNS( tag, ns=None )</code>
| |
| : Returns the selected tag, with the namespace applied. The namespace is selected from a list supplied with the module.
| |
| | |
| === The <code>Effect</code> class ===
| |
| | |
| The most important part of inkex.py is the <code>Effect</code> class. To implement an effect type extension in Python see [[PythonEffectTutorial]]
| |
| | |
| ==== Methods ====
| |
| ;<code>effect()</code>
| |
| : You should overwrite this method with your own, as shown in [[PythonEffectTutorial#Effect Extension Script]]
| |
| ;<code>getElementById( id )</code>
| |
| : Returns the firs found element with given id, as a <code>lxml</code> element.
| |
| ;<code>getParentNode( node )</code>
| |
| : Returns the parent of <code>node</code>. Probably the same as <code>node.getparent()</code> from <code>lxml</code>?
| |
| ;<code>createGuide( x, y, angle )</code>
| |
| : Creates guide at position (<code>x</code>,<code>y</code>), with angle <code>angle</code>.
| |
| ;<code>affect()</code>
| |
| : Actuate the script.
| |
| ;<code>xpathSingle( path )</code>
| |
| : An xpath wrapper to return a single node.
| |
| ;<code>uniqueId( old_id )</code>
| |
| : Return an id that is unique in the document given a proposed id, by appending random alphanumeric characters to it.
| |
| ;<code>getDocumentWidth()</code>
| |
| : Return width of document, as a string.
| |
| ;<code>getDocumentHeight()</code>
| |
| : Return height of document, as a string.
| |
| ;<code>getDocumentUnit()</code>
| |
| : Return a string representing the default unit for the document. Full list of possible units is defined in the module.
| |
| ;<code>unittouu( string )</code>
| |
| : Convert given value (as a string, e.g: "4px") to units used by the document. Returns float.
| |
| ;<code>uutounit( value, unit )</code>
| |
| : Convert a value (float) in document default units to given units.
| |
| | |
| ==== Properties ====
| |
| | |
| ;<code>document</code>
| |
| : DOM document, as a <code>lxml.etree</code>.
| |
| ;<code>selected</code>
| |
| : A dict mapping ids to nodes, for all nodes selected in Inkscape.
| |
| ;<code>doc_ids</code>:
| |
| : A dict mapping ids to the constant 1, for all of the ids used in the original document. Does not get automatically updated when adding elements.
| |
| ;<code>options</code>
| |
| : Options passed to the script.
| |
| | |
| == simplestyle.py ==
| |
| Provides methods for dealing with css data embeded in SVG's style atribute. When a color is represented as integers they should be in the (0, 255) range, when represented as floats, they should be in the (0.0, 1.0) range.
| |
| | |
| ;<code>parseStyle( string )</code>
| |
| : Create a dictionary from the value of an inline style attribute.
| |
| ;<code>formatStyle( dict )</code>
| |
| : Format an inline style attribute from a dictionary.
| |
| ;<code>isColor( c )</code>
| |
| : Determine if its a color we can use. If not, leave it unchanged.
| |
| ;<coder>parseColor( c )</code>
| |
| : Creates a rgb int array.
| |
| ;<code>formatColoria( a )</code>
| |
| : int array to #rrggbb string.
| |
| ;<code>formatColorfa( a )</code>
| |
| : float array to #rrggbb string.
| |
| ;<code>formatColor3i( r, g, b )</code>
| |
| : 3 ints to #rrggbb string.
| |
| ;<code>formatColor3f( r, g, b )</code>
| |
| : 3 floats to #rrggbb string.
| |
| | |
| *svgcolors: a dictionary defining legal color names and corresponding color values
| |
| | |
| == simplepath.py ==
| |
| Provides functions to round trip svg path d="" attribute data and a simple path format mimicing that datastructure. additional functions for scaling translating and rotating path data.
| |
| | |
| == cubicsuperpath.py ==
| |
| An alternative path representation. access both handles of a node at once. loses a paths open/closed identity.
| |
| | |
| == simpletransform.py ==
| |
| | |
| Provides code to easily transform objects.
| |
| | |
| *parseTransform
| |
| :Takes a string such as <tt>rotate(10)</tt> and produces a transformation matrix. If you also supply an initial matrix, the new one will be composed with the old one.
| |
| :Available commands: <tt>translate, scale, rotate, skewX, skewY, matrix</tt>. Other examples:
| |
| ::matrix = parseTransform('rotate(10)')
| |
| ::matrix = parseTransform('skewY(10)')
| |
| ::matrix = parseTransform('translate(10 10)')
| |
| ::matrix = parseTransform(' rotate(10)')
| |
| ::matrix = parseTransform('translate(700,210) rotate(-30)')
| |
| | |
| == pturtle.py ==
| |
| | |
| Provides turtle graphics primitives with svg path data output
| |
| | |
| == beziermisc.py ==
| |
| Utility functions for working with bezier curves
| |
| | |
| == cspsubdiv.py ==
| |
| Decompose a path into polylines
| |
| | |
| == ff*.py ==
| |
| | |
| an obscure set of tools for dealing with musical scales.
| |