Bug on Viewer ScrollBar with AUI fixed
authorlbessard
Tue, 09 Dec 2008 10:01:12 +0100
changeset 292 800e100038ae
parent 291 e580c945c62a
child 293 dbc366959daf
Bug on Viewer ScrollBar with AUI fixed
PLCOpenEditor.py
Viewer.py
--- a/PLCOpenEditor.py	Mon Dec 01 14:13:58 2008 +0100
+++ b/PLCOpenEditor.py	Tue Dec 09 10:01:12 2008 +0100
@@ -27,6 +27,9 @@
 
 if wx.VERSION >= (2, 8, 0):
     import wx.aui
+    USE_AUI = True
+else:
+    USE_AUI = False
 
 from SFCViewer import *
 from LDViewer import *
@@ -165,22 +168,6 @@
     "IL"  : []
 }
 
-def GenerateBitmap(icon1_name, icon2_name = None):
-    if icon2_name is None:
-        return wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
-    else:
-        icon1 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
-        icon2 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon2_name))
-        width = icon1.GetWidth() + icon2.GetWidth() - 1
-        height = max(icon1.GetHeight(), icon2.GetHeight())
-        tmp_bitmap = wx.EmptyBitmap(width, height)
-        dc = wx.MemoryDC()
-        dc.SelectObject(tmp_bitmap)
-        dc.Clear()
-        dc.DrawBitmap(icon1, 0, 0)
-        dc.DrawBitmap(icon2, icon1.GetWidth() - 1, 0)
-        return tmp_bitmap
-
 def AppendMenu(parent, help, id, kind, text):
     if wx.VERSION >= (2, 6, 0):
         parent.Append(help=help, id=id, kind=kind, text=text)
@@ -369,12 +356,15 @@
         self.SetMenuBar(self.MenuBar)
         self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
         
-        if wx.VERSION >= (2, 8, 0):
+        if USE_AUI:
             self.AUIManager = wx.aui.AuiManager(self)
             self.AUIManager.SetDockSizeConstraint(0.5, 0.5)
             self.Panes = {}
         
-        if wx.VERSION < (2, 8, 0):
+            self.TreeNoteBook = wx.aui.AuiNotebook(self)
+            self.AUIManager.AddPane(self.TreeNoteBook, wx.aui.AuiPaneInfo().Caption("Project").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False))
+        
+        else:
             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)
@@ -384,10 +374,7 @@
             self.TreeNoteBook = wx.Notebook(id=ID_PLCOPENEDITORTREENOTEBOOK,
                   name='TreeNoteBook', parent=self.MainSplitter, pos=wx.Point(0,
                   0), size=wx.Size(0, 0), style=0)
-        else:
-            self.TreeNoteBook = wx.aui.AuiNotebook(self)
-            self.AUIManager.AddPane(self.TreeNoteBook, wx.aui.AuiPaneInfo().Caption("Project").Left().Layer(1).BestSize(wx.Size(200, 500)).CloseButton(False))
-        
+            
         typestreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
         if not self.Debug:
             typestreestyle |= wx.TR_EDIT_LABELS
@@ -432,7 +419,12 @@
             self.TreeNoteBook.AddPage(self.InstancesTree, "Instances")
             self.TreeNoteBook.AddPage(self.TypesTree, "Types")
             
-            if wx.VERSION < (2, 8, 0):
+            if USE_AUI:
+                self.TabsOpened = wx.aui.AuiNotebook(self)
+                self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
+                        self.OnPouSelectedChanged)
+                self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane())
+            else:
                 self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
                       name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0,
                       0), size=wx.Size(0, 0), style=0)
@@ -444,23 +436,11 @@
                         self.OnPouSelectedChanged)
             
                 self.MainSplitter.SplitVertically(self.TreeNoteBook, self.TabsOpened, 200)
-            else:
-                self.TabsOpened = wx.aui.AuiNotebook(self)
-                self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
-                        self.OnPouSelectedChanged)
-                self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane())
         else:
             self.TreeNoteBook.AddPage(self.TypesTree, "Types")
             self.TreeNoteBook.AddPage(self.InstancesTree, "Instances")
             
-            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:
+            if USE_AUI:
                 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))
@@ -472,11 +452,31 @@
                           Name("ToolBar").Caption("Toolbar").
                           ToolbarPane().Top().
                           LeftDockable(False).RightDockable(False))
+            else:
+                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()
             
             self.Bind(wx.EVT_TOOL, self.OnSelectionTool, 
                   id=ID_PLCOPENEDITORTOOLBARSELECTION)
             
-            if wx.VERSION < (2, 8, 0):
+            if USE_AUI:
+                self.VariablePanelIndexer = VariablePanelIndexer(self, self, self.Controler)
+                self.AUIManager.AddPane(self.VariablePanelIndexer, wx.aui.AuiPaneInfo().Caption("Variables").Bottom().Layer(0).BestSize(wx.Size(800, 200)).CloseButton(False))
+            
+                self.TabsOpened = wx.aui.AuiNotebook(self)
+                self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
+                        self.OnPouSelectedChanged)
+                self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane().MinSize(wx.Size(0, 0)))
+            
+                self.LibraryPanel = wx.Panel(id=ID_PLCOPENEDITORLIBRARYPANEL,
+                      name='LibraryPanel', parent=self, pos=wx.Point(0,
+                      0), size=wx.Size(0, 0), style=0)
+                self.AUIManager.AddPane(self.LibraryPanel, wx.aui.AuiPaneInfo().Caption("Library").Right().Layer(0).BestSize(wx.Size(250, 400)).CloseButton(False))
+            else:
                 self.SecondSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORSECONDSPLITTER,
                       name='SecondSplitter', parent=self.MainSplitter, point=wx.Point(0, 0),
                       size=wx.Size(0, 0), style=wx.SP_3D)
@@ -494,8 +494,11 @@
                 self.SecondSplitter.SplitHorizontally(self.ThirdSplitter, self.VariablePanelIndexer, -200)
                 
                 self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
-                      name='TabsOpened', parent=self.SecondSplitter, pos=wx.Point(0,
+                      name='TabsOpened', parent=self.ThirdSplitter, pos=wx.Point(0,
                       0), size=wx.Size(0, 0), style=0)
+                self.TabsImageList = wx.ImageList(16, 31)
+                self.TabsOpened.SetImageList(self.TabsImageList)
+                self.TabsImageListIndexes = {}
                 if wx.VERSION >= (2, 6, 0):
                     self.TabsOpened.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
                         self.OnPouSelectedChanged, id=ID_PLCOPENEDITORTABSOPENED)
@@ -508,20 +511,7 @@
                       0), size=wx.Size(0, 0), style=wx.SUNKEN_BORDER)
                 
                 self.ThirdSplitter.SplitVertically(self.TabsOpened, self.LibraryPanel, -250)
-            else:
-                self.VariablePanelIndexer = VariablePanelIndexer(self, self, self.Controler)
-                self.AUIManager.AddPane(self.VariablePanelIndexer, wx.aui.AuiPaneInfo().Caption("Variables").Bottom().Layer(0).BestSize(wx.Size(800, 200)).CloseButton(False))
-            
-                self.TabsOpened = wx.aui.AuiNotebook(self)
-                self.TabsOpened.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,
-                        self.OnPouSelectedChanged)
-                self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane())
-            
-                self.LibraryPanel = wx.Panel(id=ID_PLCOPENEDITORLIBRARYPANEL,
-                      name='LibraryPanel', parent=self, pos=wx.Point(0,
-                      0), size=wx.Size(0, 0), style=0)
-                self.AUIManager.AddPane(self.LibraryPanel, wx.aui.AuiPaneInfo().Caption("Library").Right().Layer(0).BestSize(wx.Size(250, 400)).CloseButton(False))
-            
+                
             if wx.Platform == '__WXMSW__':
                 librarytreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
             else:
@@ -542,7 +532,7 @@
             
             self._init_sizers()
         
-        if wx.VERSION >= (2, 8, 0):
+        if USE_AUI:
             self.AUIManager.Update()
     
     def __init__(self, parent, controler = None, fileOpen = None, debug = False):
@@ -704,15 +694,40 @@
 #                            Notebook Unified Functions
 #-------------------------------------------------------------------------------
 
+    def GenerateBitmap(self, icon1_name, icon2_name = None):
+        if not USE_AUI:
+            index = self.TabsImageListIndexes.get((icon1_name, icon2_name), None)
+            if index is not None:
+                return index
+        if icon2_name is None:
+            tmp_bitmap = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
+        else:
+            icon1 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon1_name))
+            icon2 = wx.Bitmap(os.path.join(CWD, 'Images', '%s.png'%icon2_name))
+            width = icon1.GetWidth() + icon2.GetWidth() - 1
+            height = max(icon1.GetHeight(), icon2.GetHeight())
+            tmp_bitmap = wx.EmptyBitmap(width, height)
+            dc = wx.MemoryDC()
+            dc.SelectObject(tmp_bitmap)
+            dc.Clear()
+            dc.DrawBitmap(icon1, 0, 0)
+            dc.DrawBitmap(icon2, icon1.GetWidth() - 1, 0)
+        if USE_AUI:
+            return tmp_bitmap
+        else:
+            index = self.TabsImageList.Add(tmp_bitmap)
+            self.TabsImageListIndexes[(icon1_name, icon2_name)] = index
+            return index
+        
     def DeleteAllPages(self):
-        if wx.VERSION >= (2, 8, 0):
+        if USE_AUI:
             for idx in xrange(self.TabsOpened.GetPageCount()):
                 self.TabsOpened.DeletePage(0)
         else:
             self.TabsOpened.DeleteAllPages()
 
     def SetPageBitmap(self, idx, bitmap):
-        if wx.VERSION >= (2, 8, 0):
+        if USE_AUI:
             return self.TabsOpened.SetPageBitmap(idx, bitmap)
         else:
             return self.TabsOpened.SetPageImage(idx, bitmap)
@@ -1192,19 +1207,19 @@
             if words[0] == "P":
                 pou_type = self.Controler.GetEditedElementType(window.GetTagName(), self.Debug)[1].upper()
                 pou_body_type = self.Controler.GetEditedElementBodyType(window.GetTagName(), self.Debug)
-                self.SetPageBitmap(idx, GenerateBitmap(pou_type, pou_body_type))
+                self.SetPageBitmap(idx, self.GenerateBitmap(pou_type, pou_body_type))
             elif words[0] == "T":
                 pou_body_type = self.Controler.GetEditedElementBodyType(window.GetTagName(), self.Debug)
-                self.SetPageBitmap(idx, GenerateBitmap("TRANSITION", pou_body_type))
+                self.SetPageBitmap(idx, self.GenerateBitmap("TRANSITION", pou_body_type))
             elif words[0] == "A":
                 pou_body_type = self.Controler.GetEditedElementBodyType(window.GetTagName(), self.Debug)
-                self.SetPageBitmap(idx, GenerateBitmap("ACTION", pou_body_type))
+                self.SetPageBitmap(idx, self.GenerateBitmap("ACTION", pou_body_type))
             elif words[0] == "C":
-                self.SetPageBitmap(idx, GenerateBitmap("CONFIGURATION"))
+                self.SetPageBitmap(idx, self.GenerateBitmap("CONFIGURATION"))
             elif words[0] == "R":
-                self.SetPageBitmap(idx, GenerateBitmap("RESOURCE"))
+                self.SetPageBitmap(idx, self.GenerateBitmap("RESOURCE"))
             elif words[0] == "D":
-                self.SetPageBitmap(idx, GenerateBitmap("DATATYPE"))
+                self.SetPageBitmap(idx, self.GenerateBitmap("DATATYPE"))
             if self.Debug:
                 self.TabsOpened.SetPageText(idx, window.GetInstancePath())
             else:
@@ -1907,14 +1922,14 @@
                 else:
                     self.Disconnect(id=item, eventType=wx.wxEVT_COMMAND_MENU_SELECTED) 
                 
-                if wx.VERSION < (2, 8, 0):
+                if USE_AUI:
+                    ToolBar = self.Panes["ToolBar"]
+                else:
                     ToolBar = self.ToolBar
-                else:
-                    ToolBar = self.Panes["ToolBar"]
                 if ToolBar:
                     ToolBar.DeleteTool(item)
                     ToolBar.Realize()
-                    if wx.VERSION >= (2, 8, 0):
+                    if USE_AUI:
                         self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
                         self.AUIManager.Update()
 
@@ -1929,10 +1944,10 @@
                 self.ResetToolBar()
                 self.CurrentLanguage = language
                 self.CurrentToolBar = []
-                if wx.VERSION < (2, 8, 0):
+                if USE_AUI:
+                    ToolBar = self.Panes["ToolBar"]
+                else:
                     ToolBar = self.ToolBar
-                else:
-                    ToolBar = self.Panes["ToolBar"]
                 if ToolBar:
                     for radio, modes, id, method, picture, help in ToolBarItems[language]:
                         if modes & self.DrawingMode:
@@ -1943,7 +1958,7 @@
                             self.Bind(wx.EVT_TOOL, getattr(self, method), id=id)
                             self.CurrentToolBar.append(id)
                     ToolBar.Realize()
-                    if wx.VERSION >= (2, 8, 0):
+                    if USE_AUI:
                         self.AUIManager.GetPane("ToolBar").BestSize(ToolBar.GetBestSize())
                         self.AUIManager.Update()
             elif not language:
@@ -1961,18 +1976,18 @@
         if selected != -1:
             window = self.TabsOpened.GetPage(selected)
             window.SetMode(MODE_SELECTION)
-        if wx.VERSION < (2, 8, 0):
+        if USE_AUI:
+            ToolBar = self.Panes["ToolBar"]
+        else:
             ToolBar = self.ToolBar
-        else:
-            ToolBar = self.Panes["ToolBar"]
         if ToolBar:
             ToolBar.ToggleTool(ID_PLCOPENEDITORTOOLBARSELECTION, True)
         
     def ResetToolToggle(self, id):
-        if wx.VERSION < (2, 8, 0):
+        if USE_AUI:
+            tool = self.Panes["ToolBar"].FindById(id)
+        else:
             tool = self.ToolBar.FindById(id)
-        else:
-            tool = self.Panes["ToolBar"].FindById(id)
         tool.SetToggle(False)
 
     def OnSelectionTool(self, event):
--- a/Viewer.py	Mon Dec 01 14:13:58 2008 +0100
+++ b/Viewer.py	Tue Dec 09 10:01:12 2008 +0100
@@ -23,6 +23,10 @@
 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import wx
+if wx.VERSION >= (2, 8, 0):
+    USE_AUI = True
+else:
+    USE_AUI = False
 
 from plcopen.structures import *
 from PLCControler import ITEM_POU
@@ -2583,7 +2587,8 @@
         self.Scroll(x, yp)
         
     def OnMoveWindow(self, event):
-        self.GetBestSize()
+        if not USE_AUI:
+            self.GetBestSize()
         self.RefreshScrollBars()
         self.RefreshVisibleElements()
         event.Skip()