inkex.utils module#
Basic common utility functions for calculated things
- inkex.utils.get_user_directory()[source]#
Return the user directory where extensions are stored.
New in version 1.1.
- inkex.utils.get_inkscape_directory()[source]#
Return the system directory where inkscape’s core is.
New in version 1.1.
- class inkex.utils.KeyDict[source]#
Bases:
dict
A normal dictionary, except asking for anything not in the dictionary always returns the key itself. This is used for translation dictionaries.
- inkex.utils.parse_percent(val: str)[source]#
Parse strings that are either values (i.e., ‘3.14159’) or percentages (i.e. ‘75%’) to a float.
New in version 1.2.
- inkex.utils.Boolean(value)[source]#
ArgParser function to turn a boolean string into a python boolean
- inkex.utils.errormsg(msg)[source]#
Intended for end-user-visible error messages.
(Currently just writes to stderr with an appended newline, but could do something better in future: e.g. could add markup to distinguish error messages from status messages or debugging output.)
Note that this should always be combined with translation:
import inkex ... inkex.errormsg(_("This extension requires two selected paths."))
- exception inkex.utils.AbortExtension[source]#
Bases:
Exception
Raised to print a message to the user without backtrace
- exception inkex.utils.DependencyError[source]#
Bases:
NotImplementedError
Raised when we need an external python module that isn’t available
- exception inkex.utils.FragmentError[source]#
Bases:
Exception
Raised when trying to do rooty things on an xml fragment
- inkex.utils.to(kind)[source]#
Decorator which will turn a generator into a list, tuple or other object type.
- inkex.utils.strargs(string, kind=float)[source]#
Returns a list of floats from a string
Changed in version 1.1: also splits at -(minus) signs by adding a space in front of the - sign
Changed in version 1.2: Full support for the SVG Path data BNF
- class inkex.utils.classproperty(func)[source]#
Bases:
object
Combine classmethod and property decorators
- inkex.utils.pairwise(iterable, start=True)[source]#
Iterate over a list with overlapping pairs (see itertools recipes)
- inkex.utils.circular_pairwise(l)[source]#
Iterate over a list with overlapping pairs in a periodic way, i.e. [1, 2, 3] -> [(1, 2), (2, 3), (3, 1)]
..versionadded:: 1.3.1
- inkex.utils.math_eval(function, variable='x')[source]#
Interpret a function string. All functions from math and random may be used.
New in version 1.1.
- Returns
a lambda expression if sucessful; otherwise None.
- inkex.utils.rational_limit(f: numpy.poly1d, g: numpy.poly1d, t0)[source]#
Computes the limit of the rational function (f/g)(t) as t approaches t0.
New in version 1.4.
- class inkex.utils.NotifyList(*args, callback=None)[source]#
Bases:
list
A list that calls a callback after it is modified (to notify a parent about the modification). Modified from https://stackoverflow.com/a/13259435/3298143
New in version 1.4.
- extend(*args, **kwargs)#
Extend list by appending elements from the iterable.
- append(*args, **kwargs)#
Append object to the end of the list.
- remove(*args, **kwargs)#
Remove first occurrence of value.
Raises ValueError if the value is not present.
- pop(*args, **kwargs)#
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- class inkex.utils.NotifyOrderedDict(*args, callback=None, **kwargs)[source]#
Bases:
collections.OrderedDict
An OrderedDict that notifies a callback after a value is changed
New in version 1.4.
- clear() None. Remove all items from od. #
- popitem(*args, **kwargs)#
Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
- update([E, ]**F) None. Update D from dict/iterable E and F. #
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- setdefault(*args, **kwargs)#
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.