svghmi/hmi_tree.py
branchsvghmi
changeset 3223 061796d9855e
parent 3197 0f41c1e2c121
child 3224 507dd7bc8cb5
--- a/svghmi/hmi_tree.py	Mon Apr 05 18:22:30 2021 +0200
+++ b/svghmi/hmi_tree.py	Tue Apr 06 11:47:07 2021 +0200
@@ -9,6 +9,7 @@
 from __future__ import absolute_import
 from itertools import izip, imap
 from pprint import pformat
+import weakref
 import hashlib
 
 from lxml import etree
@@ -29,6 +30,7 @@
         self.name = name
         self.nodetype = nodetype
         self.hmiclass = hmiclass
+        self.parent = None
 
         if iectype is not None:
             self.iectype = iectype
@@ -84,6 +86,7 @@
                 if prev.path[:-1] == node.path[:-1]:
                     return "Late_HMI_NODE",prev
 
+            node.parent = weakref.ref(self)
             self.children.append(node)
             return None
 
@@ -132,6 +135,13 @@
                 for yoodl in c.traverse():
                     yield yoodl
 
+    def hmi_path(self):
+        if self.parent is None:
+            return "/"
+        p = self.parent()
+        if p.parent is None:
+            return "/" + self.name
+        return p.hmi_path() + "/" + self.name
 
     def hash(self):
         """ Produce a hash, any change in HMI tree structure change that hash """