GTK+ 2 Reference Manual |
---|
Since version 2.12, GTK+ provides GtkBuilder to construct user interfaces from XML descriptions, similar to the functionality provided by GladeXML in the libglade library.
A good way to start a migration from libglade to GtkBuilder is using
glade3 to convert your .glade file.
If your code uses the root
parameter of glade_xml_new()
,
you can use gtk_builder_add_objects_from_file()
to construct only certain
objects from a GtkBuilder file.
Alternatively, GTK+ also offers the gtk-builder-convert script you can use to do the conversion; in which case you should be careful to inspect the output and make sure you didn't lose any data.
Table 1. Step-by-step instructions for porting code from libglade to GtkBuilder
libglade | GtkBuilder |
---|---|
#include <glade/glade.h> | not needed |
GladeXML* |
GtkBuilder* |
glade_xml_new (FILE, "first_widget", NULL) |
GError* error = NULL; GtkBuilder* builder = gtk_builder_new (); if (!gtk_builder_add_from_file (builder, FILE, &error)) { g_warning ("Couldn't load builder file: %s", error->message); g_error_free (error); } |
glade_xml_get_widget (gxml, “widget_name”) |
GTK_WIDGET (gtk_builder_get_object (builder, “widget_name”)) |
glade_get_widget_name (widget) |
gtk_widget_get_name (widget) |
glade_xml_get_widget_prefix (gxml, “prefix”) |
can be emulated by gtk_builder_get_objects (builder) together with manual filtering. It returns a GSList* instead of a GList* though. |
While GtkBuilder strives to be a complete replacement for libglade, there are a number of areas where it is currently still behind libglade:
GtkBuilder supports context information in translatable properties in a slightly different way than libglade. Intltool does support this since version 0.41.1.
While libglade can often tolerate multiple widgets having the same id in a glade file, GtkBuilder will not accept duplicate object ids. Both gtk-builder-convert and the GtkBuilder parser emit warnings when they see duplicate ids.