changing label in a gtk2 stock item
- From: zentara <zentara1 sbcglobal net>
- To: gtk-perl-list gnome org
- Subject: changing label in a gtk2 stock item
- Date: Sat, 26 Jan 2008 10:39:21 -0500
Hi,
Someone asked this on perlmonks, and I thought it would be easy.....
but not. :-)
They want to change just the Label of a button from stock_id.
I thought I could change the stock item's hash value for label,
and then use it. Bad thinking. Dosn't work.
I know how to make a custom stock_id with image with the
Item::Factory; but how do you modify an existing stock item?
Here is my unsuccessful attempt. First is a gtk-close button,
and I attempt to change the gtk-close label to 'hoo haa'.
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
use Data::Dumper;
# create a new window
my $window = Gtk2::Window->new('toplevel');
$window ->signal_connect( "destroy" => sub { Gtk2->main_quit; } );
my $vbox = Gtk2::VBox->new( FALSE, 0 );
$window->add($vbox);
$vbox->set_border_width(2);
my $stock_id = 'gtk-close';
my $id_ref = Gtk2::Stock->lookup ($stock_id);
print "$id_ref\n";
print $stock_id, "\n", Dumper (Gtk2::Stock->lookup ($stock_id)), "\n";
print $id_ref->{label}, "\n";
$id_ref->{label} = 'hoo haa';
print $id_ref->{label}, "\n";
print "\n", Dumper ( $id_ref), "\n";
# just guessing at this
Gtk2::Stock->set_translate_func ('gtk-close', 'label', 'hoo haa');
# guessing add a new entry to the stock system with our id
Gtk2::Stock->add (
{
stock_id => $id_ref,
label => 'hoo haa',
#modifier => [],
#keyval => $Gtk2::Gdk::Keysyms{L},
#translation_domain => 'gtk2-perl-example',
}
);
my $button1 = Gtk2::Button->new_from_stock('gtk-close');
# create a new button with a different label but acts like gtk-close
my $button = Gtk2::Button->new_from_stock($id_ref);
$button->signal_connect( "clicked" => \&callback, "cool button" );
$vbox->pack_start( $button1, FALSE, FALSE, 0 );
$vbox->pack_start( $button, FALSE, FALSE, 0 );
$window->show_all();
Gtk2->main;
##################################################
# our usual callback function
sub callback {
my $widget = shift;
my $data = shift;
printf "Hello again - %s was pressed\n", $data;
}
##################################################
__END__
Thanks, zentara
--
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]