Fixed bug when modifying ConfTreeNode IEC Channel
authorLaurent Bessard
Thu, 09 May 2013 17:52:51 +0200
changeset 1105 f0e5b475a074
parent 1104 017cd95bc07e
child 1106 843d181f73b4
Fixed bug when modifying ConfTreeNode IEC Channel
IDEFrame.py
ProjectController.py
editors/ConfTreeNodeEditor.py
--- a/IDEFrame.py	Thu May 09 12:50:51 2013 +0200
+++ b/IDEFrame.py	Thu May 09 17:52:51 2013 +0200
@@ -1419,12 +1419,35 @@
 #-------------------------------------------------------------------------------
 
     def RefreshProjectTree(self):
+        # Disconnect event when selection in treectrl changed
+        self.Unbind(wx.EVT_TREE_SEL_CHANGED, 
+                    id=ID_PLCOPENEDITORPROJECTTREE)
+    
+        # Extract current selected item tagname
+        selected = self.ProjectTree.GetSelection()
+        if selected is not None and selected.IsOk():
+            item_infos = self.ProjectTree.GetPyData(selected)
+            tagname = item_infos.get("tagname", None)
+        else:
+            tagname = None
+        
+        # Refresh treectrl items according to project infos
         infos = self.Controler.GetProjectInfos()
         root = self.ProjectTree.GetRootItem()
         if not root.IsOk():
             root = self.ProjectTree.AddRoot(infos["name"])
         self.GenerateProjectTreeBranch(root, infos)
         self.ProjectTree.Expand(root)
+        
+        # Select new item corresponding to previous selected item
+        if tagname is not None:
+            wx.CallAfter(self.SelectProjectTreeItem, tagname)
+    
+        # Reconnect event when selection in treectrl changed
+        wx.CallAfter(self.Bind, 
+            wx.EVT_TREE_SEL_CHANGED, 
+            self.OnProjectTreeItemSelected,
+            id=ID_PLCOPENEDITORPROJECTTREE)
 
     def ResetSelectedItem(self):
         self.SelectedItem = None
--- a/ProjectController.py	Thu May 09 12:50:51 2013 +0200
+++ b/ProjectController.py	Thu May 09 17:52:51 2013 +0200
@@ -330,6 +330,7 @@
             values.append(
                 {"name": "%s: %s" % (CTNChild.GetFullIEC_Channel(),
                                      CTNChild.CTNName()), 
+                 "tagname": CTNChild.CTNFullName(),
                  "type": ITEM_CONFNODE, 
                  "confnode": CTNChild,
                  "icon": CTNChild.GetIconName(),
--- a/editors/ConfTreeNodeEditor.py	Thu May 09 12:50:51 2013 +0200
+++ b/editors/ConfTreeNodeEditor.py	Thu May 09 17:52:51 2013 +0200
@@ -506,7 +506,6 @@
             res = self.SetConfNodeParamsAttribute("BaseParams.IEC_Channel", confnode_IECChannel + dir)
             wx.CallAfter(self.RefreshIECChannelControlsState)
             wx.CallAfter(self.ParentWindow._Refresh, TITLE, FILEMENU, PROJECTTREE)
-            wx.CallAfter(self.ParentWindow.SelectProjectTreeItem, self.GetTagName())
             event.Skip()
         return OnConfNodeTreeItemChannelChanged