[wxPython] Allow changing to a wxNotebook page if conditions are met

Hi!

I'm developing a wxPython 2.3.2.1 application with Python 2.2 on Linux
which should run on Linux and on Windows. This is my first Python
application, so please bear with me :wink:

In my program I've a wxNotebook containing some pages. A certain page
should only be accessible, when the user entered something on the
previous page. At first, I wanted to do the check in a
EVT_NOTEBOOK_PAGE_CHANGING event, because that seemed to be the natural
place to do something like this because of the Veto() function.
Because this check should only be done on one special page, I thought I
could use wxNotebookEvent::GetSelection() to see where I'm going to.
However, the manual says:

  wxNotebookEvent::GetSelection
  int GetSelection() const
  Returns the currently selected page, or -1 if none was selected.
  NB: under Windows, GetSelection() will return the same value as
  GetOldSelection() when called from EVT_NOTEBOOK_PAGE_CHANGING
  handler and not the page which is going to be selected.

Bummer. So I can't use EVT_NOTEBOOK_PAGE_CHANGING.

Next I tried hooking up a EVT_PAINT event for the panel which is on the
notebook page. I thought, I could "deadvance" the user to the previous
page depending on whether he entered something or not. So, I did in the
event:

if self.DateiName is None:
        # Nothing has been entered yet
        # Go back to previous page
        self.Notebook.AdvanceSelection(false)

But this results in funny results, but certainly the selection (shown
page) is not always advanced to the previous page. Sometimes it's two
pages backward, sometimes one. The same happens, when I exchange
AdvanceSelection with:

        self.Notebook.SetSelection(self.Notebook.GetSelection() - 1)

I suppose, I'm sometimes de-advanced two pages, because the EVT_PAINT is
called twice, even if GetSelection() already returns the previous page.

Next I tried to hook this all up into EVT_NOTEBOOK_PAGE_CHANGED. But
there, AdvanceSelection() and SetSelection() doesn't seem to do anything
at all. The page does not change.

Well, I'm now out of ideas. How can I deny changing the page *TO* a
certain page in a consistent way which will also work on Windows?

Alexander Skwar

···

--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.iso-top.de | Jabber: askwar@a-message.de
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
                       Uptime: 15 hours 7 minutes

Alexander Skwar wrote:

In my program I've a wxNotebook containing some pages. A certain page
should only be accessible, when the user entered something on the
previous page.

I would take a slightly different approach to this problem. Instead of
preventing the notebook page from being shown, allow them to access the page --
but make everything on the page inactive unless your specific flag is set.
They'll be able to see the page, but everything will be "greyed out", until
they've met the specific conditions.

Not only would this be easier to code, it'll also be less likely to
confuse/frustrate your users, who could be left wondering why clicking on a
particular notebook tab does nothing...

Jeff Shannon
Technician/Programmer
Credit International

»Jeff Shannon« sagte am 2002-04-22 um 16:06:56 -0700 :

They'll be able to see the page, but everything will be "greyed out", until
they've met the specific conditions.

Hmm, yes, and maybe also add a small staticText telling why everything
is greyed out. Makes sense, and I'll do it this way. Thanks!

But I'd still like to know how to prevent changing *to* a given page.
Changing *from* a given page is easy with all those events.
Particularly, I'm interested why the EVT_PAINT event behaves so
strangely.

Oh, and another question: Can I somehow disable/grey out a notebook
page, so that they can't even click on it? Or, if that's not possible,
can I at least change the text color of a "label"?

Thanks again,

Alexander Skwar

···

--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.iso-top.de | Jabber: askwar@a-message.de
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
                       Uptime: 16 hours 28 minutes

  wxNotebookEvent::GetSelection
  int GetSelection() const
  Returns the currently selected page, or -1 if none was selected.
  NB: under Windows, GetSelection() will return the same value as
  GetOldSelection() when called from EVT_NOTEBOOK_PAGE_CHANGING
  handler and not the page which is going to be selected.

Bummer. So I can't use EVT_NOTEBOOK_PAGE_CHANGING.

Next I tried hooking up a EVT_PAINT event for the panel which is on
the notebook page. I thought, I could "deadvance" the user to the
previous page depending on whether he entered something or not. So,
I did in the event:

You can do this by catching the EVT_NOTEBOOK_CHANGED and then change the
pack back to the event.GetOldSelection() page.

···

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

»Robin Dunn« sagte am 2002-04-23 um 09:47:07 -0700 :

You can do this by catching the EVT_NOTEBOOK_CHANGED and then change the
pack back to the event.GetOldSelection() page.

As I said, doing a noteBook.SetSelection() didn't do anything in this
event. Even when I hardcoded a destination page with SetSelection(0).

Alexander Skwar

···

--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.iso-top.de | Jabber: askwar@a-message.de
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
                       Uptime: 12 hours 43 minutes

�Robin Dunn� sagte am 2002-04-23 um 09:47:07 -0700 :
> You can do this by catching the EVT_NOTEBOOK_CHANGED and then change the
> pack back to the event.GetOldSelection() page.

As I said, doing a noteBook.SetSelection() didn't do anything in this
event. Even when I hardcoded a destination page with SetSelection(0).

Oh, right. In that case you can still catch the _CHANGED event and then set
a flag specifyin the page to change back to. Then add an IDLE handler that
checks the flag and changes the page if needed. Most of the time it will
appear as quick as changing it in the _CHANGED handler, but as previously
discussed it is probably better from a user-friendlyness perspective to just
disable the controls on that page anyway.

···

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