File: element.py

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (51 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download | duplicates (2)
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