128 for child_etree in imap(lambda c:c.etree(), self.children): |
127 for child_etree in imap(lambda c:c.etree(), self.children): |
129 res.append(child_etree) |
128 res.append(child_etree) |
130 |
129 |
131 return res |
130 return res |
132 |
131 |
|
132 @classmethod |
|
133 def from_etree(cls, enode): |
|
134 """ |
|
135 alternative constructor, restoring HMI Tree from XML backup |
|
136 note: all C-related information is gone, |
|
137 this restore is only for tree display and widget picking |
|
138 """ |
|
139 nodetype = enode.tag |
|
140 attributes = enode.attrib |
|
141 name = attributes["name"] |
|
142 path = attributes["path"].split('.') if "path" in attributes else None |
|
143 hmiclass = attributes.get("hmiclass", None) |
|
144 # hash is computed on demand |
|
145 node = cls(path, name, nodetype, hmiclass=hmiclass) |
|
146 for child in enode.iterchildren(): |
|
147 node.children.append(cls.from_etree(child)) |
|
148 return node |
|
149 |
133 def traverse(self): |
150 def traverse(self): |
134 yield self |
151 yield self |
135 if hasattr(self, "children"): |
152 if hasattr(self, "children"): |
136 for c in self.children: |
153 for c in self.children: |
137 for yoodl in c.traverse(): |
154 for yoodl in c.traverse(): |
341 runtimefile_path = os.path.join(buildpath, "runtime_00_svghmi.py") |
358 runtimefile_path = os.path.join(buildpath, "runtime_00_svghmi.py") |
342 runtimefile = open(runtimefile_path, 'w') |
359 runtimefile = open(runtimefile_path, 'w') |
343 runtimefile.write(svghmiservercode) |
360 runtimefile.write(svghmiservercode) |
344 runtimefile.close() |
361 runtimefile.close() |
345 |
362 |
|
363 # Backup HMI Tree in XML form so that it can be loaded without building |
|
364 hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") |
|
365 hmitree_backup_file = open(hmitree_backup_path, 'w') |
|
366 hmitree_backup_file.write(etree.tostring(hmi_tree_root.etree())) |
|
367 hmitree_backup_file.close() |
|
368 |
346 return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "", |
369 return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "", |
347 ("runtime_00_svghmi.py", open(runtimefile_path, "rb"))) |
370 ("runtime_00_svghmi.py", open(runtimefile_path, "rb"))) |
348 # ^ |
371 # ^ |
349 # note the double zero after "runtime_", |
372 # note the double zero after "runtime_", |
350 # to ensure placement before other CTN generated code in execution order |
373 # to ensure placement before other CTN generated code in execution order |
426 CONFNODEEDITOR_TABS = [ |
449 CONFNODEEDITOR_TABS = [ |
427 (_("HMI Tree"), "CreateHMITreeView")] |
450 (_("HMI Tree"), "CreateHMITreeView")] |
428 |
451 |
429 def CreateHMITreeView(self, parent): |
452 def CreateHMITreeView(self, parent): |
430 #self.HMITreeView = HMITreeView(self) |
453 #self.HMITreeView = HMITreeView(self) |
|
454 global hmi_tree_root |
|
455 |
|
456 if hmi_tree_root is None: |
|
457 buildpath = self.Controler.GetCTRoot()._getBuildPath() |
|
458 hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") |
|
459 if os.path.exists(hmitree_backup_path): |
|
460 hmitree_backup_file = open(hmitree_backup_path, 'r') |
|
461 hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot()) |
|
462 |
431 return HMITreeSelector(parent) |
463 return HMITreeSelector(parent) |
432 |
464 |
433 class SVGHMI(object): |
465 class SVGHMI(object): |
434 XSD = """<?xml version="1.0" encoding="utf-8" ?> |
466 XSD = """<?xml version="1.0" encoding="utf-8" ?> |
435 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
467 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |