Re: radioitem
- From: zentara <zentara zentara net>
- To: gtk-perl-list gnome org
- Subject: Re: radioitem
- Date: Wed, 20 Jul 2005 12:50:05 -0400
On Tue, 19 Jul 2005 12:00:33 -0400 (EDT)
Beast wrote:
Subject: radioitem
Any sample to use callback for <RadioItem>?
It will call both One and Two when togle the selection.
TIA
This is no match for muppet's and Torsten's solution, but
here is a way I got around the double signal. It seems pretty
"clunky" by comparison. But thats me...clunky. :-)
I post it just for jollies.
(Someone complained that if you hold the mouse button down and
drag to the other button, this will cause a bit of "reset havoc", but it
works pretty good for me.)
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(300,200);
my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);
my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);
$hbox->set_border_width(2);
$vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0);
my $button = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => \&delete_event );
my $value;
my $button1 = Gtk2::RadioButton->new(undef,"Radio Button 1");
my $but1_sigid = $button1->signal_connect(
"toggled" => sub { $value = "button1";
sighandler();
},
"Radio Button 1" );
$button1->signal_handler_block ($but1_sigid);
$vbox->pack_start($button1, TRUE, TRUE, 0);
$button1->set_active(TRUE);
$button1->show;
my @group = $button1->get_group;
my $button2 = Gtk2::RadioButton->new_with_label(@group,"Radio Button 2");
my $but2_sigid = $button2->signal_connect(
"toggled" => sub {$value = "button2";
sighandler();
},
"Radio Button 2" );
$button2->signal_handler_block ($but2_sigid);
$button1->signal_connect(
"enter" => sub { $button1->signal_handler_unblock ($but1_sigid) });
$button1->signal_connect(
"leave" => sub { $button1->signal_handler_block ($but1_sigid) });
$button2->signal_connect(
"enter" => sub { $button2->signal_handler_unblock ($but2_sigid) });
$button2->signal_connect(
"leave" => sub { $button2->signal_handler_block ($but2_sigid)});
$vbox->pack_start($button2, TRUE, TRUE, 0);
$button2->show;
$window->show_all();
Gtk2->main;
#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
########################################
sub sighandler {
print "value-> $value\n";
}
######################################
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]