BaseElement¶
-
class
svgwrite.base.BaseElement(**extra)¶ The BaseElement is the root for all SVG elements. The SVG attributes are stored in attribs, and the SVG subelements are stored in elements.
-
BaseElement.__init__(**extra)¶ Parameters: extra – extra SVG attributes (keyword arguments)
- add trailing ‘_’ to reserved keywords:
'class_','from_' - replace inner ‘-’ by ‘_’:
'stroke_width'
SVG attribute names will be checked, if debug is True.
workaround for removed attribs parameter in Version 0.2.2:
# replace element = BaseElement(attribs=adict) #by element = BaseElement() element.update(adict)
- add trailing ‘_’ to reserved keywords:
Attributes¶
-
BaseElement.attribs¶ dict of SVG attributes
-
BaseElement.elements¶ list of SVG subelements
Methods¶
-
BaseElement.add(element)¶ Add an SVG element as subelement.
Parameters: element – append this SVG element Returns: the added element
-
BaseElement.tostring()¶ Get the XML representation as unicode string.
Returns: unicode XML string of this object and all its subelements
-
BaseElement.get_xml()¶ Get the XML representation as ElementTree object.
Returns: XML ElementTree of this object and all its subelements
-
BaseElement.get_id()¶ Get the object id string, if the object does not have an id, a new id will be created.
Returns: string
-
BaseElement.get_iri()¶ Get the IRI reference string of the object. (i.e.,
'#id').Returns: string
-
BaseElement.get_funciri()¶ Get the FuncIRI reference string of the object. (i.e.
'url(#id)').Returns: string
-
BaseElement.update(attribs)¶ Update SVG Attributes from dict attribs.
Rules for keys:
- trailing ‘_’ will be removed (
'class_'->'class') - inner ‘_’ will be replaced by ‘-’ (
'stroke_width'->'stroke-width')
- trailing ‘_’ will be removed (
-
BaseElement.__getitem__(key)¶ Get SVG attribute by key.
Parameters: key (string) – SVG attribute name Returns: SVG attribute value
-
BaseElement.__setitem__(key, value)¶ Set SVG attribute by key to value.
Parameters: - key (string) – SVG attribute name
- value (object) – SVG attribute value
-
BaseElement.set_desc(title=None, desc=None)¶ Insert a title and/or a desc element as first subelement.
-
BaseElement.set_metadata(xmldata)¶ Parameters: xmldata – an xml.etree.ElementTree - Element() object.
set/get SVG attributes:
element['attribute'] = value
value = element['attribute']
attribs = {
'class' = 'css-class',
'stroke' = 'black',
}
element.update(attribs)