Adding support for loading specific POUs library in LPCBeremiz
authorlaurent
Wed, 14 Dec 2011 15:18:32 +0100
changeset 605 279c16d017f3
parent 604 5b42b4401e6b
child 606 d65122c61eaf
Adding support for loading specific POUs library in LPCBeremiz
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Wed Dec 14 15:17:22 2011 +0100
+++ b/PLCOpenEditor.py	Wed Dec 14 15:18:32 2011 +0100
@@ -1911,46 +1911,47 @@
 #-------------------------------------------------------------------------------
 
     def RefreshLibraryTree(self):
-        to_delete = []
-        blocktypes = self.Controler.GetBlockTypes()
-        root = self.LibraryTree.GetRootItem()
-        if not root.IsOk():
-            root = self.LibraryTree.AddRoot("")
-        if wx.VERSION >= (2, 6, 0):
-            category_item, root_cookie = self.LibraryTree.GetFirstChild(root)
-        else:
-            category_item, root_cookie = self.LibraryTree.GetFirstChild(root, 0)
-        for category in blocktypes:
-            category_name = category["name"]
-            if not category_item.IsOk():
-                category_item = self.LibraryTree.AppendItem(root, _(category_name))
-                if wx.Platform != '__WXMSW__':
-                    category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
+        if self.Controler is not None:
+            to_delete = []
+            blocktypes = self.Controler.GetBlockTypes()
+            root = self.LibraryTree.GetRootItem()
+            if not root.IsOk():
+                root = self.LibraryTree.AddRoot("")
+            if wx.VERSION >= (2, 6, 0):
+                category_item, root_cookie = self.LibraryTree.GetFirstChild(root)
             else:
-                self.LibraryTree.SetItemText(category_item, _(category_name))
-            self.LibraryTree.SetPyData(category_item, {"type" : CATEGORY})
-            if wx.VERSION >= (2, 6, 0):
-                blocktype_item, category_cookie = self.LibraryTree.GetFirstChild(category_item)
-            else:
-                blocktype_item, category_cookie = self.LibraryTree.GetFirstChild(category_item, 0)        
-            for blocktype in category["list"]:
-                if not blocktype_item.IsOk():
-                    blocktype_item = self.LibraryTree.AppendItem(category_item, blocktype["name"])
+                category_item, root_cookie = self.LibraryTree.GetFirstChild(root, 0)
+            for category in blocktypes:
+                category_name = category["name"]
+                if not category_item.IsOk():
+                    category_item = self.LibraryTree.AppendItem(root, _(category_name))
                     if wx.Platform != '__WXMSW__':
-                        blocktype_item, category_cookie = self.LibraryTree.GetNextChild(category_item, category_cookie)
+                        category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
                 else:
-                    self.LibraryTree.SetItemText(blocktype_item, blocktype["name"])
-                self.LibraryTree.SetPyData(blocktype_item, {"type" : BLOCK, "block_type" : blocktype["type"], "inputs" : tuple([type for name, type, modifier in blocktype["inputs"]])})
-                blocktype_item, category_cookie = self.LibraryTree.GetNextChild(category_item, category_cookie)
-            while blocktype_item.IsOk():
-                to_delete.append(blocktype_item)
-                blocktype_item, category_cookie = self.LibraryTree.GetNextChild(category_item, category_cookie)
-            category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
-        while category_item.IsOk():
-            to_delete.append(category_item)
-            category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
-        for item in to_delete:
-            self.LibraryTree.Delete(item)
+                    self.LibraryTree.SetItemText(category_item, _(category_name))
+                self.LibraryTree.SetPyData(category_item, {"type" : CATEGORY})
+                if wx.VERSION >= (2, 6, 0):
+                    blocktype_item, category_cookie = self.LibraryTree.GetFirstChild(category_item)
+                else:
+                    blocktype_item, category_cookie = self.LibraryTree.GetFirstChild(category_item, 0)        
+                for blocktype in category["list"]:
+                    if not blocktype_item.IsOk():
+                        blocktype_item = self.LibraryTree.AppendItem(category_item, blocktype["name"])
+                        if wx.Platform != '__WXMSW__':
+                            blocktype_item, category_cookie = self.LibraryTree.GetNextChild(category_item, category_cookie)
+                    else:
+                        self.LibraryTree.SetItemText(blocktype_item, blocktype["name"])
+                    self.LibraryTree.SetPyData(blocktype_item, {"type" : BLOCK, "block_type" : blocktype["type"], "inputs" : tuple([type for name, type, modifier in blocktype["inputs"]])})
+                    blocktype_item, category_cookie = self.LibraryTree.GetNextChild(category_item, category_cookie)
+                while blocktype_item.IsOk():
+                    to_delete.append(blocktype_item)
+                    blocktype_item, category_cookie = self.LibraryTree.GetNextChild(category_item, category_cookie)
+                category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
+            while category_item.IsOk():
+                to_delete.append(category_item)
+                category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
+            for item in to_delete:
+                self.LibraryTree.Delete(item)
 
     def OnLibraryTreeItemSelected(self, event):
         selected = event.GetItem()