-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg.py
38 lines (26 loc) · 1.12 KB
/
svg.py
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
from nicegui.element import Element
class SVG(Element, component="svg.js"):
def __init__(self, width: int = 200, height: int = 200, viewBox : dict = {"x":0, "y":0, "width":200, "height":200}) -> None:
super().__init__()
self.width = width
self.height = height
self.viewBox = viewBox
self.children : list = []
self._props['width'] = width
self._props['height'] = height
self._props['viewBox'] = " ".join(([str(val) for val in viewBox.values()]))
def add_child(self, child):
self.children.append(child)
def add_children(self, children):
self.children.extend(children)
def remove_child(self, child):
# self.children.remove(child)
self.slots['default'].children.remove(child)
self.update()
def __str__(self) -> str:
code = "svg = SVG(width={}, height={}, viewBox={})\n".format(self.width, self.height, self.viewBox)
code += "with svg:\n"
for child in self.children:
# code += str(child)
code += child.__str__(indent=1)
return code