inkex.elements._selected module#

When elements are selected, these structures provide an advanced API.

New in version 1.1.

class inkex.elements._selected.ElementList(svg, _iter=None)[source]#

Bases: collections.OrderedDict

A list of elements, selected by id, iterator or xpath

This may look like a dictionary, but it is really a list of elements. The default iterator is the element objects themselves (not keys) and it is possible to key elements by their numerical index.

It is also possible to look up items by their id and the element object itself.

_to_key(key: None, default: Any) Any[source]#
_to_key(key: Union[int, inkex.interfaces.IElement.IBaseElement, str], default: Any) str

Takes a key (id, element, etc) and returns an xml_path key

clear()[source]#

Also clear ids

set(*ids)[source]#

Sets the currently selected elements to these ids, any existing selection is cleared.

Arguments a list of element ids, element objects or a single xpath expression starting with //.

All element objects must have an id to be correctly set.

>>> selection.set("rect123", "path456", "text789")
>>> selection.set(elem1, elem2, elem3)
>>> selection.set("//rect")
pop(key=None)[source]#

Remove the key item or remove the last item selected

add(*ids)[source]#

Like set() but does not clear first

rendering_order()[source]#

Get the selected elements by z-order (stacking order), ordered from bottom to top

New in version 1.2: paint_order() has been renamed to rendering_order()

filter(*types)[source]#

Filter selected elements of the given type, returns a new SelectedElements object

filter_nonzero(*types, error_msg: Optional[str] = None)[source]#

Filter selected elements of the given type, returns a new SelectedElements object. If the selection is empty, abort the extension.

New in version 1.2.

Parameters
  • error_msg (str, optional) – e

  • *types (Type) – type(s) to filter the selection by

  • error_msg – error message that is displayed if the selection is empty, defaults to _("Please select at least one element of type(s) {}"). Defaults to None.

Raises

AbortExtension – if the selection is empty

Returns

filtered selection

Return type

ElementList

get(*types)[source]#

Like filter, but will enter each element searching for any child of the given types

id_dict()[source]#

For compatibility, return regular dictionary of id -> element pairs

bounding_box()[source]#

Gets a inkex.transforms.BoundingBox object for the selected items.

Text objects have a bounding box without width or height that only reflects the coordinate of their anchor. If a text object is a part of the selection’s boundary, the bounding box may be inaccurate.

When no object is selected or when the object’s location cannot be determined (e.g. empty group or layer), all coordinates will be None.

paint_order(**kwargs)#

Use rendering_order()

Deprecated since version 1.2.

first()[source]#

Returns the first item in the selected list