PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : simples Perl GTK Fenster



marcdevil
05-12-2002, 14:58
hi

ich möchte ein Fenster mit einem Bild und einer Statusleiste, die in 10 Sekunden von 0 auf 100 % geht. Wie realisiere ich das mit Perl & Perl::GTK ?

ciao

marcdevil
11-12-2002, 12:42
#!/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 :)

the_brain
10-02-2003, 13:34
hi@all

ich suche ein gutes - am besten auch gleich deutsches - tutorial zu gtk in verbindung mit perl. oder beispiele, an denen man sich langhangeln kann.
die gesagt, alles auf perl-basis.

desweiteren suche ich noch ein gutes gtk-buch (wenns geht auch wieder perl) allerdings finde ich da auch nichts. schon mehrere büchereien abgeklappert. usw.

für tips und hinweise wäre ich echt dankbar.

tkortkamp
10-02-2003, 19:06
Original geschrieben von the_brain
hi@all

ich suche ein gutes - am besten auch gleich deutsches - tutorial zu gtk in verbindung mit perl. oder beispiele, an denen man sich langhangeln kann.
die gesagt, alles auf perl-basis.

desweiteren suche ich noch ein gutes gtk-buch (wenns geht auch wieder perl) allerdings finde ich da auch nichts. schon mehrere büchereien abgeklappert. usw.

für tips und hinweise wäre ich echt dankbar.
Hi!

Ich kenn jetzt kein Buch über gtk und perl, aber unter http://developer.gnome.org/doc/GGAD/ findest du ein ebook über Gtk+/Gnome in Verbindung mit C (die Befehle ähneln sich ja im Prinzip schon ziemlich).

Ich hab hier auch nur ein englisches Gtk-Perl Tutorial für dich: http://personal.riverusers.com/~swilhelm/gtkperl-tutorial/

c ya,
Tobias

the_brain
11-02-2003, 08:48
schönen dank, werd mir das mal anschauen.