--- 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()