drawpyo 0.2__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {drawpyo-0.2 → drawpyo-0.2.2}/PKG-INFO +10 -10
- {drawpyo-0.2 → drawpyo-0.2.2}/README.md +8 -8
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/__init__.py +1 -1
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram/extended_objects.py +4 -6
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram/objects.py +1 -1
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram/text_format.py +7 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram_types/tree.py +32 -34
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/xml_base.py +19 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/pyproject.toml +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram/__init__.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram/base_diagram.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram/edges.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram_types/__init__.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/diagram_types/class_diagram.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/file.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/formatting_database/edge_styles.toml +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/formatting_database/line_styles.toml +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/page.py +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/shape_libraries/flowchart.toml +0 -0
- {drawpyo-0.2 → drawpyo-0.2.2}/src/drawpyo/shape_libraries/general.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: drawpyo
|
|
3
|
-
Version: 0.2
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: A Python library for programmatically generating Draw.io charts.
|
|
5
5
|
Keywords: draw.io,diagrams.net,diagrams
|
|
6
6
|
Author-email: Xander Cesari <xander@merriman.industries>
|
|
@@ -111,22 +111,22 @@ Create some NodeObjects:
|
|
|
111
111
|
grinders = NodeObject(tree=tree, value="Appliances for Grinding Coffee", base_style="rounded rectangle")
|
|
112
112
|
|
|
113
113
|
# Main categories
|
|
114
|
-
blade_grinders = NodeObject(tree=tree, value="Blade Grinders",
|
|
115
|
-
burr_grinders = NodeObject(tree=tree, value="Burr Grinders",
|
|
116
|
-
blunt_objects = NodeObject(tree=tree, value="Blunt Objects",
|
|
114
|
+
blade_grinders = NodeObject(tree=tree, value="Blade Grinders", tree_parent=grinders)
|
|
115
|
+
burr_grinders = NodeObject(tree=tree, value="Burr Grinders", tree_parent=grinders)
|
|
116
|
+
blunt_objects = NodeObject(tree=tree, value="Blunt Objects", tree_parent=grinders)
|
|
117
117
|
```
|
|
118
118
|
|
|
119
119
|
Note that the base_style was manually declared for the first object. But NodeObjects will default to "rounded rectangle" so it's not necessary for every one. Any NodeObject can be a parent, so you can keep adding objects down the tree:
|
|
120
120
|
|
|
121
121
|
```python
|
|
122
122
|
# Other
|
|
123
|
-
elec_blade = NodeObject(tree=tree, value="Electric Blade Grinder",
|
|
124
|
-
mnp = NodeObject(tree=tree, value="Mortar and Pestle",
|
|
123
|
+
elec_blade = NodeObject(tree=tree, value="Electric Blade Grinder", tree_parent=blade_grinders)
|
|
124
|
+
mnp = NodeObject(tree=tree, value="Mortar and Pestle", tree_parent=blunt_objects)
|
|
125
125
|
|
|
126
126
|
# Conical Burrs
|
|
127
|
-
conical = NodeObject(tree=tree, value="Conical Burrs",
|
|
128
|
-
elec_conical = NodeObject(tree=tree, value="Electric",
|
|
129
|
-
manual_conical = NodeObject(tree=tree, value="Manual",
|
|
127
|
+
conical = NodeObject(tree=tree, value="Conical Burrs", tree_parent=burr_grinders)
|
|
128
|
+
elec_conical = NodeObject(tree=tree, value="Electric", tree_parent=conical)
|
|
129
|
+
manual_conical = NodeObject(tree=tree, value="Manual", tree_parent=conical)
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
> **Important Note:** TreeDiagrams do not currently support NodeObjects with multiple parents! It may not ever as this seriously complicates the auto layout process. However, you can add links between any two objects in the tree and render them in the diagram. They just may look ugly until you manually rearrange the diagram.
|
|
@@ -96,22 +96,22 @@ Create some NodeObjects:
|
|
|
96
96
|
grinders = NodeObject(tree=tree, value="Appliances for Grinding Coffee", base_style="rounded rectangle")
|
|
97
97
|
|
|
98
98
|
# Main categories
|
|
99
|
-
blade_grinders = NodeObject(tree=tree, value="Blade Grinders",
|
|
100
|
-
burr_grinders = NodeObject(tree=tree, value="Burr Grinders",
|
|
101
|
-
blunt_objects = NodeObject(tree=tree, value="Blunt Objects",
|
|
99
|
+
blade_grinders = NodeObject(tree=tree, value="Blade Grinders", tree_parent=grinders)
|
|
100
|
+
burr_grinders = NodeObject(tree=tree, value="Burr Grinders", tree_parent=grinders)
|
|
101
|
+
blunt_objects = NodeObject(tree=tree, value="Blunt Objects", tree_parent=grinders)
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
Note that the base_style was manually declared for the first object. But NodeObjects will default to "rounded rectangle" so it's not necessary for every one. Any NodeObject can be a parent, so you can keep adding objects down the tree:
|
|
105
105
|
|
|
106
106
|
```python
|
|
107
107
|
# Other
|
|
108
|
-
elec_blade = NodeObject(tree=tree, value="Electric Blade Grinder",
|
|
109
|
-
mnp = NodeObject(tree=tree, value="Mortar and Pestle",
|
|
108
|
+
elec_blade = NodeObject(tree=tree, value="Electric Blade Grinder", tree_parent=blade_grinders)
|
|
109
|
+
mnp = NodeObject(tree=tree, value="Mortar and Pestle", tree_parent=blunt_objects)
|
|
110
110
|
|
|
111
111
|
# Conical Burrs
|
|
112
|
-
conical = NodeObject(tree=tree, value="Conical Burrs",
|
|
113
|
-
elec_conical = NodeObject(tree=tree, value="Electric",
|
|
114
|
-
manual_conical = NodeObject(tree=tree, value="Manual",
|
|
112
|
+
conical = NodeObject(tree=tree, value="Conical Burrs", tree_parent=burr_grinders)
|
|
113
|
+
elec_conical = NodeObject(tree=tree, value="Electric", tree_parent=conical)
|
|
114
|
+
manual_conical = NodeObject(tree=tree, value="Manual", tree_parent=conical)
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
> **Important Note:** TreeDiagrams do not currently support NodeObjects with multiple parents! It may not ever as this seriously complicates the auto layout process. However, you can add links between any two objects in the tree and render them in the diagram. They just may look ugly until you manually rearrange the diagram.
|
|
@@ -25,7 +25,7 @@ class List(Object):
|
|
|
25
25
|
list of strings: The list items
|
|
26
26
|
"""
|
|
27
27
|
return [child.value for child in self.children]
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
@list_items.setter
|
|
30
30
|
def list_items(self, value):
|
|
31
31
|
if not isinstance(value, list):
|
|
@@ -33,7 +33,7 @@ class List(Object):
|
|
|
33
33
|
self.children = []
|
|
34
34
|
for item in value:
|
|
35
35
|
self.add_item(item)
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
def add_item(self, item_text):
|
|
38
38
|
"""This function creates a new Draw.io text item and adds it to the end of the list.
|
|
39
39
|
|
|
@@ -65,8 +65,7 @@ class List(Object):
|
|
|
65
65
|
self.autosize()
|
|
66
66
|
|
|
67
67
|
def autosize(self):
|
|
68
|
-
"""This function resizes the parent List object to match the length of the list of items. It also restacks the list items to fill any gaps from deleted items.
|
|
69
|
-
"""
|
|
68
|
+
"""This function resizes the parent List object to match the length of the list of items. It also restacks the list items to fill any gaps from deleted items."""
|
|
70
69
|
y_pos = self.startSize
|
|
71
70
|
for child in self.children:
|
|
72
71
|
child.geometry.y = y_pos
|
|
@@ -82,11 +81,10 @@ class List(Object):
|
|
|
82
81
|
_type_: _description_
|
|
83
82
|
"""
|
|
84
83
|
return self.geometry.width
|
|
85
|
-
|
|
84
|
+
|
|
86
85
|
@width.setter
|
|
87
86
|
def width(self, value):
|
|
88
87
|
for child in self.children:
|
|
89
88
|
child.width = value
|
|
90
89
|
self.geometry.width = value
|
|
91
90
|
self.update_parent()
|
|
92
|
-
|
|
@@ -59,6 +59,7 @@ class TextFormat(DiagramBase):
|
|
|
59
59
|
self._style_attributes = [
|
|
60
60
|
"html",
|
|
61
61
|
"fontFamily",
|
|
62
|
+
"fontStyle",
|
|
62
63
|
"fontSize",
|
|
63
64
|
"fontColor",
|
|
64
65
|
"labelBorderColor",
|
|
@@ -150,3 +151,9 @@ class TextFormat(DiagramBase):
|
|
|
150
151
|
return 6
|
|
151
152
|
elif bld and ita and unl:
|
|
152
153
|
return 7
|
|
154
|
+
|
|
155
|
+
@property
|
|
156
|
+
def fontStyle(self):
|
|
157
|
+
if self.font_style != 0:
|
|
158
|
+
return self.font_style
|
|
159
|
+
return None
|
|
@@ -14,13 +14,13 @@ class NodeObject(Object):
|
|
|
14
14
|
tree (TreeDiagram, optional): The owning tree diagram. Defaults to None.
|
|
15
15
|
|
|
16
16
|
Keyword Args:
|
|
17
|
-
|
|
17
|
+
tree_children (list, optional): A list of other NodeObjects
|
|
18
18
|
parent (list, optional): The parent NodeObject
|
|
19
19
|
"""
|
|
20
20
|
super().__init__(**kwargs)
|
|
21
21
|
self.tree = tree
|
|
22
|
-
self.
|
|
23
|
-
self.
|
|
22
|
+
self.tree_children = kwargs.get("tree_children", [])
|
|
23
|
+
self.tree_parent = kwargs.get("tree_parent", None)
|
|
24
24
|
self.peers = []
|
|
25
25
|
# self.level = kwargs.get("level", None)
|
|
26
26
|
# self.peers = kwargs.get("peers", [])
|
|
@@ -41,19 +41,19 @@ class NodeObject(Object):
|
|
|
41
41
|
self._tree = value
|
|
42
42
|
|
|
43
43
|
@property
|
|
44
|
-
def
|
|
45
|
-
"""The parent NodeObject
|
|
44
|
+
def tree_parent(self):
|
|
45
|
+
"""The parent NodeObject in the tree
|
|
46
46
|
|
|
47
47
|
Returns:
|
|
48
48
|
NodeObject
|
|
49
49
|
"""
|
|
50
|
-
return self.
|
|
50
|
+
return self._tree_parent
|
|
51
51
|
|
|
52
|
-
@
|
|
53
|
-
def
|
|
52
|
+
@tree_parent.setter
|
|
53
|
+
def tree_parent(self, value):
|
|
54
54
|
if value is not None:
|
|
55
|
-
value.
|
|
56
|
-
self.
|
|
55
|
+
value.tree_children.append(self)
|
|
56
|
+
self._tree_parent = value
|
|
57
57
|
|
|
58
58
|
def add_child(self, obj):
|
|
59
59
|
"""Add a new child to the object
|
|
@@ -61,8 +61,8 @@ class NodeObject(Object):
|
|
|
61
61
|
Args:
|
|
62
62
|
obj (NodeObject)
|
|
63
63
|
"""
|
|
64
|
-
self.
|
|
65
|
-
obj.
|
|
64
|
+
self.tree_children.append(obj)
|
|
65
|
+
obj._tree_parent = self
|
|
66
66
|
|
|
67
67
|
def add_peer(self, obj):
|
|
68
68
|
if obj not in self.peers:
|
|
@@ -424,8 +424,8 @@ class TreeDiagram:
|
|
|
424
424
|
def add_object(self, obj, **kwargs):
|
|
425
425
|
if obj not in self.objects:
|
|
426
426
|
obj.page = self.page
|
|
427
|
-
if "
|
|
428
|
-
obj.
|
|
427
|
+
if "tree_parent" in kwargs:
|
|
428
|
+
obj.tree_parent = kwargs.get("tree_parent")
|
|
429
429
|
self.objects.append(obj)
|
|
430
430
|
|
|
431
431
|
###########################################################
|
|
@@ -434,21 +434,21 @@ class TreeDiagram:
|
|
|
434
434
|
|
|
435
435
|
@property
|
|
436
436
|
def roots(self):
|
|
437
|
-
return [x for x in self.objects if x.
|
|
437
|
+
return [x for x in self.objects if x.tree_parent is None]
|
|
438
438
|
|
|
439
439
|
def auto_layout(self):
|
|
440
|
-
def layout_child(
|
|
440
|
+
def layout_child(tree_parent):
|
|
441
441
|
grp = TreeGroup(tree=self)
|
|
442
|
-
grp.parent_object =
|
|
443
|
-
if len(
|
|
444
|
-
# has children, go through each
|
|
445
|
-
for
|
|
446
|
-
self.connect(
|
|
447
|
-
if len(
|
|
448
|
-
# If this
|
|
449
|
-
grp.add_object(layout_child(
|
|
442
|
+
grp.parent_object = tree_parent
|
|
443
|
+
if len(tree_parent.tree_children) > 0:
|
|
444
|
+
# has children, go through each child and check its children
|
|
445
|
+
for child in tree_parent.tree_children:
|
|
446
|
+
self.connect(tree_parent, child)
|
|
447
|
+
if len(child.tree_children) > 0:
|
|
448
|
+
# If this child has its own children then recursive call
|
|
449
|
+
grp.add_object(layout_child(child))
|
|
450
450
|
else:
|
|
451
|
-
grp.add_object(
|
|
451
|
+
grp.add_object(child)
|
|
452
452
|
|
|
453
453
|
# layout the row
|
|
454
454
|
grp = layout_group(grp)
|
|
@@ -459,12 +459,10 @@ class TreeDiagram:
|
|
|
459
459
|
def layout_group(grp, pos=self.origin):
|
|
460
460
|
pos = self.origin
|
|
461
461
|
|
|
462
|
-
for
|
|
463
|
-
if
|
|
464
|
-
|
|
465
|
-
pos = self.move_in_level(
|
|
466
|
-
pos, leaf.size_in_level + self.item_spacing
|
|
467
|
-
)
|
|
462
|
+
for obj in grp.objects:
|
|
463
|
+
if obj is not grp.parent_object:
|
|
464
|
+
obj.position = pos
|
|
465
|
+
pos = self.move_in_level(pos, obj.size_in_level + self.item_spacing)
|
|
468
466
|
return grp
|
|
469
467
|
|
|
470
468
|
# def add_parent(grp, parent):
|
|
@@ -472,7 +470,7 @@ class TreeDiagram:
|
|
|
472
470
|
# level_space = (
|
|
473
471
|
# grp.size_of_level / 2
|
|
474
472
|
# + self.level_spacing
|
|
475
|
-
# +
|
|
473
|
+
# + tree_parent.size_of_level / 2
|
|
476
474
|
# )
|
|
477
475
|
# pos = self.move_between_levels(pos, -level_space)
|
|
478
476
|
# parent.center_position = pos
|
|
@@ -564,8 +562,8 @@ class TreeDiagram:
|
|
|
564
562
|
# Draw connections
|
|
565
563
|
for lvl in self.objects.values():
|
|
566
564
|
for obj in lvl:
|
|
567
|
-
if obj.
|
|
568
|
-
self.connect(source=obj.
|
|
565
|
+
if obj.tree_parent is not None:
|
|
566
|
+
self.connect(source=obj.tree_parent, target=obj)
|
|
569
567
|
|
|
570
568
|
def write(self, **kwargs):
|
|
571
569
|
self.file.write(**kwargs)
|
|
@@ -26,6 +26,8 @@ class XMLBase:
|
|
|
26
26
|
# in every other use case.
|
|
27
27
|
self.xml_parent = kwargs.get("xml_parent", None)
|
|
28
28
|
|
|
29
|
+
self.tag = kwargs.get("tag", None)
|
|
30
|
+
|
|
29
31
|
@property
|
|
30
32
|
def id(self):
|
|
31
33
|
"""
|
|
@@ -55,12 +57,27 @@ class XMLBase:
|
|
|
55
57
|
"""
|
|
56
58
|
The open tag contains the name of the object but also the attribute tags. This property function concatenates all the attributes in the class along with the opening and closing angle brackets and returns them as a string.
|
|
57
59
|
|
|
60
|
+
When the "tag" attribute tag is provided, a tags attribute is applied to the object. This allows for selecting, hiding, or displaying multiple elements in the diagram. When using tags, the open_tag value and id are shifted to the <UserObject> tag.
|
|
61
|
+
|
|
62
|
+
|
|
58
63
|
Example:
|
|
59
64
|
<class_name attribute_name=attribute_value>
|
|
60
65
|
|
|
61
66
|
Returns:
|
|
62
67
|
str: The opening tag of the object with all the attributes.
|
|
63
68
|
"""
|
|
69
|
+
if self.tag:
|
|
70
|
+
open_user_object_tag = (
|
|
71
|
+
f'<UserObject label="{self.value}" tags="{self.tag}" id="{self.id}">'
|
|
72
|
+
)
|
|
73
|
+
open_tag = "<" + self.xml_class
|
|
74
|
+
for att, value in self.attributes.items():
|
|
75
|
+
if att == "id" or att == "value":
|
|
76
|
+
continue
|
|
77
|
+
if value is not None:
|
|
78
|
+
xml_parameter = self.xml_ify(str(value))
|
|
79
|
+
open_tag = open_tag + " " + att + '="' + xml_parameter + '"'
|
|
80
|
+
return open_user_object_tag + "\n" + open_tag + ">"
|
|
64
81
|
open_tag = "<" + self.xml_class
|
|
65
82
|
for att, value in self.attributes.items():
|
|
66
83
|
if value is not None:
|
|
@@ -79,6 +96,8 @@ class XMLBase:
|
|
|
79
96
|
Returns:
|
|
80
97
|
str: The closing tag of the object with all the attributes.
|
|
81
98
|
"""
|
|
99
|
+
if self.tag:
|
|
100
|
+
return "</{0}>\n</UserObject>".format(self.xml_class)
|
|
82
101
|
return "</{0}>".format(self.xml_class)
|
|
83
102
|
|
|
84
103
|
@property
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|