Adding support for wxAUI in wx 2.8
authorlbessard
Tue, 13 Nov 2007 17:21:30 +0100
changeset 120 add8e391e00c
parent 119 564564136c79
child 121 40b91ba978db
Adding support for wxAUI in wx 2.8
NoteBook still have to be switch to MDI
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Mon Nov 05 09:41:12 2007 +0100
+++ b/PLCOpenEditor.py	Tue Nov 13 17:21:30 2007 +0100
@@ -24,8 +24,10 @@
 
 from time import localtime
 from datetime import datetime
-import wx
-import wx.grid
+import wx, wx.grid
+
+if wx.VERSION >= (2, 8, 0):
+    import wx.aui
 
 from SFCViewer import *
 from LDViewer import *
@@ -313,16 +315,27 @@
             accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, ID_PLCOPENEDITORFILEMENUITEMS5)])
             self.SetAcceleratorTable(accel)
         
-        self.MainSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORMAINSPLITTER,
-              name='MainSplitter', parent=self, point=wx.Point(0, 0),
-              size=wx.Size(0, 0), style=wx.SP_3D)
-        self.MainSplitter.SetNeedUpdating(True)
-        self.MainSplitter.SetMinimumPaneSize(1)
-        
-        self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE,
-              name='treeCtrl1', parent=self.MainSplitter, pos=wx.Point(0, 0),
-              size=wx.Size(-1, -1),
-              style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
+        if wx.VERSION >= (2, 8, 0):
+            self.AUIManager = wx.aui.AuiManager(self)
+            self.Panes = {}
+        
+        if wx.VERSION < (2, 8, 0):
+            self.MainSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORMAINSPLITTER,
+                  name='MainSplitter', parent=self, point=wx.Point(0, 0),
+                  size=wx.Size(0, 0), style=wx.SP_3D)
+            self.MainSplitter.SetNeedUpdating(True)
+            self.MainSplitter.SetMinimumPaneSize(1)
+            
+            self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE,
+                  name='treeCtrl1', parent=self.MainSplitter, pos=wx.Point(0, 0),
+                  size=wx.Size(-1, -1),
+                  style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
+        else:
+            self.ProjectTree = wx.TreeCtrl(id=ID_PLCOPENEDITORPROJECTTREE,
+                  name='treeCtrl1', parent=self, pos=wx.Point(0, 0),
+                  size=wx.Size(200, -1),
+                  style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
+            self.AUIManager.AddPane(self.ProjectTree, wx.aui.AuiPaneInfo().Caption("Project Tree").CloseButton(False))
         if wx.VERSION >= (2, 6, 0):
             self.ProjectTree.Bind(wx.EVT_RIGHT_UP, self.OnProjectTreeRightUp)
         else:
@@ -338,25 +351,49 @@
         self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnProjectTreeItemSelected,
               id=ID_PLCOPENEDITORPROJECTTREE)
         
-        self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, 
-              ID_PLCOPENEDITORTOOLBAR, 'ToolBar')
-        self.ToolBar.SetToolBitmapSize(wx.Size(25, 25))
-        self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, 
-              wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object")
-        self.ToolBar.Realize()
+        if wx.VERSION < (2, 8, 0):
+            self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, 
+                  ID_PLCOPENEDITORTOOLBAR, 'ToolBar')
+            self.ToolBar.SetToolBitmapSize(wx.Size(25, 25))
+            self.ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, 
+                  wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object")
+            self.ToolBar.Realize()
+        else:
+            ToolBar = wx.ToolBar(self, ID_PLCOPENEDITORTOOLBAR, wx.DefaultPosition, wx.DefaultSize,
+                    wx.TB_FLAT | wx.TB_NODIVIDER | wx.NO_BORDER)
+            ToolBar.SetToolBitmapSize(wx.Size(25, 25))
+            ToolBar.AddRadioTool(ID_PLCOPENEDITORTOOLBARSELECTION, 
+                  wx.Bitmap(os.path.join(CWD, 'Images', 'select.png')), wx.NullBitmap, "Select an object")
+            ToolBar.Realize()
+            self.Panes["ToolBar"] = ToolBar
+            self.AUIManager.AddPane(ToolBar, wx.aui.AuiPaneInfo().
+                      Name("ToolBar").Caption("Toolbar").
+                      ToolbarPane().Top().
+                      LeftDockable(False).RightDockable(False))
+        
         self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
               id=ID_PLCOPENEDITORTOOLBARSELECTION)
-    
-        self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
-              name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0,
-              0), size=wx.Size(0, 0), style=0)
+            
+        if wx.VERSION < (2, 8, 0):
+            self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
+                  name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0,
+                  0), size=wx.Size(0, 0), style=0)
+            self.MainSplitter.SplitVertically(self.ProjectTree, self.TabsOpened, 200)
+        else:
+            self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
+                  name='TabsOpened', parent=self, pos=wx.Point(0,
+                  0), size=wx.Size(0, 0), style=0)
+            self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().Name("TabsOpened").CenterPane())
+
         if wx.VERSION >= (2, 6, 0):
             self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
                 self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED)
         else:
             wx.EVT_NOTEBOOK_PAGE_CHANGED(self.TabsOpened, ID_PLCOPENEDITORTABSOPENED,
                 self.OnPouSelectedChanged)
-        self.MainSplitter.SplitVertically(self.ProjectTree, self.TabsOpened, 200)
+        
+        if wx.VERSION > (2, 8, 0):
+            self.AUIManager.Update(); 
         
     def __init__(self, parent, controler = None, fileOpen = None):
         self.ModeSolo = controler == None
@@ -621,10 +658,16 @@
         if selected != -1:
             window = self.TabsOpened.GetPage(selected)
             window.SetMode(MODE_SELECTION)
-        self.ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
+        if wx.VERSION < (2, 8, 0):
+            self.ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
+        else:
+            self.Panes["ToolBar"].ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
 
     def ResetToolToggle(self, id):
-        tool = self.ToolBar.FindById(id)
+        if wx.VERSION < (2, 8, 0):
+            tool = self.ToolBar.FindById(id)
+        else:
+            tool = self.Panes["ToolBar"].FindById(id)
         tool.SetToggle(False)
 
     def OnSelectionTool(self, event):
@@ -1089,7 +1132,16 @@
                 self.Unbind(wx.EVT_MENU, id=item)
             else:
                 self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
-            self.ToolBar.DeleteTool(item)
+            
+            if wx.VERSION < (2, 8, 0):
+                ToolBar = self.ToolBar
+            else:
+                ToolBar = self.Panes["ToolBar"]
+            ToolBar.DeleteTool(item)
+            ToolBar.Realize()
+            if wx.VERSION >= (2, 8, 0):
+                self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
+                self.AUIManager.Update()
 
     def RefreshToolBar(self):
         language = self.Controler.GetCurrentElementEditingBodyType()
@@ -1097,15 +1149,22 @@
             self.ResetToolBar()
             self.CurrentLanguage = language
             self.CurrentToolBar = []
+            if wx.VERSION < (2, 8, 0):
+                ToolBar = self.ToolBar
+            else:
+                ToolBar = self.Panes["ToolBar"]
             for radio, modes, id, method, picture, help in ToolBarItems[language]:
                 if modes & self.DrawingMode:
                     if radio or self.DrawingMode == FREEDRAWING_MODE:
-                        self.ToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help)
+                        ToolBar.AddRadioTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), wx.NullBitmap, help)
                     else:
-                        self.ToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help)
+                        ToolBar.AddSimpleTool(id, wx.Bitmap(os.path.join(CWD, "Images", picture)), help)
                     self.Bind(wx.EVT_TOOL, getattr(self, method), id=id)
                     self.CurrentToolBar.append(id)
-            self.ToolBar.Realize()
+            ToolBar.Realize()
+            if wx.VERSION >= (2, 8, 0):
+                self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
+                self.AUIManager.Update()
         elif not language:
             self.ResetToolBar()
             self.CurrentLanguage = language