File: libglade-notes.html

package info (click to toggle)
libglade 0.11-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,748 kB
  • ctags: 660
  • sloc: ansic: 8,107; sh: 7,135; makefile: 420; python: 152; sed: 93
file content (353 lines) | stat: -rw-r--r-- 6,271 bytes parent folder | download
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
<HTML
><HEAD
><TITLE
>Libglade Programming Notes</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINK
REL="HOME"
TITLE="Libglade Reference Manual"
HREF="libglade.html"><LINK
REL="PREVIOUS"
TITLE="Libglade Reference Manual"
HREF="libglade.html"><LINK
REL="NEXT"
TITLE="Adding GNOME Support"
HREF="libglade-gnome.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
BGCOLOR="#000000"
CELLPADDING="1"
CELLSPACING="0"
><TR
><TH
COLSPAN="4"
ALIGN="center"
><FONT
COLOR="#FFFFFF"
SIZE="5"
>Libglade Reference Manual</FONT
></TH
></TR
><TR
><TD
WIDTH="25%"
BGCOLOR="#C00000"
ALIGN="left"
><A
HREF="libglade.html"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>&#60;&#60;&#60; Previous Page</B
></FONT
></A
></TD
><TD
WIDTH="25%"
BGCOLOR="#0000C0"
ALIGN="center"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
><A
HREF="libglade.html"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>Home</B
></FONT
></A
></B
></FONT
></TD
><TD
WIDTH="25%"
BGCOLOR="#00C000"
ALIGN="center"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>&nbsp;</B
></FONT
></TD
><TD
WIDTH="25%"
BGCOLOR="#C00000"
ALIGN="right"
><A
HREF="libglade-gnome.html"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>Next Page &#62;&#62;&#62;</B
></FONT
></A
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="LIBGLADE-NOTES"
>Libglade Programming Notes</A
></H1
><P
>Libglade is an alternative to using Glade's code generation.
    Instead of generating code from the XML interface description,
    libglade loads and parses the description at runtime.  It also
    provides functions that can be used to connect signal handlers to
    parts of the interface.</P
><P
>In this way, it allows you to separate your program code
    from the interface code.  In fact, if you use the
    glade_xml_signal_autoconnect() function, the GUI code could be as
    simple as the <TT
CLASS="FILENAME"
>test-libglade.c</TT
> example that
    comes with libglade.  Of course, you would also add your own
    signal handlers to the code.  Note that the signals are connected
    the same way as if you had hand coded the interface.  There is no
    extra overhead to interfaces generated by libglade (after the
    initial generating of course, and this is not much of an overhead)
    when compared to a hand crafted interface.</P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="LIBGLADE-BASICS"
>Libglade Programming Basics</A
></H1
><P
>Your basic libglade program will look something like this:</P
><TABLE
BORDER="0"
BGCOLOR="#D6E8FF"
WIDTH="100%"
CELLPADDING="6"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#include &lt;gtk/gtk.h&gt;
#include &lt;glade/glade.h&gt;

void some_signal_handler_func(GtkWidget *widget, gpointer user_data) {
  /* do something useful here */
}

int main(int argc, char *argv[]) {
    GladeXML *xml;

    gtk_init(&amp;argc, &amp;argv);
    glade_init();

    /* load the interface */
    xml = glade_xml_new("filename-for-interface", NULL);
    /* connect the signals in the interface */
    glade_xml_signal_autoconnect(xml);
    /* start the event loop */
    gtk_main();
    return 0;
}</PRE
></TD
></TR
></TABLE
><P
>This will create the interface from the file
      <TT
CLASS="FILENAME"
>filename-for-interface</TT
>, then connect all
      the signals in the interface.  The automatic signal connection
      is done by looking up function names in the symbol table using
      gmodule.  This means that the interface file can use standard
      GTK functions such as <TT
CLASS="FUNCTION"
>gtk_widget_show</TT
>, or
      <TT
CLASS="FUNCTION"
>gtk_main_quit</TT
>, or others in the interface
      and not have to write any code to connect the signals.</P
><P
>The <TT
CLASS="FUNCTION"
>some_signal_handler_func</TT
> function
      is not referenced anywhere in the program explicitely, but if
      any signals are defined in the interface description that use
      "some_signal_handler_func" as the handler name, then this
      function will automatically be connected.  Note that the
      function can not be static, since we require it to apear in the
      symbol table.  Here is an example of the XML that would cause
      <TT
CLASS="FUNCTION"
>some_signal_handler_func</TT
> to be
      connected:</P
><TABLE
BORDER="0"
BGCOLOR="#D6E8FF"
WIDTH="100%"
CELLPADDING="6"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&lt;widget&gt;
  &lt;class&gt;GtkWindow&lt;/class&gt;
  &lt;name&gt;MainWindow&lt;/name&gt;
  &lt;signal&gt;
    &lt;name&gt;destroy&lt;/name&gt;
    &lt;handler&gt;some_signal_handler_func&lt;/handler&gt;
  &lt;/signal&gt;
  ...</PRE
></TD
></TR
></TABLE
><P
>To compile the program, we would use the following:</P
><TABLE
BORDER="0"
BGCOLOR="#D6E8FF"
WIDTH="100%"
CELLPADDING="6"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>cc -o testprogram testprogram.c `libglade-config --cflags --libs`</PRE
></TD
></TR
></TABLE
><P
>The <TT
CLASS="FILENAME"
>libglade-config</TT
> script will give
      the correct parameters used to compile the program.  If you are
      using automake or autoconf, you may want to investigate the
      AM_PATH_LIBGLADE macro that is installed as
      <TT
CLASS="FILENAME"
>$(datadir)/aclocal/libglade.m4</TT
>.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><BR><BR><TABLE
WIDTH="100%"
BORDER="0"
BGCOLOR="#000000"
CELLPADDING="1"
CELLSPACING="0"
><TR
><TD
WIDTH="25%"
BGCOLOR="#C00000"
ALIGN="left"
><A
HREF="libglade.html"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>&#60;&#60;&#60; Previous Page</B
></FONT
></A
></TD
><TD
WIDTH="25%"
BGCOLOR="#0000C0"
ALIGN="center"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
><A
HREF="libglade.html"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>Home</B
></FONT
></A
></B
></FONT
></TD
><TD
WIDTH="25%"
BGCOLOR="#00C000"
ALIGN="center"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>&nbsp;</B
></FONT
></TD
><TD
WIDTH="25%"
BGCOLOR="#C00000"
ALIGN="right"
><A
HREF="libglade-gnome.html"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>Next Page &#62;&#62;&#62;</B
></FONT
></A
></TD
></TR
><TR
><TD
COLSPAN="2"
ALIGN="left"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>Libglade Reference Manual</B
></FONT
></TD
><TD
COLSPAN="2"
ALIGN="right"
><FONT
COLOR="#FFFFFF"
SIZE="3"
><B
>Adding GNOME Support</B
></FONT
></TD
></TR
></TABLE
></DIV
></BODY
></HTML
>