Gtk2
view release on metacpan or search on metacpan
gtk-demo/appwindow.pl view on Meta::CPAN
# Close dialog on user response
$dialog->signal_connect (response => sub { $_[0]->destroy; 1 });
$dialog->show;
}
#
# This function registers our custom toolbar icons, so they can be themed.
#
# It's totally optional to do this, you could just manually insert icons
# and have them not be themeable, especially if you never expect people
# to theme your app.
#
my $registered = FALSE;
sub register_stock_icons {
if (!$registered) {
my @items = (
#[ "demo-gtk-logo", "_GTK!", 0, 0, undef ]
{
stock_id => "demo-gtk-logo",
label => "_GTK!",
},
);
$registered = TRUE;
# Register our stock items
Gtk2::Stock->add (@items);
# Add our custom icon factory to the list of defaults
my $factory = Gtk2::IconFactory->new;
$factory->add_default;
#
# demo_find_file() looks in the the current directory first,
# so you can run gtk-demo without installing GTK, then looks
# in the location where the file is installed.
#
my $pixbuf = undef;
### my $filename = demo_find_file ("gtk-logo-rgb.gif", undef);
my $filename = "gtk-logo-rgb.gif";
if ($filename) {
eval {
$pixbuf = Gtk2::Gdk::Pixbuf->new_from_file (
main::demo_find_file ($filename));
# The gtk-logo-rgb icon has a white background, make it transparent
my $transparent = $pixbuf->add_alpha (TRUE, 0xff, 0xff, 0xff);
my $icon_set = Gtk2::IconSet->new_from_pixbuf ($transparent);
$factory->add ("demo-gtk-logo", $icon_set);
};
warn "failed to load GTK logo for toolbar"
if $@;
}
# $factory goes out of scope here, but GTK will hold a reference on it.
}
}
sub update_statusbar {
my ($buffer, $statusbar) = @_;
$statusbar->pop (0); # clear any previous message, underflow is allowed
my $count = $buffer->get_char_count;
my $iter = $buffer->get_iter_at_mark ($buffer->get_insert);
my $row = $iter->get_line;
my $col = $iter->get_line_offset;
$statusbar->push (0, "Cursor at row $row column $col - $count chars in document");
}
sub mark_set_callback {
my ($buffer, $new_location, $mark, $data) = @_;
update_statusbar ($buffer, $data);
}
sub do {
if (!$window) {
register_stock_icons ();
#
# Create the toplevel window
#
$window = Gtk2::Window->new;
$window->set_title ("Application Window");
# NULL window variable when window is closed
$window->signal_connect (destroy => sub { $window = undef; 1 });
my $table = Gtk2::Table->new (1, 4, FALSE);
$window->add ($table);
#
# Create the menubar
#
my $accel_group = Gtk2::AccelGroup->new;
$window->add_accel_group ($accel_group);
my $item_factory = Gtk2::ItemFactory->new ("Gtk2::MenuBar", "<main>",
$accel_group);
# Set up item factory to go away with the window
$window->{'<main>'} = $item_factory;
# create menu items
$item_factory->create_items ($window, @menu_items);
$table->attach ($item_factory->get_widget ("<main>"),
# X direction Y direction
0, 1, 0, 1,
[qw/expand fill/], [],
0, 0);
( run in 2.745 seconds using v1.01-cache-2.11-cpan-98e64b0badf )