Re: button children!!

On Tue, 2003-01-28 at 05:39, Andy Ford wrote:
If I do a $button_hbox->children();
and print out the result, I get a value of '2' !!!!

Any suggestions as to which method I could use to do this??

actually, i would suggest a different approach altogether.

instead of trying to walk the widget hierarchy to find the label and
pixmap you want to change, try storing pointers to them in the button
widget itself.

you can use either the object's user data or just make custom keys in
the hash.

$button = Gtk::Button->new;
$hbox = Gtk::HBox->new;
$pixmap = ...
$label = ...
$button->add ( $hbox );
$hbox->pack_start ( $pixmap, ... );
$hbox->pack_start ( $label, ... );

# store important data pointers directly in the widget's data 
# structure so we always have access to them.
$button->{pixmap} = $pixmap;
$button->{label} = $label;

$button->signal_connect ( clicked => sub {
                                my $bn = shift;
                                my $pixmap = $bn->{pixmap};
                                my $label = $bn->{label};
                        } );

and even yet another approach would be to pass the values to the

$button->signal_connect ( clicked => sub {
                                my $bn = shift;
                                my $data = shift;
                                my $label = $data->{label};
                                my $pixmap = $data->{pixmap};
                        }, { pixmap => $pixmap, label => $label } );

muppet <scott asofyet org>

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