Re: Help starting with gtk

Alex King <> writes:

> I'm just starting programming with GTK/GDK and I'm struggling with the
> lack of docs.  I have a Debian system with GTK 1.0.1.  I'm new to x
> programming.
> I'll include the test program I'm working with - it compiles without
> warnings but gives errors when run on my setup.  The program was pulled
> together from bits of the faq and tutorial - I want to be able to draw
> different shapes in different colours on the window every 1/2 second, but
> I cant get past the warnings eg. 
> ** WARNING **: file gdkgc.c: line 43 (gdk_gc_new_with_values): "window !=
> ** WARNING **: file gdkgc.c: line 375 (gdk_gc_set_foreground): "gc !=
> ** WARNING **: file gdkdraw.c: line 117 (gdk_draw_arc): "gc != NULL"

All of these warnings come from one thing:

>   gtk_drawing_area_size(GTK_DRAWING_AREA(data.area),100,100);
>   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
>                       GTK_SIGNAL_FUNC (delete_event), NULL);
>   gtk_window_set_title (GTK_WINDOW (window), "Adding Program");
>   gtk_container_add(GTK_CONTAINER(window),data.area);
>   data.gc=gdk_gc_new(data.area->window);

At this call, data.area->window is currently NULL. The window for the
drawing area won't normally be created until you show the toplevel

You can force this "realization" by adding immediately before:

 gtk_widget_realize (data.area);

The other approach is to, in you callback, do something like

 /* To be safe, check that the window is realized at this point */
 if (!GTK_WIDGET_REALIZED (data.area)) 
   return TRUE;

 if (!data.gc)
     data.gc = ....


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