Re: [gtk2-perl-xs] pixmap



Phanatic said:
i have now a question. i looked this topic up in the old gtk-perl tutorial,
but i cannot get pixmaps into work ;(

i have an xpm file. how to get it shown in a window? please provide a code
snippet...


# you need a GdkWindow so that the xpm library knows with what type of visual
# the xpm data will be used...
my $gtkwindow = Gtk::Window->new ('toplevel');
# realize so that the GdkWindow exists
$gtkwindow->realize;

# now call create_from_xpm with the filename and that GdkWindow
my ($icon, $mask) = Gtk::Gdk::Pixmap->create_from_xpm ($gtkwindow->window,
$file);

# and then create a GtkPixmap to display it.
my $gtkpixmap = Gtk::Pixmap->new ($icon, $mask);

$gtkwindow->add ($gtkpixmap);
$gtkwindow->show_all;

# that's it!

that works with gtk-perl.  you didn't say which one you were working with, so
there.

there are other ways to trick it out so that you don't need to realize the
window first --- i think it's gdk_pixmap_colormap_create_from_xpm, but then
you need to supply the colormap from the widget into which you will place the
xpm.  fun, eh?


GtkPixmap is deprecated in Gtk+ 2.0.  so, in gtk2-perl, you'd use GtkImage
instead.

  my $image = Gtk2::Image->new_from_pixmap ($icon, $mask);

(new_from_pixmap will be in CVS later this afternoon.  oops.  but
set_from_pixmap is already in there, so you can create an empty GtkImage and
then set it.  i don't use GdkPixmaps anymore because GdkPixbuf is much nicer.)

haven't tried with gtk2-perl.

-- 
muppet <scott at asofyet dot org>





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