wx.notebook GetCurrentPage returns Nonetype in Windows 7 but panel object in Linux

Hi everyone,

I have an event handler function within a notebook class that uses self.GetCurrentPage().

In Linux, this returns the expected panel instance, but when run in Windows XP and Windows 7, it returns None.

Is there any known possible reason for this?

Thanks,

Eric

Hi,

···

On Tue, Jan 3, 2012 at 3:53 PM, Eric Y. Zhao <ezhao15@gmail.com> wrote:

Hi everyone,

I have an event handler function within a notebook class that uses
self.GetCurrentPage().

In Linux, this returns the expected panel instance, but when run in Windows
XP and Windows 7, it returns None.

Is there any known possible reason for this?

Not of the top of my head but there could be a difference in the order
of operations that occur during certain events.

What event(s) are you responding to when this occurs?

Can you make a small runnable sample app that reproduces the problem
(MakingSampleApps - wxPyWiki)?

Cody

Hi Cody,

Thanks for the quick reply. I actually just resolved the problem.
I had a structure like the following

class Book(wx.Notebook):
    def __init__(self, parent):
        wx.Notebook.__init__(self, parent)
        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
self.on_notebook_change, self)

    def on_notebook_change(self, evt):
        currentPanel = self.GetCurrentPage()
        print currentPanel

This would have printed None when the event was triggered. In
addition, I found that self.GetSelection returned -1 every time the
event was triggered.

I resolved the issue by changing a single line. I changed
        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
self.on_notebook_change, self)
to
        parent.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,
self.on_notebook_change, self)

so that the event is bound to the parent panel/frame rather than to
the notebook instance itself.
Should this make a difference? And why does it seem to work either way
on Linux?

Thanks

···

On Jan 3, 2:23 pm, Cody <codyprec...@gmail.com> wrote:

Hi,

On Tue, Jan 3, 2012 at 3:53 PM, Eric Y. Zhao <ezha...@gmail.com> wrote:

> Hi everyone,

> I have an event handler function within a notebook class that uses
> self.GetCurrentPage().

> In Linux, this returns the expected panel instance, but when run in Windows
> XP and Windows 7, it returns None.

> Is there any known possible reason for this?

Not of the top of my head but there could be a difference in the order
of operations that occur during certain events.

What event(s) are you responding to when this occurs?

Can you make a small runnable sample app that reproduces the problem
(MakingSampleApps - wxPyWiki)?

Cody