Fixing standard functions library treectrl in library panel in order to make it similar on all platforms
authorlaurent
Fri, 09 Dec 2011 10:22:26 +0100
changeset 599 4bb7b132e15d
parent 598 510647310137
child 600 7db729686416
Fixing standard functions library treectrl in library panel in order to make it similar on all platforms
Fixing Toolbar refreshing method in order to make it faster
PLCOpenEditor.py
Viewer.py
--- 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()
--- a/Viewer.py	Fri Dec 09 10:15:42 2011 +0100
+++ b/Viewer.py	Fri Dec 09 10:22:26 2011 +0100
@@ -27,10 +27,6 @@
 from threading import Lock
 
 import wx
-if wx.VERSION >= (2, 8, 0):
-    USE_AUI = True
-else:
-    USE_AUI = False
 
 from plcopen.structures import *
 from PLCControler import ITEM_POU
@@ -2920,8 +2916,7 @@
                 self.Scroll(x, yp)
         
     def OnMoveWindow(self, event):
-        if not USE_AUI:
-            self.Editor.GetBestSize()
+        self.Editor.GetBestSize()
         self.RefreshScrollBars()
         self.RefreshVisibleElements()
         event.Skip()