File: FAQ

package info (click to toggle)
glade-nonus 0.6.4-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 12,152 kB
  • ctags: 3,879
  • sloc: ansic: 54,332; sh: 6,839; makefile: 743; sed: 93
file content (538 lines) | stat: -rw-r--r-- 19,806 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538

Table of Contents
=================

1. General Information About Glade

  1.1 What documentation is there for Glade?
  1.2 Is there any example code?
  1.3 Do I have to use a particular license for the C code generated by Glade?

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.
  2.2 How do I change the colors of a widget, e.g. make a label red?
  2.3 How do I add a pixmap to a button?
  2.4 How do I add several widgets of the same type in one go?
  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
  2.6 What graphics formats does Glade support?
  2.7 How do I add a signal handler?

3. Building The C Code Generated By Glade

  3.1 How do I build the code generated by Glade?

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

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

4. Using The C Code Generated By Glade

  4.1  What are all the files output by Glade?
  4.2  What files can the developer edit safely and which are overwritten?
  4.3  How do I add my own source files to the project?
  4.4  How do I add a library to the project?
  4.5  How do I get a pointer to a widget from within a signal handler?
  4.6  How do I get a pointer to a widget in another window?
  4.7  How do I get the value of a GtkOptionMenu?
  4.8  How do I get a GtkOptionMenu to call a function when it changes?
  4.9  How do I connect to GtkAdjustment signals?
  4.10 How do I add rows to a GtkCList before the window is shown?


==============================================================================

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:

 o Spanish Guide - http://tigre.aragon.unam.mx/m3d/links_es.htm
 o Italian Guide - http://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 http://glade.gnome.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 http://glade.gnome.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
http://glade.gnome.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 http://developer.gnome.org/doc/API

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 in Glade:

     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.

NOTE: 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:

 o Select the widget you want to add the handler to.
 o Select the 'Signals' page in the Property Editor window.
 o Click the '...' button to the right of the 'Signal:' field. This should
   show a popup window listing the signals that this widget emits.
 o In the popup window, select which signal you want to connect a handler for
   and hit the 'OK' button.
 o Glade automatically creates a name for the signal handler function in the
   'Handler:' field, but you are free to change this if you desire.
 o 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 Makefiles. 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: 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	- contains a few macros which are set during the configure
		  script and added to the config.h header (which should be the
		  first file #include'd by all of your source files).
		  Most of these macros are needed for gettext support
		  (ENABLE_NLS, HAVE_CATGETS, HAVE_GETTEXT, HAVE_LC_MESSAGES,
		  HAVE_STPCPY), HAVE_LIBSM is needed for GNOME (but it doesn't
		  hurt a GTK+ app), and a few are added by Glade
		  (PACKAGE_LOCALE_DIR, PACKAGE_DATA_DIR, PACKAGE_SOURCE_DIR).
stamp-h.in	- used as a timestamp by automake, for rebuilding some
		  generated files.

AUTHORS		- these files are all initially empty, but are created to
ChangeLog	  comply with the GNU conventions.
NEWS
README

src/Makefile.am	- standard automake file.
src/main.c	- contains the main() function which will create one of each
		  window/dialog for you.
src/interface.h - declarations of functions you can call to create the windows
		  and dialogs which were built in Glade.
src/interface.c - the code to create the windows and dialogs and all the
		  widgets.
src/callbacks.h - declarations of the signal handler and callback functions
		  which you will write.
src/callbacks.c - the signal handler and callback functions, 
src/support.h   - declarations of some support functions, including
		  lookup_widget() which you can use to get pointers to widgets.
src/support.c   - the support functions.


If gettext support is enable, the po directory is created, with POTFILES.in
and a separate ChangeLog. POTFILES.in lists the source files which contain
translatable strings, and you should add any source files you create here.

For GNOME projects the macros directory is also added, containing all the m4
macros used to build the project. (These should really have been installed as
part of GNOME, but unfortunately this wasn't done in GNOME 1.0.X. Hopefully
this will be fixed in a future version of GNOME, and so this directory will not
be needed.)

*NOTE*: if you change the 'GNOME Support' or 'Gettext Support' project
options after building the project, you will need to update some of the
build files such as configure.in, Makefile.am
The best solution may be to change the project directory in the 'Project
Options' dialog, and to rebuild the project from scratch. However, you would
have to copy over any code you have added to signal handlers. An alternative
would be to delete autogen.sh, configure.in, Makefile.am, src/Makefile.am,
and src/main.c and use Glade to recreate them. But if you have changed these
files you will need to add the changes back in.
(Hopefully Glade will deal with this better in future.)



4.2 What files can the developer edit safely and which files are overwritten?

Glade will not overwrite most of the files. It will recreate the build files
if they don't exist (and the corresponding project option is set.)

The files which Glade overwrites are:

  interface.h
  interface.c
  support.h
  support.c

(Though you may have named them differently in your project, if you changed
them in the Project Options dialog.)

These files all have a warning at the top saying 'DO NOT EDIT'.


If you have added or updated any signal handlers, then these are appended to
the callbacks.h and callbacks.c files. So any code you have already added
for callbacks is completely safe! If you have renamed a handler function then
it is up to you to remove the old version and copy any code to the new
function.



4.3 How do I add my own source files to the project?

Add the source file (and any header file) to src/Makefile.am, in the
project1_SOURCES variable (where 'project1' is the name of your project).

If you are using gettext, you may also want to add the source file to
po/POTFILES.in so that the strings can be translated.



4.4 How do I add a library to the project?

You need to add a test for the library in your project's configure.in file,
making sure that the CPPFLAGS and LIBS are updated to account for the library.
(The CPPFLAGS variable should contain any -I flags to pass to the C
preprocessor, and the LIBS variable should contain the -l and -L options to
pass to the linker.)

autoconf provides macros such as AC_CHECK_HEADER and AC_CHECK_LIB which can
be used to check for general headers and libraries.

Many GTK+ and Gnome libraries provide a config script such as gtk-config
which will output the CPPFLAGS and LIBS flags needed.

For example, libxml provides an xml-config script which you can use like this:

  dnl Get libxml flags & libs
  AC_PATH_PROG(xml_config, xml-config)
  if test "x$xml_config" = "x"; then
    AC_MSG_ERROR([*** xml-config not found.])
  fi

  XML_CFLAGS=`$xml_config --cflags 2>/dev/null`
  XML_LIBS=`$xml_config --libs 2>/dev/null`
  CPPFLAGS="$CPPFLAGS $XML_CFLAGS"
  LIBS="$LIBS $XML_LIBS"

NOTE: Make sure you place your configure.in test before the call to AC_OUTPUT.


4.5 How do I get a pointer to a widget from within a signal handler?

If you have a pointer to any widget in a window, you can get a pointer to
any other widget in the window using the lookup_widget() function that Glade
provides (in support.c).

You pass it a pointer to any widget in a window, and the name of the widget
that you want to get. Usually in signal handlers you can use the first argument
to the signal handler as the first parameter to lookup_widget(), e.g.

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  GtkWidget *entry1;

  entry1 = lookup_widget (GTK_WIDGET (button), "entry1");

  ...
}


Note that this does not work if you are using libglade. The corresponding
code for libglade would be:

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  GladeXML* xml;
  GtkWidget* entry1;

  xml = glade_get_widget_tree (GTK_WIDGET (button1));
  entry1 = glade_xml_get_widget (xml, "entry1");

  ...
}


4.6 How do I get a pointer to a widget in another window?

You need to keep track of pointers to all your toplevel windows.
For simple applications you can just use global variables to store these
pointers.

For more complicated applications you can use the gtk_object_set_data() and
related functions to store a pointer to one window inside another window.
For example, if you want to create a dialog which needs to access widgets in
the main window you can do this:

  dialog = create_dialog1 ();  /* Call the function generated by Glade. */
  gtk_object_set_data (GTK_OBJECT (dialog), "main_window", main_window);

Then when you need to access the main window from within the dialog code,
you can do this:

  main_window = gtk_object_get_data (GTK_OBJECT (dialog), "main_window");

NOTE: You need to be careful to ensure that the pointer is always valid.
If the window being pointed to is destroyed, make sure you no longer use the
pointer to it or your application may crash.


4.7 How do I get the value of a GtkOptionMenu?

Call gtk_menu_get_active() with the GtkOptionMenu's menu to get the currently
selected menu item. You can use g_list_index() to find its index in the menu:

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  GtkWidget *option_menu, *menu, *active_item;
  gint active_index;

  option_menu = lookup_widget (GTK_WIDGET (button), "optionmenu1");
  menu = GTK_OPTION_MENU (option_menu)->menu;
  active_item = gtk_menu_get_active (GTK_MENU (menu));
  active_index = g_list_index (GTK_MENU_SHELL (menu)->children, active_item);

  g_print ("Active index: %i\n", active_index);
}


4.8 How do I get a GtkOptionMenu to call a function when it changes?

Glade doesn't support this at present, but you can set it up manually.

When you create the window, get the option menu and connect to the "deactivate"
signal emitted by its menu:

  window1 = create_window1 ();
  option_menu = lookup_widget (window1, "optionmenu1");
  gtk_signal_connect (GTK_OBJECT (GTK_OPTION_MENU (option_menu)->menu),
                      "deactivate", GTK_SIGNAL_FUNC (on_option_selected),
                      NULL);


Then add a handler to callbacks.c. You can get the index of the selected item
just like the previous answer:

static void
on_option_selected (GtkMenuShell *menu_shell,
                    gpointer data)
{
  GtkWidget *active_item;
  gint item_index;
  
  active_item = gtk_menu_get_active (GTK_MENU (menu_shell));
  item_index = g_list_index (menu_shell->children, active_item);

  g_print ("In on_option_selected active: %i\n", item_index);
}


4.9 How do I connect to GtkAdjustment signals?

Glade doesn't support this at present, but you can set it up manually, in a
similar way to question 3.6.

When you create the window, get a pointer to the widget containing the
adjustment, and connect to the "changed" or "value_changed" signals:

  window1 = create_window1 ();
  hscale = lookup_widget (window1, "hscale1");
  gtk_signal_connect (GTK_OBJECT (GTK_RANGE (hscale)->adjustment),
                      "changed", GTK_SIGNAL_FUNC (on_adjustment_changed),
                      NULL);


4.10 How do I add rows to a GtkCList before the window is shown?

After you create the window, using the 'create' function generated by Glade,
use lookup_widget() to get a pointer to the GtkCList widget, and add the rows
as required. e.g.

  GtkWidget *window, *clist;
  gchar *row[2];		/* Our GtkCList only has 2 columns. */

  window = create_window1 ();
  clist = lookup_widget (window, "clist1");

  row[0] = "Hello";
  row[1] = "World";
  gtk_clist_append (GTK_CLIST (clist), row);

  row[0] = "Second";
  row[1] = "Row";
  gtk_clist_append (GTK_CLIST (clist), row);

  gtk_widget_show (window1);