--- a/svghmi/svghmi.py Wed Mar 10 09:59:18 2021 +0100
+++ b/svghmi/svghmi.py Wed Mar 10 10:01:05 2021 +0100
@@ -17,7 +17,6 @@
-import wx.dataview as dv
from lxml.etree import XSLTApplyError
@@ -130,6 +129,24 @@
+ def from_etree(cls, enode): + alternative constructor, restoring HMI Tree from XML backup + note: all C-related information is gone, + this restore is only for tree display and widget picking + attributes = enode.attrib + name = attributes["name"] + path = attributes["path"].split('.') if "path" in attributes else None + hmiclass = attributes.get("class", None) + # hash is computed on demand + node = cls(path, name, nodetype, hmiclass=hmiclass) + for child in enode.iterchildren(): + node.children.append(cls.from_etree(child)) if hasattr(self, "children"):
@@ -343,6 +360,12 @@
runtimefile.write(svghmiservercode)
+ # Backup HMI Tree in XML form so that it can be loaded without building + hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") + hmitree_backup_file = open(hmitree_backup_path, 'w') + hmitree_backup_file.write(etree.tostring(hmi_tree_root.etree())) + hmitree_backup_file.close() return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "",
("runtime_00_svghmi.py", open(runtimefile_path, "rb")))
@@ -353,14 +376,11 @@
class HMITreeSelector(wx.TreeCtrl):
def __init__(self, parent):
- wx.TreeCtrl.__init__(self,parent,style=wx.TR_MULTIPLE)# | wx.TR_HIDE_ROOT)
- self.il = il = wx.ImageList(*isz)
- self.fldridx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_FOLDER, wx.ART_OTHER, isz))
- self.fldropenidx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_FOLDER_OPEN, wx.ART_OTHER, isz))
- self.fileidx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))
+ wx.TreeCtrl.__init__(self, parent, style=( on_hmitree_update = self.SVGHMIEditorUpdater()
@@ -372,16 +392,12 @@
if c.hmiclass is not None else c.name
tc_child = self.AppendItem(current_tc_root, display_name)
self.SetPyData(tc_child, None)
- self.SetItemImage(tc_child, self.fldridx, wx.TreeItemIcon_Normal)
- self.SetItemImage(tc_child, self.fldropenidx, wx.TreeItemIcon_Expanded)
self._recurseTree(c,tc_child)
display_name = '{} {}'.format(c.nodetype[4:], c.name)
tc_child = self.AppendItem(current_tc_root, display_name)
self.SetPyData(tc_child, None)
- self.SetItemImage(tc_child, self.fileidx, wx.TreeItemIcon_Normal)
- self.SetItemImage(tc_child, self.fileidx, wx.TreeItemIcon_Expanded)
@@ -394,11 +410,10 @@
root_display_name = _("Please build to see HMI Tree") if hmi_tree_root is None else "HMI"
self.root = self.AddRoot(root_display_name)
self.SetPyData(self.root, None)
- self.SetItemImage(self.root, self.fldridx, wx.TreeItemIcon_Normal)
- self.SetItemImage(self.root, self.fldropenidx, wx.TreeItemIcon_Expanded)
if hmi_tree_root is not None:
self._recurseTree(hmi_tree_root, self.root)
@@ -428,6 +443,15 @@
def CreateHMITreeView(self, parent):
#self.HMITreeView = HMITreeView(self)
+ if hmi_tree_root is None: + buildpath = self.Controler.GetCTRoot()._getBuildPath() + hmitree_backup_path = os.path.join(buildpath, "hmitree.xml") + if os.path.exists(hmitree_backup_path): + hmitree_backup_file = open(hmitree_backup_path, 'r') + hmi_tree_root = HMITreeNode.from_etree(etree.parse(hmitree_backup_file).getroot()) return HMITreeSelector(parent)