Fix bug while using 'Close project' menu and a few POUs are opened
authorlaurent
Tue, 31 Jan 2012 23:38:12 +0100
changeset 635 dbcb8e2d2730
parent 634 cc3335911c01
child 636 44978a2b9703
Fix bug while using 'Close project' menu and a few POUs are opened
PLCOpenEditor.py
controls/EditorPanel.py
--- a/PLCOpenEditor.py	Tue Jan 31 13:38:06 2012 +0100
+++ b/PLCOpenEditor.py	Tue Jan 31 23:38:12 2012 +0100
@@ -1222,7 +1222,7 @@
             if not window.IsDebugging():
                 wx.CallAfter(self.SelectTypesTreeItem, window.GetTagName())
             else:
-                wx.CallAfter(self.SelectInstancesTreeItem, self.InstancesTree.GetRootItem(), window.GetInstancePath())
+                wx.CallAfter(self.SelectInstancesTreeItem, window.GetInstancePath())
             window.RefreshView()
         wx.CallAfter(self._Refresh, FILEMENU, EDITMENU, DISPLAYMENU, TOOLBAR)
         event.Skip()
@@ -1323,40 +1323,40 @@
     def SelectTypesTreeItem(self, tagname):
         if self.TypesTree is not None:
             root = self.TypesTree.GetRootItem()
-            words = tagname.split("::")
-            if words[0] == "D":
-                return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_DATATYPE)])
-            elif words[0] == "P":
-                return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_POU)])
-            elif words[0] == "T":
-                return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_TRANSITION)])
-            elif words[0] == "A":
-                return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_ACTION)])
-            elif words[0] == "C":
-                return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION)])
-            elif words[0] == "R":
-                return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION), (words[2], ITEM_RESOURCE)])
+            if root.IsOk():
+                words = tagname.split("::")
+                if words[0] == "D":
+                    return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_DATATYPE)])
+                elif words[0] == "P":
+                    return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_POU)])
+                elif words[0] == "T":
+                    return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_TRANSITION)])
+                elif words[0] == "A":
+                    return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_POU), (words[2], ITEM_ACTION)])
+                elif words[0] == "C":
+                    return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION)])
+                elif words[0] == "R":
+                    return self.RecursiveTypesTreeItemSelection(root, [(words[1], ITEM_CONFIGURATION), (words[2], ITEM_RESOURCE)])
         return False
 
     def RecursiveTypesTreeItemSelection(self, root, items):
         found = False
-        if self.TypesTree is not None:
-            if wx.VERSION >= (2, 6, 0):
-                item, root_cookie = self.TypesTree.GetFirstChild(root)
+        if wx.VERSION >= (2, 6, 0):
+            item, root_cookie = self.TypesTree.GetFirstChild(root)
+        else:
+            item, root_cookie = self.TypesTree.GetFirstChild(root, 0)
+        while item.IsOk() and not found:
+            if (self.TypesTree.GetItemText(item), self.TypesTree.GetPyData(item)) == items[0]:
+                if len(items) == 1:
+                    self.SelectedItem = item
+                    self.TypesTree.SelectItem(item)
+                    wx.CallAfter(self.ResetSelectedItem)
+                    return True
+                else:
+                    found = self.RecursiveTypesTreeItemSelection(item, items[1:])
             else:
-                item, root_cookie = self.TypesTree.GetFirstChild(root, 0)
-            while item.IsOk() and not found:
-                if (self.TypesTree.GetItemText(item), self.TypesTree.GetPyData(item)) == items[0]:
-                    if len(items) == 1:
-                        self.SelectedItem = item
-                        self.TypesTree.SelectItem(item)
-                        wx.CallAfter(self.ResetSelectedItem)
-                        return True
-                    else:
-                        found = self.RecursiveTypesTreeItemSelection(item, items[1:])
-                else:
-                    found = self.RecursiveTypesTreeItemSelection(item, items)
-                item, root_cookie = self.TypesTree.GetNextChild(root, root_cookie)
+                found = self.RecursiveTypesTreeItemSelection(item, items)
+            item, root_cookie = self.TypesTree.GetNextChild(root, root_cookie)
         return found
 
     def OnTypesTreeBeginDrag(self, event):
@@ -1902,25 +1902,31 @@
             event.Skip()
         return AddVariableGraphic
 
-    def SelectInstancesTreeItem(self, root, instancepath):
+    def RecursiveInstancesTreeItemSelection(self, root, instancepath):
         found = False
+        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:
+            name = self.InstancesTree.GetItemText(item).split(" (")[0]
+            if name == paths[0]:
+                if len(paths) == 1:
+                    self.InstancesTree.SelectItem(item)
+                    return True
+                else:
+                    found = self.SelectInstancesTreeItem(item, paths[1])
+            item, root_cookie = self.InstancesTree.GetNextChild(root, root_cookie)
+        return found
+    
+    def SelectInstancesTreeItem(self, instancepath):
         if self.InstancesTree is not None:
-            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:
-                name = self.InstancesTree.GetItemText(item).split(" (")[0]
-                if name == paths[0]:
-                    if len(paths) == 1:
-                        self.InstancesTree.SelectItem(item)
-                        return True
-                    else:
-                        found = self.SelectInstancesTreeItem(item, paths[1])
-                item, root_cookie = self.InstancesTree.GetNextChild(root, root_cookie)
-        return found
-
+            root = self.InstancesTree.GetRootItem()
+            if root.IsOk():
+                return self.RecursiveInstancesTreeItemSelection(root, instancepath)
+        return False
+    
     def ResetGraphicViewers(self):
         for i in xrange(self.TabsOpened.GetPageCount()):
             editor = self.TabsOpened.GetPage(i)
--- a/controls/EditorPanel.py	Tue Jan 31 13:38:06 2012 +0100
+++ b/controls/EditorPanel.py	Tue Jan 31 23:38:12 2012 +0100
@@ -40,7 +40,10 @@
     
     def _init_Editor(self, prnt):
         self.Editor = None
-        
+    
+    def _init_MenuItems(self):
+        self.MenuItems = []
+    
     def _init_ctrls(self, prnt):
         wx.SplitterWindow.__init__(self, id=self.ID, name='MainSplitter', parent=prnt,
               size=wx.Size(0, 0), style=wx.SUNKEN_BORDER|wx.SP_3D)
@@ -48,6 +51,7 @@
         self.SetMinimumPaneSize(1)
         
         self._init_Editor(self)
+        self._init_MenuItems()
         
         if self.VARIABLE_PANEL_TYPE is not None:
             self.VariableEditor = VariablePanel(self, self, self.Controler, self.VARIABLE_PANEL_TYPE, self.Debug)
@@ -128,6 +132,12 @@
         if self.VariableEditor is not None:
             self.VariableEditor.RefreshView()
     
+    def GetPluginMenuItems(self):
+        return self.MenuItems
+    
+    def RefreshPluginMenu(self, plugin_menu):
+        pass
+    
     def _Refresh(self, *args):
         self.ParentWindow._Refresh(*args)