PLCOpenEditor.py
changeset 599 4bb7b132e15d
parent 587 98445f90f45d
child 604 5b42b4401e6b
--- a/PLCOpenEditor.py	Fri Dec 09 10:15:42 2011 +0100
+++ b/PLCOpenEditor.py	Fri Dec 09 10:22:26 2011 +0100
@@ -273,7 +273,7 @@
 def GetShortcutKeyCallbackFunction(viewer_function):
     def ShortcutKeyFunction(self, event):
         control = self.FindFocus()
-        if control.GetName() in ["Viewer", "TextViewer"]:
+        if control is not None and control.GetName() in ["Viewer", "TextViewer"]:
             getattr(control.Parent, viewer_function)()
         elif isinstance(control, wx.stc.StyledTextCtrl):
             getattr(control, viewer_function)()
@@ -618,14 +618,10 @@
               0), size=wx.Size(0, 0), style=0)
         self.RightNoteBook.AddPage(self.LibraryPanel, _("Library"))
         
-        if wx.Platform == '__WXMSW__':
-            librarytreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
-        else:
-            librarytreestyle = wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT|wx.TR_SINGLE|wx.SUNKEN_BORDER
         self.LibraryTree = wx.TreeCtrl(id=ID_PLCOPENEDITORLIBRARYTREE,
                   name='LibraryTree', parent=self.LibraryPanel, 
                   pos=wx.Point(0, 0), size=wx.Size(0, 0),
-                  style=librarytreestyle)
+                  style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER|wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT)
         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnLibraryTreeItemSelected,
               id=ID_PLCOPENEDITORLIBRARYTREE)
         self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnLibraryTreeBeginDrag,
@@ -1064,7 +1060,7 @@
 
     def OnSelectAllMenu(self, event):
         control = self.FindFocus()
-        if control.GetName() == "Viewer":
+        if control is not None and control.GetName() == "Viewer":
             control.Parent.SelectAll()
         elif isinstance(control, wx.stc.StyledTextCtrl):
             control.SelectAll()
@@ -1920,11 +1916,7 @@
         blocktypes = self.Controler.GetBlockTypes()
         root = self.LibraryTree.GetRootItem()
         if not root.IsOk():
-            if wx.Platform == '__WXMSW__':
-                root = self.LibraryTree.AddRoot(_("Block Types"))
-                self.LibraryTree.SetPyData(root, {"type" : CATEGORY})
-            else:
-                root = self.LibraryTree.AddRoot("")
+            root = self.LibraryTree.AddRoot("")
         if wx.VERSION >= (2, 6, 0):
             category_item, root_cookie = self.LibraryTree.GetFirstChild(root)
         else:
@@ -1960,8 +1952,6 @@
             category_item, root_cookie = self.LibraryTree.GetNextChild(root, root_cookie)
         for item in to_delete:
             self.LibraryTree.Delete(item)
-        if wx.Platform == '__WXMSW__':        
-            self.LibraryTree.Expand(root)
 
     def OnLibraryTreeItemSelected(self, event):
         selected = event.GetItem()
@@ -1992,22 +1982,25 @@
 #-------------------------------------------------------------------------------
 
     def ResetToolBar(self):
+        if USE_AUI:
+            ToolBar = self.Panes["ToolBar"]
+        else:
+            ToolBar = self.ToolBar
+        
         for item in self.CurrentToolBar:
             if wx.VERSION >= (2, 6, 0):
                 self.Unbind(wx.EVT_MENU, id=item)
             else:
                 self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
-            
-            if USE_AUI:
-                ToolBar = self.Panes["ToolBar"]
-            else:
-                ToolBar = self.ToolBar
+        
             if ToolBar:
                 ToolBar.DeleteTool(item)
-                ToolBar.Realize()
-                if USE_AUI:
-                    self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
-                    self.AUIManager.Update()
+        
+        if ToolBar:
+            ToolBar.Realize()
+            if USE_AUI:
+                self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
+                self.AUIManager.Update()
 
     def RefreshToolBar(self):
         selected = self.TabsOpened.GetSelection()