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