Glade FAQ

This is version 1.0 of the Glade FAQ.

Table of Contents
Glade FAQ

Glade FAQ

This is a list of the most frequently asked questions for the Glade GTK+/GNOME user interface builder.

1. General Information About Glade
1.1.
1.2.
1.3.
2. Creating A User Interface In Glade
2.1.
2.2.
2.3.
2.4.
2.5.
2.6.
2.7.
3. Building The C Code Generated By Glade
3.1.
3.2.
3.3.
4. Using The C Code Generated By Glade
4.1.

1. General Information About Glade

1.1.

What documentation is there for Glade?

In the GNOME version of Glade the Quick-Start Guide, Manual, and FAQ are available from the Help menu. Unfortunately these do not cover all aspects of using Glade yet.

There are a few other docs available on the web:

Spanish Guide - tigre.aragon.unam.mx/m3d/links_es.htm

Italian Guide - digilander.iol.it/robang/glade

I don't think there are any books specifically about Glade, though I have seen a chapter on Glade in a book from Wrox press for Linux developers.

I'll add links to documentation to Glade's home page at glade.pn.org as they become available.

1.2.

Is there any example code?

Glade includes a simple text editor example application in the examples/editor directory. If you have a binary-only package of Glade (e.g. an RPM), these files may possibly be installed in /usr/doc/glade-X.X.X. If you can't find it, download the Glade tarball from glade.pn.org.

The web site contains links to quite a few applications created using Glade. These may contain useful example code. See the 'Applications' page on glade.pn.org.

1.3.

Do I have to use a particular license for the C code generated by Glade?

No. You are free to use whatever license you like for the C code generated by Glade.

Though in the spirit of free software we do encourage you to use the GPL or LGPL licenses.

2. Creating A User Interface In Glade

2.1.

When I add a widget to a window, it fills the whole window and I can't add any other widgets.

This is not a bug in Glade! In GTK+ you use containers to lay out your widgets. The commonly-used containers are at the bottom of the main page on the palette. Try adding a vertical box to a window in Glade. Now add a table to one of the positions in the vertical box. Do you get the idea now?

If you really want to position widgets at specific coordinates, try the Fixed container. However, this isn't recommended since your windows/dialogs will not look good when resized, and if you translate the text in the labels and buttons into other languages they may not fit.

2.2.

How do I change the colors of a widget, e.g. make a label red?

You can use standard GTK+ rc files to set the colors & fonts of your widgets. If you turn on the 'Set Widget Names' project option in Glade, that may make it easier to refer to your widgets, as you can refer to them by name. See the GTK+ Resource Files documentation at developer.gnome.org/doc/API/gtk/index.html.

You can also change a widget's style within your code by calling gtk_widget_modify_style(), e.g.
  GdkColor red = { 0, 65535, 0, 0 };
  GtkRcStyle *rc_style = gtk_rc_style_new ();
  rc_style->fg[GTK_STATE_NORMAL] = red;
  rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_FG;
  gtk_widget_modify_style (widget, rc_style);
  gtk_rc_style_unref (rc_style);
      

2.3.

How do I add a pixmap to a button?

Create a button and select Remove Label from the popup menu. You can then add any widgets you like to the button, e.g. a horizontal box with a pixmap and a label inside it. (Glade may make this even easier in future.)

2.4.

How do I add several widgets of the same type in one go?

Hold the 'Control' key when you select the widget in the Palette. It will then stay selected until you select another widget or the Selector.

2.5.

I get this warning whenever I use a scrolled window: Gtk-WARNING **: gtk_scrolled_window_add(): cannot add non scrollable widget use gtk_scrolled_window_add_with_viewport() instead

You can safely ignore this warning. It is output by GTK+ to remind people to update their code, since the behaviour of scrolled windows changed quite a bit between GTK+ 1.0 and GTK+ 1.2. But the Glade code is OK. The warning should not appear in your final application.

2.6.

What graphics formats does Glade support?

If you are creating a GTK+ application, your graphics must be in XPM format. (GTK+ 2.0 will include the gdk-pixbuf library and so will support many more graphics formats.)

If you are creating a GNOME application, most graphics formats can be used. Though the PNG format is preferred for most graphics such as icons.

You can convert images between formats using the GIMP graphics application or the 'convert' utility in the ImageMagick toolkit.

2.7.

How do I add a signal handler?

Follow these steps:

  • Select the widget you want to add the handler to.

  • Select the 'Signals' page in the Property Editor window.

  • Click the '...' button to the right of the 'Signal:' field. This should show a popup window listing the signals that this widget emits.

  • In the popup window, select which signal you want to connect a handler for and hit the 'OK' button.

  • Glade automatically creates a name for the signal handler function in the 'Handler:' field, but you are free to change this if you desire.

  • Click the 'Add' button to add it to the list of signal handlers for this widget.

When you generate the C source code, an empty signal handler function should be output in the callbacks.c file. You can add your code to this function.

3. Building The C Code Generated By Glade

3.1.

How do I build the code generated by Glade?

You need automake >= 1.4 & autoconf >= 2.13 to build the generated C code. You also need gettext >= 0.10.35 if you enabled gettext support. See the Requirements section in the README file for links to these.

Run ./autogen.sh in the toplevel directory of the project to run automake, autoconf and the related utilities to build the Makefile's. Pass it any options you want passed to configure, e.g. ./autogen.sh --prefix /usr/local/gnome.

Then run make to build your application.

Note that for GNOME applications, you must also do a make install so that the pixmaps are installed properly. If you don't do that, it will still run, but you won't see the pixmaps.

3.2.

I get this error: aclocal: configure.in: 10: macro `AM_PATH_GTK' not found in library

This means that the gtk.m4 file cannot be found. (gtk.m4 is a set of m4 macros which is installed as part of GTK+ and is used to build programs which use GTK+.) aclocal (part of automake) searches for these macros to add to aclocal.m4 in your program's root directory.

To find out where GTK+ is installed, run gtk-config --prefix. The gtk.m4 file should be in the share/aclocal subdirectory. To find out the directory that aclocal is using, run aclocal --print-ac-dir.

You should add the directory that the GTK+ m4 file is installed to the ACLOCAL_FLAGS environment variable, e.g. if the GTK+ m4 files are in /usr/local/share/aclocal, then add this to your $HOME/.profile: export ACLOCAL_FLAGS="-I /usr/local/share/aclocal/".

3.3.

I get this error: ** CRITICAL **: file glade_gnome.c: line 939 (glade_gnome_write_menu_item_source): assertion `source_buffer != NULL' failed.

You are trying to use Gnome stock menu items in a GTK+-only app. Edit any menus you have and make sure the "Stock" property is set to "None" for every item.

4. Using The C Code Generated By Glade

4.1.

What are all the files output by Glade?

These are the default output files, but some of your file names may differ if you have changed the project options.

autogen.sh . A script which runs automake, autoconf and the related programs in the correct order, making it very easy to build the application. You pass it any arguments you want to be passed to configure. After running it, you can type make to build the application.

configure.in . Standard script passed to autoconf to generate the configure script.

Makefile.am . Standard make rules passed to automake to generate the Makefile.in, which the configure script turns into Makefile.

acconfig.h .