Heres a very simple example of the offending code. If you select any
listbox item, EXCEPT the first, you will get 2 events and 2 callbacks -
the first one with index 0 selected and the second with whatever index
you actually selected.
If anyone see something wrong with code please tell me. Thanks.
Jeff
--------------------------------------------------------- CUT
---------------------------------------------
#!/usr/bin/perl -w
use Wx;
use strict;
my %widgets;
my %event;
#######################################
#
package MyFrame;
#
#######################################
use base 'Wx::Frame';
use Wx qw/:everything/;
sub new {
############################################
# Top Level Frame:
my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_;
$parent = undef unless defined $parent;
$id = -1 unless defined $id;
$title = "" unless defined $title;
$pos = [50,50] unless defined $pos;
$size = [765,800] unless defined $size;
$style = wxDOUBLE_BORDER|wxDEFAULT_FRAME_STYLE unless defined $style;
$name = "" unless defined $name;
my( $this ) = $self->SUPER::new( $parent, $id, $title, $pos, $size,
$style, $name );
############################################
$this->{itemBoxSizer2} = Wx::BoxSizer->new( wxVERTICAL );
$widgets{wxBoxSizer}{itemBoxSizer2}=$this->{itemBoxSizer2};
$this->SetSizer($this->{itemBoxSizer2});
$this->{ID_PANEL} = Wx::Panel->new( $this, -1, wxDefaultPosition,
Wx::Size->new(300, 300), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
$widgets{wxPanel}{ID_PANEL}=$this->{ID_PANEL};
$this->{itemBoxSizer2}->Add($this->{ID_PANEL}, 1, wxGROW|wxALL, 5 );
$this->{itemBoxSizer4} = Wx::BoxSizer->new( wxHORIZONTAL );
$widgets{wxBoxSizer}{itemBoxSizer4}=$this->{itemBoxSizer4};
$this->{ID_PANEL}->SetSizer($this->{itemBoxSizer4});
my @itemListBox5Strings;
$this->{ID_LISTBOX1} = Wx::ListBox->new( $this->{ID_PANEL}, -1,
wxDefaultPosition, wxDefaultSize, \...@itemlistbox5strings,
wxLB_SINGLE );
$widgets{wxListBox}{ID_LISTBOX1}=$this->{ID_LISTBOX1};
$this->{itemBoxSizer4}->Add($this->{ID_LISTBOX1}, 2, wxGROW|wxALL, 30 );
Wx::Event::EVT_LISTBOX($this, $this->{ID_LISTBOX1}, sub {
my $sid =
$widgets{wxListBox}{ID_LISTBOX1}->GetString($widgets{wxListBox}{ID_LISTBOX1}->GetSelections());
print $sid," \n";
}
);
my $list = [1,2,3,4,5,6];
$this->{ID_LISTBOX1}->InsertItems($list,0);
return $this
}
#######################################
#
package MyApp;
#
#######################################
use base 'Wx::App';
use vars qw(@ISA );
our @ISA = qw(Wx::App);
#######################################
#
#######################################
sub OnInit {
my( $frame ) = MyFrame->new(undef, -1);
$frame->Show(1);
$frame->SetTitle("TEST");
return 1;
}
#######################################
#
#######################################
#######################################
#
package main;
#
#######################################
my( $app ) = MyApp->new();
$app->MainLoop();
__END__
On 7/19/2010 10:43 PM, perltk wrote:
I'm subclassing the listbox and now whenever the listbox subclass is
first instantiated the first - and only the first click fire the event
twice.
The first event fires and the call back executes the GetSelections
method which always returns the 0 index in the listbox regardless of
which item was actually selected. The second event works as expected
and GetSelections returns the index actually selected. Whats even
stranger is if the actual selected index is 0 there is only one event
and works as expected.
After that the listbox works as expected.
Any ideas ?
Jeff