Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
authorlaurent
Thu, 16 Feb 2012 22:55:50 +0100
changeset 647 2d53c653d8d2
parent 646 97bed1acd860
child 648 95d165193770
Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
PLCControler.py
PLCOpenEditor.py
--- a/PLCControler.py	Wed Feb 15 00:30:02 2012 +0100
+++ b/PLCControler.py	Thu Feb 16 22:55:50 2012 +0100
@@ -302,14 +302,14 @@
             self.FileName = os.path.splitext(os.path.basename(filepath))[0]
     
     # Change project properties
-    def SetProjectProperties(self, name = None, properties = None):
+    def SetProjectProperties(self, name = None, properties = None, buffer = True):
         if self.Project is not None:
             if name is not None:
                 self.Project.setname(name)
             if properties is not None:
                 self.Project.setfileHeader(properties)
                 self.Project.setcontentHeader(properties)
-            if name is not None or properties is not None:
+            if buffer and name is not None or properties is not None:
                 self.BufferProject()
     
     # Return project name
--- a/PLCOpenEditor.py	Wed Feb 15 00:30:02 2012 +0100
+++ b/PLCOpenEditor.py	Thu Feb 16 22:55:50 2012 +0100
@@ -1221,9 +1221,9 @@
             window = self.TabsOpened.GetPage(selected)
             if not window.IsDebugging():
                 wx.CallAfter(self.SelectTypesTreeItem, window.GetTagName())
+                window.RefreshView()
             else:
                 wx.CallAfter(self.SelectInstancesTreeItem, window.GetInstancePath())
-            window.RefreshView()
         wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, TOOLBAR)
         event.Skip()
 
@@ -1845,6 +1845,7 @@
                         icon = self.GenerateBitmap("ACTION", bodytype)
                     new_window.SetIcon(icon)
                     self.AddPage(new_window, "")
+                    new_window.RefreshView()
                     new_window.SetFocus()
                     self.RefreshPageTitles()
             if selected_item is not None and selected_infos[0] in ITEMS_VARIABLE:
@@ -1902,29 +1903,30 @@
             event.Skip()
         return AddVariableGraphic
 
-    def RecursiveInstancesTreeItemSelection(self, root, instancepath):
-        found = False
+    def GetInstancesTreeItem(self, root, instancepath):
         paths = instancepath.split(".", 1)
         if wx.VERSION >= (2, 6, 0):
             item, root_cookie = self.InstancesTree.GetFirstChild(root)
         else:
             item, root_cookie = self.InstancesTree.GetFirstChild(root, 0)
-        while item.IsOk() and not found:
+        while item.IsOk():
             name = self.InstancesTree.GetItemText(item).split(" (")[0]
             if name == paths[0]:
                 if len(paths) == 1:
-                    self.InstancesTree.SelectItem(item)
-                    return True
+                    return item
                 else:
-                    found = self.RecursiveInstancesTreeItemSelection(item, paths[1])
+                    return self.GetInstancesTreeItem(item, paths[1])
             item, root_cookie = self.InstancesTree.GetNextChild(root, root_cookie)
-        return found
+        return None
     
     def SelectInstancesTreeItem(self, instancepath):
         if self.InstancesTree is not None:
             root = self.InstancesTree.GetRootItem()
             if root.IsOk():
-                return self.RecursiveInstancesTreeItemSelection(root, instancepath)
+                item = self.GetInstancesTreeItem(root, instancepath)
+                if item is not None:
+                    self.InstancesTree.SelectItem(item)
+                    return True
         return False
     
     def ResetGraphicViewers(self):
@@ -1933,15 +1935,28 @@
             if isinstance(editor, GraphicViewer):
                 editor.ResetView()
 
-    def CloseDebugTabs(self):
+    def CloseObsoleteDebugTabs(self):
         if self.EnableDebug:
             idxs = range(self.TabsOpened.GetPageCount())
             idxs.reverse()
+            root = None
+            if self.InstancesTree is not None:
+                root = self.InstancesTree.GetRootItem()
+                if not root.IsOk():
+                    root = None
             for idx in idxs:
-                window = self.TabsOpened.GetPage(idx)
-                if window.IsDebugging():
-                    self.TabsOpened.DeletePage(idx)
-            self.DebugVariablePanel.ResetGrid()
+                editor = self.TabsOpened.GetPage(idx)
+                item = None
+                if root is not None:
+                    item = self.GetInstancesTreeItem(root, editor.GetInstancePath())
+                if editor.IsDebugging():
+                    if item is None:
+                        self.TabsOpened.DeletePage(idx)
+                    elif isinstance(editor, GraphicViewer):
+                        editor.ResetView()
+                    else:
+                        editor.RefreshView()
+            self.DebugVariablePanel.UnregisterObsoleteData()
     
     def AddDebugVariable(self, iec_path):
         if self.EnableDebug:
@@ -4109,6 +4124,16 @@
         self.VariablesGrid.RefreshButtons()
         self.Thaw()
     
+    def UnregisterObsoleteData(self):
+        for idx, item in enumerate(self.Table.GetData()):
+            if self.GetDataType(item.GetVariable()) is None:
+                self.RemoveDataConsumer(item)
+                self.Table.RemoveItem(idx)
+        self.Freeze()
+        self.Table.ResetView(self.VariablesGrid)
+        self.VariablesGrid.RefreshButtons()
+        self.Thaw()
+    
     def ResetGrid(self):
         self.DeleteDataConsumers()
         self.Table.Empty()