Re: gtk-perl tutorial and help



Thanks Scott

I fumbled my way through and realised it was not 'realized'!!
Your explanation certainly helps - thanks for your time

Regards

Andy

On Mon, 2003-01-20 at 14:03, muppet wrote:

Andy Ford wrote:

When I run this, I get the following error message...

'window is not of type Gtk::Gdk::Window '

The error message was generated from the code..
....create_from_xpm_d( $window->window,$style,@xpm_data );


in order to use a GdkWindow, the GdkWindow must exist.  the GdkWindow 
corresponds exactly to the actual XWindow, which doesn't exist on the X 
server until the XWindow has been created or "realized"; you typically 
realize a GtkWidget's GdkWindow by calling gtk_widget_show -- which 
calls XMapWindow.

however, while calling show on a child window marks it to be shown with 
the parent, calling show on  a toplevel (as you are doing) causes the 
whole thing to show up right then ---- since you aren't finished setting 
it up, this causes unwanted layouts and freaky visual nastiness.

to force the creation of the GdkWindow without putting the window on the 
screen yet, you must "realize" the widget separately before showing it 
by calling gtk_widget_realize (normally gtk_widget_show calls 
gtk_widget_realize for you).[1]

$window = new Gtk::Window( 'toplevel' );
$style = $window->get_style()->bg( 'normal' );

$window->realize;

($pixmap, $mask ) = Gtk::Gdk::Pixmap->create_from_xpm_d(
$window->window,$style,@xpm_data );


now $window->window is valid to use.


another alternative is to create the pixmap without a window, using 
gdk_pixmap_colormap_create_from_xpm_d, a la

($pixmap, $mask) = new Gtk::Gdk::Pixmap::colormap_create_from_xpm_d ( 
undef, $window->get_colormap, $style, @xpm_data );

note the fact that we're using a colormap rather than a GdkWindow as the 
reference drawable.  this allows you to do complete setup of your window 
hierarchy *before* the window is realized.  (in fact, you don't have to 
call realize.  :-)

[1] for a little more correct explanation of realizing, mapping, and 
showing, see the GGAD: 
http://developer.gnome.org/doc/GGAD/z57.html#SEC-REALIZINGSHOWING




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