Blob Blame History Raw
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Migrating from libglade to GtkBuilder: GTK+ 2 Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="GTK+ 2 Reference Manual">
<link rel="up" href="migrating.html" title="Part IV. Migrating from Previous Versions of GTK+">
<link rel="prev" href="gtk-migrating-GtkLinkButton.html" title="Migrating from GnomeHRef to GtkLinkButton">
<link rel="next" href="gtk-migrating-tooltips.html" title="Migrating from GtkTooltips to GtkTooltip">
<meta name="generator" content="GTK-Doc V1.26.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="migrating.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="gtk-migrating-GtkLinkButton.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="gtk-migrating-tooltips.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="gtk-migrating-GtkBuilder"></a>Migrating from libglade to GtkBuilder</h2></div></div></div>
<p>
    Since version 2.12, GTK+ provides <a class="link" href="GtkBuilder.html" title="GtkBuilder"><span class="type">GtkBuilder</span></a> to construct
    user interfaces from XML descriptions, similar to the functionality
    provided by <span class="type">GladeXML</span> in the libglade library.
  </p>
<p>
    A good way to start a migration from libglade to GtkBuilder is using
    <span class="application">glade3</span> to convert your .glade file.
    If your code uses the <em class="parameter"><code>root</code></em> parameter of <code class="function">glade_xml_new()</code>,
    you can use <a class="link" href="GtkBuilder.html#gtk-builder-add-objects-from-file" title="gtk_builder_add_objects_from_file ()"><code class="function">gtk_builder_add_objects_from_file()</code></a> to construct only certain
    objects from a GtkBuilder file.
  </p>
<p>
    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.
  </p>
<div class="table">
<a name="id-1.5.15.5"></a><p class="title"><b>Table 1. Step-by-step instructions for porting code from libglade to GtkBuilder</b></p>
<div class="table-contents"><table class="table" summary="Step-by-step instructions for porting code from libglade to GtkBuilder" width="100%" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>libglade</th>
<th>GtkBuilder</th>
</tr></thead>
<tbody>
<tr>
<td>#include &lt;glade/glade.h&gt;</td>
<td>not needed</td>
</tr>
<tr>
<td><pre class="screen">GladeXML*</pre></td>
<td><pre class="screen">GtkBuilder*</pre></td>
</tr>
<tr>
<td><pre class="screen">glade_xml_new (FILE, "first_widget", NULL)</pre></td>
<td>
<pre class="screen">
GError* error = NULL;
GtkBuilder* builder = gtk_builder_new ();
if (!gtk_builder_add_from_file (builder, FILE, &amp;error))
  {
    g_warning ("Couldn't load builder file: %s", error-&gt;message);
    g_error_free (error);
  }
</pre>
          </td>
</tr>
<tr>
<td><pre class="screen">glade_xml_get_widget (gxml, “widget_name”)</pre></td>
<td><pre class="screen">GTK_WIDGET (gtk_builder_get_object (builder, “widget_name”))</pre></td>
</tr>
<tr>
<td><pre class="screen">glade_get_widget_name (widget)</pre></td>
<td><pre class="screen">gtk_widget_get_name (widget)</pre></td>
</tr>
<tr>
<td><pre class="screen">glade_xml_get_widget_prefix (gxml, “prefix”)</pre></td>
<td>can be emulated by <code class="literal">gtk_builder_get_objects (builder)</code> together with manual filtering. It returns a GSList* instead of a GList* though.</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
    While GtkBuilder strives to be a complete replacement for
    libglade, there are a number of areas where it is currently
    still behind libglade:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
        GtkBuilder supports context information in translatable
        properties in a slightly different way than libglade.
        Intltool does support this since version 0.41.1.
      </p></li>
<li class="listitem"><p>
        While libglade can often tolerate multiple widgets having the
        same id in a glade file, GtkBuilder will not accept duplicate
        object ids. Both <span class="application">gtk-builder-convert</span>
        and the GtkBuilder parser emit warnings when they see
        duplicate ids.
      </p></li>
</ul></div>
<p>
  </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.26.1</div>
</body>
</html>