A GNOME program is a GTK+ GUI application, which makes use of the GNOME libraries. The GNOME libraries make it possible to have similar look and feel among applications, and to make simple things, simple to program. Plus the GNOME libraries add a whole bunch of widgets that simply don't fit into GTK+.
The following program creates a basic gnome window and adds a horizontal box into which it packs two buttons, which (when pressed) print a string onto the stdout of the terminal you started the application from.
/*
* A simple Gnome program, outside of GNOME tree, not using i18n
* buttons.c
*/
/* the very basic gnome include */
#include <gnome.h>
/* a callback for the buttons */
static void
button_clicked(GtkWidget *button, gpointer data)
{
/* the string to print is passed though the data field
(which is a void *) */
char *string = data;
/* print a string on the standard output */
g_print(string);
}
int
main(int argc, char *argv[])
{
GtkWidget *app;
GtkWidget *button;
GtkWidget *hbox;
/* Initialize GNOME, this is very similar to gtk_init */
gnome_init ("buttons-basic-example", "0.1", argc, argv);
/* Create a Gnome app widget, which sets up a basic window
for your application */
app = gnome_app_new ("buttons-basic-example",
"Basic GNOME Application");
/* bind "delete_event", which is the event we get when
the user closes the window with the window manager,
to gtk_main_quit, which is a function that causes
the gtk_main loop to exit, and consequently to quit
the application */
gtk_signal_connect (GTK_OBJECT (app), "delete_event",
GTK_SIGNAL_FUNC (gtk_main_quit),
NULL);
/* create a horizontal box for the buttons and add it
into the app widget */
hbox = gtk_hbox_new (FALSE,5);
gnome_app_set_contents (GNOME_APP (app), hbox);
/* make a button and add it into the horizontal box,
and bind the clicked event to call button_clicked */
button = gtk_button_new_with_label("Button 1");
gtk_box_pack_start (GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (button_clicked),
"Button 1\\n");
/* and another button */
button = gtk_button_new_with_label("Button 2");
gtk_box_pack_start (GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (button_clicked),
"Button 2\\n");
/* show everything inside this app widget and the app
widget itself */
gtk_widget_show_all(app);
/* enter the main loop */
gtk_main ();
return 0;
} |
Please note the use of gnome_init instead of gtk_init, and GnomeApp widget instead of just a regular GtkWindow. We will go into detail of these later.