Basic builder » History » Version 7
iri, 02/22/2011 02:30 PM
1 | 1 | iri | h1. Basic builder |
---|---|---|---|
2 | |||
3 | It's a very simple interface built with GtkBuilder. |
||
4 | |||
5 | # add the file with _gtkBuilderNewFromFile |
||
6 | # if needed, get any included object (for example, a window, a button ...) with _gtkBuilderWidgetGet |
||
7 | # if needed, define any callback and others codes ... |
||
8 | # run the GTK+ loop. |
||
9 | |||
10 | 5 | iri | Note : Don't call _gtkWidgetShow(All), all included widgets will be automatically shown. |
11 | 1 | iri | |
12 | Look this Scol code : |
||
13 | |||
14 | <pre><code class="php"> |
||
15 | fun cbDestroy (obj, uparam)= |
||
16 | _fooS strcat "upram = " itoa uparam; |
||
17 | 7 | iri | /* Stop the GTK+ loop */ |
18 | 1 | iri | _gtkMainQuit; |
19 | 0;; |
||
20 | |||
21 | fun cbButtonClicked (obj, uparam)= |
||
22 | _fooS strcat "button param = " uparam; |
||
23 | 0;; |
||
24 | |||
25 | fun main ()= |
||
26 | _showconsole; |
||
27 | 4 | iri | // add a .xml file |
28 | 1 | iri | let _gtkBuilderNewFromFile _channel _checkpack "tests/2dgtk/0.glade" -> builder in |
29 | |||
30 | // get object from the builder : a window and a button |
||
31 | let _gtkBuilderWidgetGet builder "main_window" -> win in |
||
32 | let _gtkBuilderWidgetGet builder "button_1" -> button in |
||
33 | ( |
||
34 | // define the callbacks |
||
35 | _gtkWindowCBdestroyed win @cbDestroy 10; |
||
36 | _gtkButtonCB button @cbButtonClicked "yes !" SCOL_GTK_BUTTON_CB_CLICKED; |
||
37 | // run the GTK+ loop |
||
38 | _gtkMain; |
||
39 | 0 |
||
40 | );; |
||
41 | </code></pre> |
||
42 | |||
43 | and now, the xml file : |
||
44 | |||
45 | <pre><code class="xml"> |
||
46 | <?xml version="1.0"?> |
||
47 | <interface> |
||
48 | <requires lib="gtk+" version="2.16"/> |
||
49 | <!-- interface-naming-policy project-wide --> |
||
50 | <object class="GtkWindow" id="main_window"> |
||
51 | <property name="visible">True</property> |
||
52 | <property name="title" translatable="yes">Test 2dGtk - 0</property> |
||
53 | <child> |
||
54 | <object class="GtkVBox" id="main_box"> |
||
55 | <property name="visible">True</property> |
||
56 | <property name="spacing">5</property> |
||
57 | <child> |
||
58 | <object class="GtkButton" id="button_1"> |
||
59 | <property name="label" translatable="yes">button 1</property> |
||
60 | <property name="visible">True</property> |
||
61 | <property name="can_focus">True</property> |
||
62 | <property name="receives_default">True</property> |
||
63 | </object> |
||
64 | <packing> |
||
65 | <property name="position">0</property> |
||
66 | </packing> |
||
67 | </child> |
||
68 | </object> |
||
69 | </child> |
||
70 | </object> |
||
71 | </interface> |
||
72 | </code></pre> |
||
73 | 2 | iri | |
74 | 3 | iri | Return [[Examples]] |