Explorar el Código

label and placeholders are no longeur properties of cell but attributs of cell

Léo Laffeach hace 2 años
padre
commit
a64d829cf5
Se han modificado 4 ficheros con 19 adiciones y 7 borrados
  1. 2 0
      drawio2py/abstract_syntax.py
  2. 4 0
      drawio2py/generator.py
  3. 9 7
      drawio2py/parser.py
  4. 4 0
      drawio2py/util.py

+ 2 - 0
drawio2py/abstract_syntax.py

@@ -17,6 +17,8 @@ class Cell(Element):
 	""" Instances of Cell are: the root cell and its layers """
 	id: str
 	value: str
+	label : str
+	placeholders : bool
 	parent: Optional['Cell']    # Every cell has a parent, except for the root.
 	children: List['Cell']
 	properties: dict[str,str] # User-defined properties

+ 4 - 0
drawio2py/generator.py

@@ -36,6 +36,10 @@ def write_cell(cell, root):
 	attrs = {}
 	if not cell.properties:
 		attrs["id"] = cell.id
+	if cell.label:
+		attrs["label"] = cell.label
+	if cell.placeholders:
+		attrs["placeholders"] = "1"
 	if cell.value:
 		attrs["value"] = cell.value
 	if cell.style:

+ 9 - 7
drawio2py/parser.py

@@ -87,9 +87,11 @@ class Parser:
 	@staticmethod
 	def parse_object(oroot):
 		croot = oroot.find(".//mxCell")
-		id = oroot.attrib['id']
-		properties = {k:v for k,v in oroot.attrib.items() if k != "id"}
-		return Parser.parse_cell(croot, id, properties)
+		id = oroot.attrib.get('id')
+		label = oroot.attrib.get('label')
+		placeholders = oroot.attrib.get('placeholders') == "1"
+		properties = {k:v for k,v in oroot.attrib.items() if not(k in ["id", "label", "placeholders"])}
+		return Parser.parse_cell(croot, id, label, placeholders, properties)
 
 	@staticmethod
 	def parse_style(style_string):
@@ -111,7 +113,7 @@ class Parser:
 		return Style(data=data)
 
 	@staticmethod
-	def parse_cell(croot, id=None, properties={}):
+	def parse_cell(croot, id=None, label=None, placeholders=None, properties={}):
 		if id == None:
 			cid = croot.attrib.get("id")
 		else:
@@ -128,13 +130,13 @@ class Parser:
 			source = croot.attrib.get("source", None)
 			target = croot.attrib.get("target", None)
 
-			return Edge(cid, value, parent, [], properties, style, atts, geom, source, target)
+			return Edge(cid, value, label, placeholders, parent, [], properties, style, atts, geom, source, target)
 
 		geom = Parser.parse_cell_geometry(croot.find(".//mxGeometry"))
 		if geom != None:
-			return Vertex(cid, value, parent, [], properties, style, atts, geom, [], [])
+			return Vertex(cid, value, label, placeholders, parent, [], properties, style, atts, geom, [], [])
 		else:
-			return Cell(cid, value, parent, [], properties, style, atts)
+			return Cell(cid, value, label, placeholders, parent, [], properties, style, atts)
 
 	@staticmethod
 	def parse_components(nroot, cell_dict):

+ 4 - 0
drawio2py/util.py

@@ -34,6 +34,8 @@ def generate_empty_root_and_layer() -> Cell:
     root = Cell(
         id="0",
         value="",
+        label=None,
+        placeholders=False,
         parent=None,
         children=[],
         properties={},
@@ -43,6 +45,8 @@ def generate_empty_root_and_layer() -> Cell:
     layer = Cell(
         id="1",
         value="",
+        label=None,
+        placeholders=False,
         parent=root,
         children=[],
         properties={},