#!/usr/bin/perl use strict; use diagnostics; use warnings; use Gtk2 '-init'; use Glib qw(TRUE FALSE); use Gnome2::Canvas; # Draw a Gtk2 window my $window = Gtk2::Window->new(); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_default_size(500, 500); $window->set_border_width(5); my $vBox = Gtk2::VBox->new(FALSE, 0); $window->add($vBox); # Draw a Gtk2::Frame containing a Gnome2::Canvas # The frame should be as long as possible, but only 50 pixels high my $frameHeight = 50; my $frame = Gtk2::Frame->new(undef); $frame->set_border_width(0); $frame->set_size_request(-1, $frameHeight); my $canvas = Gnome2::Canvas->new(); # (This line appears to move the canvas to the top-left corner of # the frame) $canvas->set_center_scroll_region(FALSE); $frame->add($canvas); $vBox->pack_start($frame, FALSE, FALSE, 0); # Draw a red bar, almost as long as the frame, but with a fixed height my ($width, $height) = $canvas->get_size(); my $rect = Gnome2::Canvas::Item->new( $canvas->root(), 'Gnome2::Canvas::Rect', x1 => 20, y1 => 20, x2 => ($width - 40), y2 => ($frameHeight - 20), fill_color => '#FF0000', outline_color => '#000000', ); $rect->raise_to_top(); $window->show_all(); Gtk2->main;