window resizing



Hello,

  I have a simple application, whose toplevel window has the following 
structure :

 +-VBox----------------------+
 |    [Image]                |
 +---------------------------+
 |+--HBox-------------------+|
 ||            [Next] [Quit]||
 |+-------------------------+|
 +---------------------------+

When it starts, it displays an image. Upon clicking on the 'Next'
button, another image is read and displayed.

When the second image displayed is larger than the first, everything
resizes nicely to accomodate. However, when the second image is smaller
than the first, the window does not shrink: [Image] has some empty
space on both sides, while the HBox has some empty space below. I can
manually resize (downsize) the window, but it would be nicer if it
would fit tightly to its content by itself. How do you ask GTK to
adopt this kind of behaviour?

Thank you very much for your help,

   laurent



----------------------------------------------------------------------------
#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Glib qw/TRUE FALSE/;


my $image = undef;
my $fig = 1;

#===== create window
my $window = Gtk2::Window->new ('toplevel');
$window->set_resizable( TRUE );
$window->signal_connect( delete_event => \&Quit );

#===== add widgets
GetImage( $fig );

my $next_btn = Gtk2::Button->new( 'Next' );
$next_btn->signal_connect( 'clicked', sub{ GetImage( ++$fig ); } );
my $close_btn = Gtk2::Button->new_from_stock( 'gtk-close' );
$close_btn->signal_connect( 'clicked'  , sub{ Gtk2->main_quit; } ) ; 

my $hbox = Gtk2::HBox->new( FALSE, 5 );
$hbox->pack_end( $close_btn, FALSE, TRUE, 5 );
$hbox->pack_end( $next_btn, FALSE, TRUE, 5 );

my $vbox = Gtk2::VBox->new(FALSE,0);
$vbox->pack_start( $image, FALSE, FALSE, 0 );
$vbox->pack_start( $hbox, FALSE, FALSE, 10 );

$window->add($vbox);
$window->set_position( 'center' );
$window->show_all;

Gtk2->main;


#================================================================================
sub GetImage
{
  my $id = shift;
  my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file( "fig${id}.png" );
  if ( defined $image ) {
    $image->clear;
    $image->set_from_pixbuf( $pixbuf );
  } else {
    $image = Gtk2::Image->new_from_pixbuf( $pixbuf );
  }
}




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