1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Nicolas P. Rougier. All rights reserved.
# Distributed under the terms of the new BSD License.
# -----------------------------------------------------------------------------
import copy
from . style import Style
namespace = '{http://www.w3.org/2000/svg}'
class Element(object):
"""Generic SVG element"""
def __init__(self, content=None, parent=None):
self._parent = parent
self._id = hex(id(self))
self._style = Style()
self._computed_style = Style()
if isinstance(content, str):
return
self._id = content.get('id', self._id)
self._style.update(content.get("style", None))
self._computed_style = Style()
if parent and parent.style:
self._computed_style = copy.copy(parent.style)
self._computed_style.update(content.get("style", None))
@property
def root(self):
if self._parent:
return self._parent.root
return self
@property
def parent(self):
if self._parent:
return self._parent
return None
@property
def style(self):
return self._computed_style
@property
def viewport(self):
if self._parent:
return self._parent.viewport
return None
|