I believe this is known behaviour. From http://docs.wxwidgets.org/stable/wx_wxnotebookevent.html#wxnotebookeventgetselection :
*"NB:* under Windows, GetSelection() will return the same value as GetOldSelection()<http://docs.wxwidgets.org/stable/wx_wxnotebookevent.html#wxnotebookeventgetoldselection>when called from EVT_NOTEBOOK_PAGE_CHANGING handler and not the page which is going to be selected. Also note that the values of selection and old selection returned for an event generated in response to a call to wxNotebook::SetSelection<http://docs.wxwidgets.org/stable/wx_wxnotebook.html#wxnotebooksetselection>shouldn't be trusted as they are currently inconsistent under different platforms (but in this case you presumably don't need them anyhow as you already have the corresponding information)." The only way I know to achieve this cross platform is to use EVT_NOTEBOOK_PAGE_CHANGED. You can use $event->GetOldSelection to see what the "previous" tab was and GetSelection to see the current tab. Instead of a Veto, you would need to call SetSelection to move back to the previous tab. Hope that helps, Brad On 1 December 2011 10:05, Bruce Ravel <bra...@bnl.gov> wrote: > > Hi, > > I am surprised by a bit of behavior by a Notebook on my windows > machines. The short script below distills the problem down to its > essence. > > I want to use the EVT_NOTEBOOK_PAGE_CHANGING event to veto the > selection of a tab under a certain situation. In this simple example, > I intend to veto the selection of tab #0. > > My intent is to recognize the newly selected tab using > $event->GetSelection. On my linux machine, this retuns the index of > the tab clicked on. Tab #2 is displayed on startup. Clicking on tab > #1, then on tab #0 does the following: > > bruce@dh10 [demeter] > perl nb.pl > old selection = 2, new selection = 1 > old selection = 1, new selection = 0 > > The second click is vetoed, since GetSelection returns 0. > > On my Windows machine (Wx 0.99, wxWidgets 2.8.12, WinXp, perl 5.12.3), > the following happens: > > C:\Documents and Settings\bravel\Desktop>perl nb.pl > old selection = 2, new selection = 2 > old selection = 1, new selection = 1 > old selection = 0, new selection = 0 > > Clicking on tab #1, $event->GetSelection returns 2 then displays tab > #1 and so on. > > In short, $event->GetSelection is returning the same value as > GetOldSelection on Windows. > > Ultimately, my goal is to veto a tab selection under a specified > condition. Is there another way of doing this that will work on both > platforms? > > Thanks in advance, > Bruce > > > > > #!/usr/bin/perl > package MyApp; > use base 'Wx::App'; > use Wx qw(:everything); > use Wx::Event qw(EVT_NOTEBOOK_PAGE_CHANGING); > > sub OnInit { > my $frame = Wx::Frame -> new(undef, -1, 'demo', [-1,-1], [700,150]); > my $sizer = Wx::BoxSizer->new(wxVERTICAL); > my $nb = Wx::Notebook->new( $frame, -1, wxDefaultPosition, wxDefaultSize, > wxNB_TOP ); > $sizer->Add($nb); > foreach my $i (0..2) { > my $panel = Wx::Panel->new($nb, -1, wxDefaultPosition, [500,100]); > $nb -> AddPage($panel, $i, $i); > }; > EVT_NOTEBOOK_PAGE_CHANGING($frame, $nb, > sub{ my($self, $event) = @_; > my ($selection) = $event->GetSelection; > my ($oldselection) = $event->GetOldSelection; > printf("old selection = %d, new selection = %d\n", > $oldselection, > $selection); > $event->Veto() if ($selection == 0); > return; > }); > > > $frame->SetSizer($sizer); > $frame -> Show(1); > 1; > }; > package main; > use Wx qw(:everything); > my $app = MyApp->new->MainLoop; > > -- > > Bruce Ravel ------------------------------------ bra...@bnl.gov > > National Institute of Standards and Technology > Synchrotron Methods Group at NSLS --- Beamlines U7A, X24A, X23A2 > Building 535A > Upton NY, 11973 > > My homepage: http://xafs.org/BruceRavel > EXAFS software: http://cars9.uchicago.edu/ifeffit/Demeter > -- Brad Embree email: b...@donor.com phone: 877-751-3300 x429 <http://brad.donor.com>