138 """ |
138 """ |
139 nodetype = enode.tag |
139 nodetype = enode.tag |
140 attributes = enode.attrib |
140 attributes = enode.attrib |
141 name = attributes["name"] |
141 name = attributes["name"] |
142 path = attributes["path"].split('.') if "path" in attributes else None |
142 path = attributes["path"].split('.') if "path" in attributes else None |
143 hmiclass = attributes.get("hmiclass", None) |
143 hmiclass = attributes.get("class", None) |
144 # hash is computed on demand |
144 # hash is computed on demand |
145 node = cls(path, name, nodetype, hmiclass=hmiclass) |
145 node = cls(path, name, nodetype, hmiclass=hmiclass) |
146 for child in enode.iterchildren(): |
146 for child in enode.iterchildren(): |
147 node.children.append(cls.from_etree(child)) |
147 node.children.append(cls.from_etree(child)) |
148 return node |
148 return node |
374 |
374 |
375 |
375 |
376 class HMITreeSelector(wx.TreeCtrl): |
376 class HMITreeSelector(wx.TreeCtrl): |
377 def __init__(self, parent): |
377 def __init__(self, parent): |
378 global on_hmitree_update |
378 global on_hmitree_update |
379 wx.TreeCtrl.__init__(self,parent,style=wx.TR_MULTIPLE)# | wx.TR_HIDE_ROOT) |
379 wx.TreeCtrl.__init__(self, parent, style=( |
380 |
380 wx.TR_MULTIPLE | |
381 isz = (16,16) |
381 wx.TR_HAS_BUTTONS | |
382 self.il = il = wx.ImageList(*isz) |
382 wx.SUNKEN_BORDER | |
383 self.fldridx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_FOLDER, wx.ART_OTHER, isz)) |
383 wx.TR_LINES_AT_ROOT)) |
384 self.fldropenidx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_FOLDER_OPEN, wx.ART_OTHER, isz)) |
|
385 self.fileidx = il.AddIcon(wx.ArtProvider.GetIcon(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) |
|
386 self.SetImageList(il) |
|
387 |
384 |
388 on_hmitree_update = self.SVGHMIEditorUpdater() |
385 on_hmitree_update = self.SVGHMIEditorUpdater() |
389 self.MakeTree() |
386 self.MakeTree() |
390 |
387 |
391 def _recurseTree(self, current_hmitree_root, current_tc_root): |
388 def _recurseTree(self, current_hmitree_root, current_tc_root): |
393 if hasattr(c, "children"): |
390 if hasattr(c, "children"): |
394 display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \ |
391 display_name = ('{} (class={})'.format(c.name, c.hmiclass)) \ |
395 if c.hmiclass is not None else c.name |
392 if c.hmiclass is not None else c.name |
396 tc_child = self.AppendItem(current_tc_root, display_name) |
393 tc_child = self.AppendItem(current_tc_root, display_name) |
397 self.SetPyData(tc_child, None) |
394 self.SetPyData(tc_child, None) |
398 self.SetItemImage(tc_child, self.fldridx, wx.TreeItemIcon_Normal) |
|
399 self.SetItemImage(tc_child, self.fldropenidx, wx.TreeItemIcon_Expanded) |
|
400 |
395 |
401 self._recurseTree(c,tc_child) |
396 self._recurseTree(c,tc_child) |
402 else: |
397 else: |
403 display_name = '{} {}'.format(c.nodetype[4:], c.name) |
398 display_name = '{} {}'.format(c.nodetype[4:], c.name) |
404 tc_child = self.AppendItem(current_tc_root, display_name) |
399 tc_child = self.AppendItem(current_tc_root, display_name) |
405 self.SetPyData(tc_child, None) |
400 self.SetPyData(tc_child, None) |
406 self.SetItemImage(tc_child, self.fileidx, wx.TreeItemIcon_Normal) |
|
407 self.SetItemImage(tc_child, self.fileidx, wx.TreeItemIcon_Expanded) |
|
408 |
401 |
409 def MakeTree(self): |
402 def MakeTree(self): |
410 global hmi_tree_root |
403 global hmi_tree_root |
411 |
404 |
412 self.Freeze() |
405 self.Freeze() |
415 self.DeleteAllItems() |
408 self.DeleteAllItems() |
416 |
409 |
417 root_display_name = _("Please build to see HMI Tree") if hmi_tree_root is None else "HMI" |
410 root_display_name = _("Please build to see HMI Tree") if hmi_tree_root is None else "HMI" |
418 self.root = self.AddRoot(root_display_name) |
411 self.root = self.AddRoot(root_display_name) |
419 self.SetPyData(self.root, None) |
412 self.SetPyData(self.root, None) |
420 self.SetItemImage(self.root, self.fldridx, wx.TreeItemIcon_Normal) |
|
421 self.SetItemImage(self.root, self.fldropenidx, wx.TreeItemIcon_Expanded) |
|
422 |
413 |
423 if hmi_tree_root is not None: |
414 if hmi_tree_root is not None: |
424 self._recurseTree(hmi_tree_root, self.root) |
415 self._recurseTree(hmi_tree_root, self.root) |
|
416 self.Expand(self.root) |
425 |
417 |
426 self.Thaw() |
418 self.Thaw() |
427 |
419 |
428 def SVGHMIEditorUpdater(self): |
420 def SVGHMIEditorUpdater(self): |
429 selfref = weakref.ref(self) |
421 selfref = weakref.ref(self) |