gtk-perl bug, bad programming, or other?



Hello...

I was creating a small Gtk app with perl and ran into what I think is a bug in gtk-perl.  Or am I just doing this wrong?. I was looping through an array to create a bunch of buttons and ran into weird problems using signal_connect.  I created a test case that creates six buttons to show this. I'm using Fedora linux 22 on intel with all updates. I also tested with both Gtk2 and Gtk3.


resulting output:

$ ./test.pl 
get_label for button[0] is:  five 
get_label for button[1] is:  1 
get_label for button[2] is:  2 
get_label for button[three] is:  five 
get_label for button[four] is:  five 
get_label for button[five] is:  five 


code:

$ cat test.pl 
#!/usr/bin/perl

use Gtk2 -init;

my $window = Gtk2::Window->new ("toplevel");

my $layout = Gtk2::Layout->new(undef,undef);
$window->add ($layout);

my $vbox = Gtk2::VBox->new();
$layout->add($vbox);

my @button;

$button[0]=Gtk2::Button->new("0");
$vbox->add($button[0]);
$button[0]->signal_connect (clicked => sub {
   # Should output 0 , but does not
   print "get_label for button[0] is:  ".$button[0]->get_label." \n";
   }
);

$button[1]=Gtk2::Button->new("1");
$vbox->add($button[1]);
$button[1]->signal_connect (clicked => sub {
   # Should output 1
   print "get_label for button[1] is:  ".$button[1]->get_label." \n";
   }
);

$button[2]=Gtk2::Button->new("2");
$vbox->add($button[2]);
$button[2]->signal_connect (clicked => sub {
   # Should output 2
   print "get_label for button[2] is:  ".$button[2]->get_label." \n";
   }
);

$button["three"]=Gtk2::Button->new("three");
$vbox->add($button["three"]);
$button["three"]->signal_connect (clicked => sub {
   # Should output three , but does not
   print "get_label for button[three] is:  ".$button["three"]->get_label." \n";
   }
);

# No quotes
$button[four]=Gtk2::Button->new(four);
$vbox->add($button[four]);
$button[four]->signal_connect (clicked => sub {
   # Should output four , but does not
   print "get_label for button[four] is:  ".$button[four]->get_label." \n";
   }
);

$button["five"]=Gtk2::Button->new("five");
$vbox->add($button["five"]);
$button["five"]->signal_connect (clicked => sub {
   # Should output five
   print "get_label for button[five] is:  ".$button["five"]->get_label." \n";
   }
);

$window->show_all;
Gtk2->main;

exit 0;




--
Christopher McCrory
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]