Code:
#!/usr/local/bin/perl -w
use Gtk;
use strict;
set_locale Gtk;
init Gtk;
my $false = 0;
my $true = 1;
my $window;
my $box;
my $button;
my $pbar;
my $timer;
my $align;
my $adj;
my $check1;
my $check2;
my $vbox;
my $vbox2;
# Create the window
$window = new Gtk::Window( "toplevel" );
$window->set_title( "Loading" );
$window->border_width( 10 );
$window->realize();
$window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );
$window->signal_connect( "delete_event", sub { Gtk->exit( 0 ); } );
$vbox = new Gtk::VBox( $false, 5 );
$vbox->border_width( 10 );
$window->add( $vbox );
$vbox->show();
# Create a centering alignment object
$align = new Gtk::Alignment( 0.5, 0.5, 0, 0 );
$vbox->pack_start( $align, $false, $false, 5 );
$align->show();
# Create a Adjusment object to hold the range of the progress bar
$adj = new Gtk::Adjustment( 0, 1, 150, 0, 0, 0 );
# Create the GtkProgressBar using the adjustment
$pbar = new_with_adjustment Gtk::ProgressBar( $adj );
# Set the format of the string that can be displayed in the
# trough of the progress bar:
# %p - percentage
# %v - value
# %l - lower range value
# %u - upper range value
$pbar->set_format_string( "%v from [%l-%u] (=%p%%)" );
$align->add( $pbar );
$pbar->show();
# Add a timer callback to update the value of the progress bar
$timer = Gtk->timeout_add( 100, \&progress_timeout );
# Add a button
$button = new Gtk::Button();
$box = xpm_label_box( $window, "/usr/local/share/pixmaps/b.xpm", "" );
$vbox->pack_start( $button, $false, $false, 0 );
$box->show();
$button->add( $box );
$button->show();
$window->add( $button );
$window->show();
alarm(10);
main Gtk;
exit( 0 );
sub progress_timeout
{
my ( $widget ) = @_;
my $new_val;
my $adj;
# Calculate the value of the progress bar using the
# value range set in the adjustment object
$new_val = $pbar->get_value() + 2;
$adj = $pbar->adjustment;
$new_val = $adj->lower if ( $new_val > $adj->upper );
# Set the new value
$pbar->set_value( $new_val );
# As this is a timeout function, return TRUE so that it
# continues to get called
return ( $true );
}
# Create a new hbox with an image and a label packed into it
# and return the box.
sub xpm_label_box
{
my ( $parent, $xpm_filename, $label_text ) = @_;
my $box;
my $style;
my $pixmap;
my $mask;
my $pixmapwid;
my $label;
# Create box for xpm and label
$box = new Gtk::HBox( $false, 0 );
# Get the style of the button to get the background color.
$style = $parent->get_style()->bg( 'normal' );
# Now on to the xpm stuff
( $pixmap, $mask ) = Gtk::Gdk::Pixmap->create_from_xpm( $parent->window,
$style,
$xpm_filename );
$pixmapwid = new Gtk::Pixmap( $pixmap, $mask );
# Create a label for the button
$label = new Gtk::Label( $label_text );
# Pack the pixmap and label into the box
$box->pack_start( $pixmapwid, $false, $false, 3 );
$box->pack_start( $label, $false, $false, 3 );
$box->border_width( 2 );
$pixmapwid->show();
$label->show();
return ( $box );
}
kann sein, das aus dem Muster noch codebestandteile zuviel drin sind, aber es tuts nun
Lesezeichen