wxNotebook and EVT_NOTEBOOK_PAGE_CHANGED and GetSelection()

When I have a wxNotebook, and I remove a page,
I get a PAGE_CHANGED event.

When I'm handling at this event, I seem to get odd results back from
both the event.GetSelection() and notebook.GetSelection() calls: If page
0 is selected, and I remove page 0, GetSelection() returns 1, not 0 -
even if there's no page 1 after the deletion.

I'm using wxPythonGTK-py2.2-2.4.0.7-1 on RH7.0 linux.

When I run this on Windows, it works.

Any suggestions? Am I doing something crazy here?

Thanks,
  Tom

Here's a little program that demonstrates the problem:

from wxPython.wx import *
import time
import sys

class MyFrame(wxFrame):

    def OnButton(self, event):
        self.nb.RemovePage(0)

    def OnPageChanged(self, event):
        print "on page changed: new %d old %d"%(event.GetSelection(),
event.GetOldSelection())
        print "on page notebook selection %d"%(self.nb.GetSelection())

    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title, size=(300, 250))

        self.nb = wxNotebook(self, -1)

        for i in range(5):
            page = wxPanel(self.nb, -1)
            self.nb.AddPage(page, "page %d"%i)
            b = wxButton(page, -1, "button %d"%i)
            EVT_BUTTON(self, b.GetId(), self.OnButton)
        EVT_NOTEBOOK_PAGE_CHANGED(self, self.nb.GetId(),
self.OnPageChanged)

app = wxPySimpleApp()
frame = MyFrame(NULL, -1, "Notebook Test")
frame.Show()
app.MainLoop()

Tom McDermott wrote:

When I have a wxNotebook, and I remove a page,
I get a PAGE_CHANGED event.

When I'm handling at this event, I seem to get odd results back from
both the event.GetSelection() and notebook.GetSelection() calls: If page
0 is selected, and I remove page 0, GetSelection() returns 1, not 0 -
even if there's no page 1 after the deletion.

I'm using wxPythonGTK-py2.2-2.4.0.7-1 on RH7.0 linux.

When I run this on Windows, it works.

Any suggestions? Am I doing something crazy here?

Please enter a bug report about it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!