Object +-- Widget +-- Container +-- Box +-- ButtonBox
Les boîtes de boutons sont un moyen pratique pour disposer rapidement d'un groupe de boutons. Elles existent sous forme horizontale ou verticale. Vous créez une nouvelle boîte de boutons avec l'un des appel suivant :
$button_box = new Gtk::HButtonBox(); $button_box = new Gtk::VButtonBox();
Les seuls attributs ayant un rapport avec les aspects des boîtes de boutons concernent la manière dont disposer les boutons.
$button_box->set_spacing_default( $spacing ); $button_box->get_spacing_default();
Le second attribut auquel vous avez accès agit sur la disposition des boutons à l'intérieur de la boîte.
$button_box->set_layout_default( $layout );
L'argument $layout peut prendre les valeurs suivantes :
'default_style' 'spread' 'edge' 'start' 'end'
La disposition courante peut être retrouvée par :
$button_box->get_layout_default();
Les boutons sont ajoutés par la fonction :
$button_box->add( $button );
Voici un exemple qui illustre les différentes valeurs de $layout dans une boîte de boutons.
#!/usr/bin/perl -wuse Gtk;
use strict;
init Gtk;
my $false = 0;
my $true = 1;
my $window;
my $main_vbox;
my $vbox;
my $hbox;
my $frame_horizontal;
my $frame_vertical;
$window = new Gtk::Window( "toplevel" );
$window->set_title( "Button Boxes" );
$window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );
$window->border_width( 10 );
$main_vbox = new Gtk::VBox( $false, 0 );
$window->add( $main_vbox );
$frame_horizontal = new Gtk::Frame( "Horizontal Button Boxes" );
$main_vbox->pack_start( $frame_horizontal, $true, $true, 10 );
$vbox = new Gtk::VBox( $false, 0 );
$vbox->border_width( 10 );
$frame_horizontal->add( $vbox );
$vbox->pack_start( create_bbox( $true, "Spread (spacing 30)", 30, 85, 20, 'spread' ), $true, $true, 0 );
$vbox->pack_start( create_bbox( $true, "Spread (spacing 40)", 40, 85, 20, 'spread' ), $true, $true, 0 );
$vbox->pack_start( create_bbox( $true, "Edge (spacing 30)", 30, 85, 20, 'edge' ), $true, $true, 5 );
$vbox->pack_start( create_bbox( $true, "Start (spacing 20)", 20, 85, 20, 'start' ), $true, $true, 5 );
$vbox->pack_start( create_bbox( $true, "End (spacing 10)", 10, 85, 20, 'end' ), $true, $true, 5 );
$frame_vertical = new Gtk::Frame( "Vertical Button Boxes" );
$main_vbox->pack_start( $frame_vertical, $true, $true, 10 );
$hbox = new Gtk::HBox( $false, 0 );
$hbox->border_width( 10 );
$frame_vertical->add( $hbox );
$hbox->pack_start( create_bbox( $false, "Spread (spacing 5)", 5, 85, 20, 'spread' ), $true, $true, 0 );
$hbox->pack_start( create_bbox( $false, "Edge (spacing 30)", 30, 85, 20, 'edge' ), $true, $true, 5 );
$hbox->pack_start( create_bbox( $false, "Start (spacing 20)", 20, 85, 20, 'start' ), $true, $true, 5 );
$hbox->pack_start( create_bbox( $false, "End (spacing 20)", 20, 85, 20, 'end' ), $true, $true, 5 );
$window->show_all();
main Gtk;
exit( 0 );
### Routines
# Crée une boîte de boutons avec des paramètres spécifiques.
sub create_bbox { my ( $horizontal, $title, $spacing, $child_w, $child_h, $layout ) = @_; my $frame; my $bbox; my $button; $frame = new Gtk::Frame( $title ); if ( $horizontal ) { $bbox = new Gtk::HButtonBox(); } else { $bbox = new Gtk::VButtonBox(); } $bbox->border_width( 5 ); $frame->add( $bbox ); # Set the appearance of the Button Box $bbox->set_layout( $layout ); $bbox->set_spacing( $spacing ); $bbox->set_child_size( $child_w, $child_h ); $button = new Gtk::Button( "OK" ); $bbox->add( $button ); $button = new Gtk::Button( "Cancel" ); $bbox->add( $button ); $button = new Gtk::Button( "Help" ); $bbox->add( $button ); return ( $frame ); }