agw.aui LoadPerspective problem

In my program, I write the following 2 methods to add/remove the
notebook's pages.

  def AddPanel(self, panel):
    self._mainNotebook.AddPage(panel, panel.GetLabel(), False)
    panel.Show()
    self._mainNotebook.Update()

  def RemovePanel(self, idx):
    page = self._mainNotebook.GetPage(idx)
    page.Hide()
    self._mainNotebook.RemovePage(idx)
    self._mainNotebook.Update()

When the program started, I create many panels and call 'AddPanel' to
add all panels to the notebook.
Then I call 'RemovePanel' to hide one(Le'ts call it panelA) and call
notebook's 'SavePerspective', and exit the program.

When I start the program again, call notebook's 'LoadPerspective',
everything is OK. The panelA is not in the notebook also.

But, when I called:
self._mainNotebook.GetPageIndex(panelA):
The return value is not wx.NOT_FOUND.

Is this a bug?

Thank you

Zeb wrote:

In my program, I write the following 2 methods to add/remove the
notebook's pages.

  def AddPanel(self, panel):
    self._mainNotebook.AddPage(panel, panel.GetLabel(), False)
    panel.Show()
    self._mainNotebook.Update()

  def RemovePanel(self, idx):
    page = self._mainNotebook.GetPage(idx)
    page.Hide()
    self._mainNotebook.RemovePage(idx)
    self._mainNotebook.Update()

When the program started, I create many panels and call 'AddPanel' to
add all panels to the notebook.
Then I call 'RemovePanel' to hide one(Le'ts call it panelA) and call
notebook's 'SavePerspective', and exit the program.

When I start the program again, call notebook's 'LoadPerspective',
everything is OK. The panelA is not in the notebook also.

But, when I called:
self._mainNotebook.GetPageIndex(panelA):
The return value is not wx.NOT_FOUND.

Well, if it's not in the notebook then it won't have a page index because it's not a notebook page.

···

--
Robin Dunn
Software Craftsman

Because the pageA is not in the notebook, so I think when I call:
self._mainNotebook.GetPageIndex(panelA)
The return value should be wx.NOT_FOUND,
But in fact, the return value is 5.

Zeb wrote:

Because the pageA is not in the notebook, so I think when I call:
self._mainNotebook.GetPageIndex(panelA)
The return value should be wx.NOT_FOUND,
But in fact, the return value is 5.

Sorry, I didn't see the "not" in your original message. Please make a small standalone sample that shows the problem and then I'm sure Andrea will take a look at it when he gets some time.

···

--
Robin Dunn
Software Craftsman

Yesterday, I have dived into the source code. I think I have found the
reason that cause this problem.
When 'SavePerspective', the notebook only save the page's index.
For example, I have created 6 panels, and added them all into the
notebook. So When exit, the saved perspective is something like:
pane name=0,1,2,3,4,5
Let's assume the pageA has the index 3, pageB has the index 5. If I
close the pageA(index 3), then the saved perspective is something
like:
pane name=0,1,2,3,4
When I start the program, and load the perspective again, the pageB
won't be in the notebook, and the pageA will be in the notebook.

So I think maybe there is a assumption that when we 'LoadPerspective',
we must make sure the panel's acount and order is the same as the last
time we 'SavePerspective'. Is that right?

I will make a small sample later when I get home.

Thanks.

sorry, I have wrote a wrong word.

'the panel's acount and order'
should be
'the panel's amount and order'

import os, sys
import wx

import wx.lib.agw.aui as aui

class MyFrame(wx.Frame):

    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, pos=(150, 150),
size=(640, 480))

        self.CreateStatusBar()

        self._auiMgr = aui.AuiManager(self)

        client_size = self.GetClientSize()
        self._noteBook = aui.AuiNotebook(self, -1)
        self._panelA = wx.Panel(self._noteBook, -1)
        self._panelB = wx.Panel(self._noteBook, -1)
        self._panelC = wx.Panel(self._noteBook, -1)
        self._panelD = wx.Panel(self._noteBook, -1)
        self._noteBook.AddPage(self._panelA, u"PanelA", False)
        self._noteBook.AddPage(self._panelB, u"PanelB", False)
        self._noteBook.AddPage(self._panelC, u"PanelC", False)
        self._noteBook.AddPage(self._panelD, u"PanelD", False)
        self._auiMgr.AddPane(self._noteBook, aui.AuiPaneInfo
().CenterPane().PaneBorder(False))

        try:
            self._noteBook.LoadPerspective(open
(u'perspective.txt').read())
        except:
            pass

        self._auiMgr.Update()

        self.Bind(wx.EVT_CLOSE, self.__OnClose)

        self._noteBook.Bind(aui.EVT_AUINOTEBOOK_PAGE_CLOSE,
self.__OnPageClose)

    def __OnPageClose(self, e):
        idx = e.GetSelection()
        self.RemovePanel(idx)
        e.Veto()

    def AddPanel(self, panel):
        self._noteBook.AddPage(panel, panel.GetLabel(), False)
        panel.Show()
        self._noteBook.Update()

    def RemovePanel(self, idx):
        page = self._noteBook.GetPage(idx)
        page.Hide()
        self._noteBook.RemovePage(idx)
        self._noteBook.Update()

    def __OnClose(self, e):
        open(u'perspective.txt', 'w').write
(self._noteBook.SavePerspective())
        self._auiMgr.UnInit()
        self.Destroy()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, "Simple wxPython App")
        self.SetTopWindow(frame)

        frame.Show(True)
        return True

app = MyApp(redirect=False)
app.MainLoop()

This is the sample.
Run the program, and close panelC, then close the program.
The program will save perspective to 'perspective.txt'.
Run the program again, you will see panelD is disappeared, but panelC
is in the notebook.

I have solved the problem last night.
By saving a panel list string when I close the program, I make the
panel's amount and order the same as the last time I close the
program.
But I think this should be handled by notebook's Load/Save
perspective, maybe.

Hi,

2009/7/8 Zeb:

import os, sys
import wx

import wx.lib.agw.aui as aui

class MyFrame(wx.Frame):

def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, pos=(150, 150),
size=(640, 480))

   self\.CreateStatusBar\(\)

   self\.\_auiMgr = aui\.AuiManager\(self\)

   client\_size = self\.GetClientSize\(\)
   self\.\_noteBook = aui\.AuiNotebook\(self, \-1\)
   self\.\_panelA = wx\.Panel\(self\.\_noteBook, \-1\)
   self\.\_panelB = wx\.Panel\(self\.\_noteBook, \-1\)
   self\.\_panelC = wx\.Panel\(self\.\_noteBook, \-1\)
   self\.\_panelD = wx\.Panel\(self\.\_noteBook, \-1\)
   self\.\_noteBook\.AddPage\(self\.\_panelA, u"PanelA", False\)
   self\.\_noteBook\.AddPage\(self\.\_panelB, u"PanelB", False\)
   self\.\_noteBook\.AddPage\(self\.\_panelC, u"PanelC", False\)
   self\.\_noteBook\.AddPage\(self\.\_panelD, u"PanelD", False\)
   self\.\_auiMgr\.AddPane\(self\.\_noteBook, aui\.AuiPaneInfo

().CenterPane().PaneBorder(False))

   try:
       self\.\_noteBook\.LoadPerspective\(open

(u'perspective.txt').read())
except:
pass

   self\.\_auiMgr\.Update\(\)

   self\.Bind\(wx\.EVT\_CLOSE, self\.\_\_OnClose\)

   self\.\_noteBook\.Bind\(aui\.EVT\_AUINOTEBOOK\_PAGE\_CLOSE,

self.__OnPageClose)

def __OnPageClose(self, e):
idx = e.GetSelection()
self.RemovePanel(idx)
e.Veto()

def AddPanel(self, panel):
self._noteBook.AddPage(panel, panel.GetLabel(), False)
panel.Show()
self._noteBook.Update()

def RemovePanel(self, idx):
page = self._noteBook.GetPage(idx)
page.Hide()
self._noteBook.RemovePage(idx)
self._noteBook.Update()

def __OnClose(self, e):
open(u'perspective.txt', 'w').write
(self._noteBook.SavePerspective())
self._auiMgr.UnInit()
self.Destroy()

class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, "Simple wxPython App")
self.SetTopWindow(frame)

   frame\.Show\(True\)
   return True

app = MyApp(redirect=False)
app.MainLoop()

This is the sample.
Run the program, and close panelC, then close the program.
The program will save perspective to 'perspective.txt'.
Run the program again, you will see panelD is disappeared, but panelC
is in the notebook.

I have solved the problem last night.
By saving a panel list string when I close the program, I make the
panel's amount and order the same as the last time I close the
program.
But I think this should be handled by notebook's Load/Save
perspective, maybe.

It looks like a bug in AUI Save/Load perspective. I will take a look
at it next week when I'll be back from Kazakhstan.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

I have created ticket #11036 for this bug.