a bunch of questions about displaying jpegs



Hi,

I'm new to this list.  Sorry that I start by asking questions.  I'm
trying to use gtk-perl to display a few jpegs (consecutively) and add
comments to them.

After a lot of trying and searching the web I succeeded in displaying
a jpeg file, using ImlibImage.  I have heard that Pixbuf might be
better, but I don't know how that works.  I have attached some code at
the end, but basically I'm using:

    my $im = load_image Gtk::Gdk::ImlibImage($file);
    my $w = $im->rgb_width;
    my $h = $im->rgb_height;
    $im->render($w, $h);
    my $p = $im->move_image();
    my $m = $im->move_mask;
    $pixmapwid = new Gtk::Pixmap( $p, $m );
    $pixmapwid->show();
    $frame = new Gtk::Frame( "jpeg" );
    $frame->add($pixmapwid);

Questions:

1. How do I change the picture to another one?  The only way I
   succeeded in doing that was by destroying the frame and adding a
   new frame.  But that is not very elegant and also not feasible when
   the picture is somewhere deeply nested in widgets.

2. Is it better to use pixbuf instead of Imlib?  How does that work?

3. Is it better to use gtk2 instead of gtk?  At this moment I only
   care about getting the "job" done.  Finding documentation has been
   a little harder than I imagined.

4. How do I find out about all the methods that $pixmapwid (for
   instance) responds to.  I have been trying random names without
   much luck and I'm feeling quite stupid.

Thanks for taking the time to read this far ;-)

regards,
Richard

P.S. full code of program that displays jpeg:

#!/usr/bin/perl -w

use Gtk::Gdk::ImlibImage;
use Gtk; use strict;

init Gtk; set_locale Gtk;

my $file = shift or die "usage: supply name of jpeg picture\n";

my $false = 0; my $true = 1;
my $window; my $vbox; my $frame; my $label; my $pict; my $style;
my $pixmap; my $mask; my $pixmapwid;

    #########################
    # set up toplevel window
    #########################
$window = new Gtk::Window( "toplevel" );
$window->set_title( "toplevel-window" );
$vbox = new Gtk::VBox( $false, 5 );
$window->add( $vbox );
$window->border_width( 5 );
$window->signal_connect( "delete_event", sub { Gtk->exit(0); } );
$window->show();

    #########################
    # load picture
    #########################
my $im = load_image Gtk::Gdk::ImlibImage($file);
my $w = $im->rgb_width;
my $h = $im->rgb_height;
$im->render($w, $h);
my $p = $im->move_image();
my $m = $im->move_mask;

    #########################
    # set up pixmap and frame
    #########################
$pixmapwid = new Gtk::Pixmap( $p, $m );
$pixmapwid->show();
$frame = new Gtk::Frame( "jpeg" );
$frame->add($pixmapwid);
$vbox->pack_start( $frame, $false, $false, 0);

    #########################
    # show all
    #########################
$window->show_all();
Gtk->main_iteration while ( Gtk->events_pending );

main Gtk;
exit(0);




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