Glade tutorial

Glade XML file:

http://people.gnome.org/~newren/tutorials/developing-with-gnome/html/apb.html

Call Glade XML from C:

http://people.gnome.org/~newren/tutorials/developing-with-gnome/html/apc.html

Glade XML file

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">  <glade-interface> <requires lib="gnome"/>  <widget class="GtkDialog" id="MainWindow">   <property name="border_width">6</property>   <property name="visible">True</property>   <property name="title" translatable="yes">Useless Program</property>   <property name="type">GTK_WINDOW_TOPLEVEL</property>   <property name="window_position">GTK_WIN_POS_NONE</property>   <property name="modal">False</property>   <property name="resizable">False</property>   <property name="destroy_with_parent">False</property>   <property name="has_separator">False</property>   <signal name="delete_event" handler="gtk_main_quit" last_modification_time="Mon, 15 Mar 2004 23:13:27 GMT"/>    <child internal-child="vbox">     <widget class="GtkVBox" id="dialog-vbox">       <property name="visible">True</property>       <property name="homogeneous">False</property>       <property name="spacing">12</property>        <child internal-child="action_area"> <widget class="GtkHButtonBox" id="dialog-action_area">   <property name="visible">True</property>   <property name="layout_style">GTK_BUTTONBOX_END</property>    <child>     <widget class="GtkButton" id="OKButton">       <property name="visible">True</property>       <property name="can_default">True</property>       <property name="can_focus">True</property>       <property name="label">gtk-ok</property>       <property name="use_stock">True</property>       <property name="relief">GTK_RELIEF_NORMAL</property>       <property name="response_id">-5</property>       <signal name="clicked" handler="ok_button_clicked" last_modification_time="Mon, 15 Mar 2004 23:14:00 GMT"/>     </widget>   </child> </widget> <packing>   <property name="padding">0</property>   <property name="expand">False</property>   <property name="fill">True</property>   <property name="pack_type">GTK_PACK_END</property> </packing>       </child>        <child> <widget class="GtkHBox" id="InfoBox">   <property name="border_width">6</property>   <property name="visible">True</property>   <property name="homogeneous">False</property>   <property name="spacing">12</property>    <child>     <widget class="GtkImage" id="InfoImage">       <property name="visible">True</property>       <property name="stock">gtk-dialog-warning</property>       <property name="icon_size">6</property>       <property name="xalign">0.5</property>       <property name="yalign">0</property>       <property name="xpad">0</property>       <property name="ypad">0</property>     </widget>     <packing>       <property name="padding">0</property>       <property name="expand">False</property>       <property name="fill">False</property>     </packing>   </child>    <child>     <widget class="GtkLabel" id="InfoLabel">       <property name="visible">True</property>       <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot; size=&quot;larger&quot;&gt;This program does nothing useful&lt;/span&gt;  No code has yet been added to this program to do anything other than display this short warning.  This program will now close.</property>       <property name="use_underline">False</property>       <property name="use_markup">True</property>       <property name="justify">GTK_JUSTIFY_LEFT</property>       <property name="wrap">True</property>       <property name="selectable">False</property>       <property name="xalign">0.5</property>       <property name="yalign">0.5</property>       <property name="xpad">0</property>       <property name="ypad">0</property>     </widget>     <packing>       <property name="padding">0</property>       <property name="expand">False</property>       <property name="fill">False</property>     </packing>   </child> </widget> <packing>   <property name="padding">0</property>   <property name="expand">False</property>   <property name="fill">False</property> </packing>       </child>     </widget>   </child> </widget>  </glade-interface>

C file

/* This program displays a simple window and has a simple callback for

 * when the OK button is clicked.

 */

#include <gtk/gtk.h>

#include <glade/glade.h>

void

ok_button_clicked (GtkWidget *widget, gpointer user_data)

{

  printf ("Thanks for trying out my program.\n");

  gtk_main_quit ();

}

int

main (int argc, char *argv[])

{

  GladeXML  *main_window;

  GtkWidget *widget;

  gtk_init (&argc, &argv);

  /* load the interface */

  main_window = glade_xml_new ("../example-1.glade", NULL, NULL);

  /* connect the signals in the interface */

  /* Have the ok button call the ok_button_clicked callback */

  widget = glade_xml_get_widget (main_window, "OKButton");

  g_signal_connect (G_OBJECT (widget), "clicked",

                    G_CALLBACK (ok_button_clicked),

                    NULL);

  /* Have the delete event (window close) end the program */

  widget = glade_xml_get_widget (main_window, "MainWindow");

  g_signal_connect (G_OBJECT (widget), "delete_event",

                    G_CALLBACK (gtk_main_quit), NULL);

  /* start the event loop */

  gtk_main ();

  return 0;

}