Hi Mattia,

Do you know anything about this?

-------- Original Message --------
Subject:        wxlistbox Broken
Date:   Wed, 21 Jul 2010 07:11:40 -0400
From:   perltk <per...@maine.rr.com>
To:     wxperl-users@perl.org



So has anyone else seen this ?
Is there a work around ?


On 7/20/2010 7:47 AM, perltk wrote:
 Is wxlistbox broken on Linux for wxLB_SINGLE ?

 If I change wxLB_SINGLE to wxLB_EXTENDED works fine.

 Tried the same experiment on a example code from web and it breaks
 that code as well. :
 This wxperl on Linux
 ------- cut here ---------

 #!/usr/bin/perl -w
 use strict;

 use Wx;

 package ListBoxSelection;
 use Wx qw[:everything];
 use base 'Wx::App';
 use Wx::Event qw(EVT_LISTBOX);

 my $listbox1;
 my $listbox2;

 sub OnInit
 {
     my $self = shift;

     my $frame = Wx::Frame->new( undef, -1, 'Wx::ListBox selection
 example');
     my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);

     $listbox1 = Wx::ListBox->new($frame, -1, wxDefaultPosition,
 wxDefaultSize,
         [ 'This', 'is one of my', 'really', 'wonderful', 'examples', ],
         wxLB_SINGLE, wxDefaultValidator, 'listbox_1');

     $listbox2 = Wx::ListBox->new($frame, -1, wxDefaultPosition,
 wxDefaultSize,
         [ 1, 2, 3, 4, 5],
         wxLB_SINGLE, wxDefaultValidator, 'listbox_2');

     EVT_LISTBOX($self, $listbox1, sub { $self->on_listbox($listbox1,
 $_[1]) } );
     EVT_LISTBOX($self, $listbox2, sub { $self->on_listbox($listbox2,
 $_[1]) } );

     $sizer->Add($listbox1, 1, wxEXPAND, 10);
     $sizer->Add($listbox2, 1, wxEXPAND, 10);
     $frame->SetSizerAndFit($sizer);
     $frame->Show( 1 );
 }

 sub on_listbox
 {
     my $self = shift;
     my $ctrl = shift;
     my $event = shift;

     print "-------------------------\n";
     my @choices = $ctrl->GetSelections();

     print "status-in  :\n";
     print "1: " . join (', ', $listbox1->GetSelections()) . "\n";
     print "2: " . join (', ', $listbox2->GetSelections()) . "\n";

     map { $listbox1->Deselect($_); } [0, 1, 2, 3, 4];
     $listbox2->SetSelection(wxNOT_FOUND);

     foreach my $choice (@choices)
     {
         $listbox1->Select($choice);
         $listbox2->Select($choice);
     }

     print "status-out  :\n";
     print "1: " . join (', ', $listbox1->GetSelections()) . "\n";
     print "2: " . join (', ', $listbox2->GetSelections()) . "\n";
 }


 package main;

 my $app = ListBoxSelection->new;
 $app->MainLoop;

 ------- cut here ---------





 On 7/20/2010 6:09 AM, perltk wrote:
 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









Reply via email to