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