I was very upset and discouraged ... and when i was resigned to open and xpm image, load it to a pixmap, and then load it with the Gtk2::RcStyle as a background image ...
when i received your reply ...
The use of an XPM hardcoded into an array was like a deją vu ... I took my last breath and said i'm going to make the last effort ... and an hour after ... tachan!!!!!

I can load any image (jpeg, png ... and all those supported by the gdkPixbuf) to a background. Here is the code, modified from the one you submitted (i've only change the set_bg function ...)

#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $rc_style = Gtk2::RcStyle->new; $rc_style->bg_pixmap_name('normal', 'bunny.xpm'); my $window = Gtk2::Window->new('toplevel'); $window->set_title('Embed test'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(500,500); $window->modify_style ($rc_style); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $window->add($vbox); $vbox->set_border_width(2); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); $hbox->set_border_width(2); $vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); my $button1 = Gtk2::Button->new('Set BG'); $hbox->pack_end( $button1, FALSE, FALSE, 0 ); $button1->signal_connect( clicked => \&set_bg ); my $vbox1 = Gtk2::VBox->new( 0, 5 ); $vbox->pack_end ($vbox1, TRUE, TRUE, 0); my $btn = Gtk2::Button->new_from_stock('gtk-quit'); $btn->signal_connect( 'clicked' => \&delete_event ); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; } #### sub set_bg{ #### PNG & Pixbuff :-) my $values; my ($widget, $context, @other_params) = @_; my $colormap = $window->get_default_colormap; my $pixbuff = Gtk2::Gdk::Pixbuf->new_from_file("figure.png"); my $graphicContext = Gtk2::GC->get(Gtk2::Gdk::Visual->get_best_depth, $colormap, $values); $pixbuff->render_to_drawable($widget->get_parent_window, $graphicContext, 0,0,0,0,500,500,'normal',0,0); }

The conclusion, is:
In X11 programming, you can draw anything to any 'drawable' window (i'm not an expert, but this is correct), With the help of Gtk2::Widget::get_parent_window we obtain a Gtk2::Gdk::Window which is a Gtk2::Gdk::Drawable. Once we got a drawable window, i think we can do almost anything with it (low level :') ... and low docummented)

Okay, alls seems to be fine, but i have other problem now; how i obtain a Gtk2::Gdk::Window without waiting to the execution of the callback function? ... We need a kind of casting function!!!! ... Ideas?


Cheers
turo



(... thanks zentara!!! ...)

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

In reply to Re^2: Perl-Gtk2::How to set a window background image. by turo
in thread Perl-Gtk2::How to set a window background image. by turo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.