Show notebook page from event

Hi Marco,

The first problem is that I have some notebook stored in a dictionary
called notebookList.
I want to show a page in a notebook by a click-event on a menuitem.
That is when I click in the menuItem I would like that the relative
page of relative notebook show us.

Something like this:
notebookList[thatSection].ShowPage(1) #I don't know how to get the
numberOfPage and get them each one by one.

Uhm, I don't see the problem here: do you already know which page you
want to show or is it menu-dependent? In the first case, you can just
do something like:

notebookList[thatSection].SetSelection(yourPage)

Otherwise, you should link the menu ID (or the menu label) to the page
you want to show, i.e.:

def OnMenu(self, event):

    if event.GetId() == ID_SHOW_PAGE_1:
        notebookList[thatSection].SetSelection(1)

Or something along these lines (maybe a more clever approach).

The second question is about calling the function in Bind()

wx.EVT_MENU(MainView, menuItem.GetId(), self.onClick)

def onClick (self, event):
pass

The question is: is it possibile to pass some widget parameters at onClick() ?

Well, you could either store a reference to your parameter like:

self.myParameter = whatever

And then use it in the event handler, or you could use this solution
posted by Robin:

HTH.

Andrea.

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

···

On 4/18/07, Sbaush wrote:

Wednesday, April 18, 2007, 9:51:55 AM, Marco Meoni - Sbaush wrote:

What do you mean when you tell about link the menu label to a page? In
my case the ID of all the elements of the menu is the same, because
the menu is generated automatically...

Although you can get wxPython to generate the IDs automatically,
they'll not be the same. They _cannot_ be the same.

So it's too important to link the events to the menuitem label, so
we could write a controls to bind to correct page. How can i know
the label of the menu, like the GetId for the ID?

You can't do that directly. And even if you do it'll become a tricky
task when you think of i18n, for example.

Please see the attached file for a way to change wx.Notebook pages via
a wx.Menubar. But if your app is going to require a more complex
wx.Menubar, hopefully metamenus
<http://j.domaindlx.com/elements28/wxpython/Metamenus.html&gt; will save
you a lot of time when coding your own menus.

-- tacao

No bits were harmed during the making of this e-mail.

nbtest.py (3 KB)