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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
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", parent=grinders)
115
- burr_grinders = NodeObject(tree=tree, value="Burr Grinders", parent=grinders)
116
- blunt_objects = NodeObject(tree=tree, value="Blunt Objects", parent=grinders)
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", parent=blade_grinders)
124
- mnp = NodeObject(tree=tree, value="Mortar and Pestle", parent=blunt_objects)
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", parent=burr_grinders)
128
- elec_conical = NodeObject(tree=tree, value="Electric", parent=conical)
129
- manual_conical = NodeObject(tree=tree, value="Manual", parent=conical)
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", parent=grinders)
100
- burr_grinders = NodeObject(tree=tree, value="Burr Grinders", parent=grinders)
101
- blunt_objects = NodeObject(tree=tree, value="Blunt Objects", parent=grinders)
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", parent=blade_grinders)
109
- mnp = NodeObject(tree=tree, value="Mortar and Pestle", parent=blunt_objects)
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", parent=burr_grinders)
113
- elec_conical = NodeObject(tree=tree, value="Electric", parent=conical)
114
- manual_conical = NodeObject(tree=tree, value="Manual", parent=conical)
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.
@@ -5,4 +5,4 @@ from .page import Page
5
5
  from . import diagram
6
6
  from . import diagram_types
7
7
 
8
- __version__ = "0.2"
8
+ __version__ = "0.2.2"
@@ -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
-
@@ -184,7 +184,7 @@ class Object(DiagramBase):
184
184
 
185
185
  def __str__(self):
186
186
  return self.__repr__()
187
-
187
+
188
188
  def __delete__(self):
189
189
  self.page.remove_object(self)
190
190
 
@@ -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
- children (list, optional): A list of other NodeObjects
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.children = kwargs.get("children", [])
23
- self.parent = kwargs.get("parent", None)
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 parent(self):
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._parent
50
+ return self._tree_parent
51
51
 
52
- @parent.setter
53
- def parent(self, value):
52
+ @tree_parent.setter
53
+ def tree_parent(self, value):
54
54
  if value is not None:
55
- value.children.append(self)
56
- self._parent = value
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.children.append(obj)
65
- obj._parent = self
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 "parent" in kwargs:
428
- obj.parent = kwargs.get("parent")
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.parent is None]
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(parent):
440
+ def layout_child(tree_parent):
441
441
  grp = TreeGroup(tree=self)
442
- grp.parent_object = parent
443
- if len(parent.children) > 0:
444
- # has children, go through each leaf and check its children
445
- for leaf in parent.children:
446
- self.connect(parent, leaf)
447
- if len(leaf.children) > 0:
448
- # If this leaf has its own children then recursive call
449
- grp.add_object(layout_child(leaf))
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(leaf)
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 leaf in grp.objects:
463
- if leaf is not grp.parent_object:
464
- leaf.position = pos
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
- # + parent.size_of_level / 2
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.parent is not None:
568
- self.connect(source=obj.parent, target=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