f00860
f00860

Reputation: 3576

GtkBuilder does not realize widgets?

I have a simple Glade-file included in a C source. Here are the interesting parts:

int main(int argc, char *argv[]) {
  GtkBuilder *builder;
  gtk_init(&argc, &argv);

  gdk_gl_init(&argc, &argv);
  // ... some OpenGL specific initializations

  builder = gtk_builder_new();
  gtk_builder_add_from_file(builder, "gui.ui", NULL);
  gtk_builder_connect_signals(builder, NULL);

  window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
  drawingArea = GTK_wIDGET(gtk_builder_get_object(builder, "drawing_area"));


  gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
  gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
  // ...
}

If I compile this, I get this warning:

gtk_widget_set_gl_capability: assertion `!gtk_widget_get_realized (widget)' failed

If I now use LibGlade instead of the GtkBuilder with this code (I saved the glade file to be compatible with Libglade):

int main(int argc, char *argv[]) {
  GladeXML *xml;
  gtk_init(&argc, &argv);

  gdk_gl_init(&argc, &argv);
  // ... some OpenGL specific initializations

  xml = glade_xml_new("gui.glade", NULL, NULL);
  glade_xml_signal_autoconnect(xml);

  window = glade_xml_get_widget(xml, "main_window");
  drawingArea = glade_xml_get_widget(xml, "drawing_area");


  gtk_container_set_reallocate_redraws(GTK_CONTAINER(window), TRUE);
  gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE);
  // ...
}

All works fine and no error appear. I've tried several things to force the realize the drawing_area in the GtkBuilder version but nothing worked. Is there some magic trick that I forgot here?

Upvotes: 0

Views: 1306

Answers (1)

Roland Graham
Roland Graham

Reputation: 11

Set the Visible property of the top Window to False.

I have had the exact same problem for the last couple of weeks. A glade xml file that I converted from glade2 to glade3 that used gtkglext just would not accept the gtk_widget_set_gl_capability call. After I read this post and did a comparison with a functioning file (thanks to Jose Commins ) did I realize that the visible property on the top window was set to True. Change it to False, everything works. Since all the top windows in the old glade2 file were set to True, that must have been the default. The newer software sets it to False. Builder must initialize the top window when it is created and labeled as visible in contrast to the old C code practice of waiting until the create functions were explicitly called.

Upvotes: 1

Related Questions