For the most part, writing GTK+ apps using Wrapl is quite similar to writing them in C.
Using Glade files in Wrapl
Since there is a one-to-one mapping of GTK+ objects to Riva objects, and since the riva module loader is extensible at runtime, the module Gtk.Glader.Loader registers a loader for .glade files. A .glade loaded in this fashion behaves like a Riva module, exporting widgets as Riva objects using their names in the .glade file. In addition, they can be set to automatically connect to Wrapl/Riva functions to handle signals. Callbacks are specified as Module.Export where Module is the path of the module separated by /'s. To denote a module relative to the directory containing the .glade file, Module should start with a /.
The following code combined with the proceeding .glade file will produce the same result as the code above. There is one caveat: the module must be loaded using riva -PGtk/Glade/Loader -L. Gtk2, in order to preload Gtk.Glade.Loader, and so that the module Gtk2 is loaded within the module system and not as an anonymous module.
1MOD Gtk2;
2
3IMP Gtk.Gtk;
4IMP .Gtk2UI;
5
6Gtk2UI.MainWindow:ShowAll;
7Gtk.Main.Run();
8
9DEF OnClick!(button, userdata) (
10 Gtk2UI.Dialog:Run;
11 Gtk2UI.Dialog:Hide;
12);
13
14END Gtk2.
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
3
4<glade-interface>
5 <widget class="GtkWindow" id="MainWindow">
6 <signal name="destroy" handler="Gtk/Gtk/Main.Quit"/>
7 <child>
8 <widget class="GtkButton" id="button1">
9 <property name="visible">True</property>
10 <property name="can_focus">True</property>
11 <property name="receives_default">True</property>
12 <property name="label" translatable="yes">Press Me!</property>
13 <property name="response_id">0</property>
14 <signal name="clicked" handler="/Gtk2.OnClick"/>
15 </widget>
16 </child>
17 </widget>
18 <widget class="GtkDialog" id="Dialog">
19 <property name="border_width">5</property>
20 <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
21 <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
22 <property name="transient_for">MainWindow</property>
23 <child internal-child="vbox">
24 <widget class="GtkVBox" id="dialog-vbox1">
25 <property name="visible">True</property>
26 <property name="spacing">2</property>
27 <child>
28 <widget class="GtkLabel" id="label1">
29 <property name="visible">True</property>
30 <property name="label" translatable="yes">Sample GTK+ application</property>
31 </widget>
32 <packing>
33 <property name="position">1</property>
34 </packing>
35 </child>
36 <child internal-child="action_area">
37 <widget class="GtkHButtonBox" id="dialog-action_area1">
38 <property name="visible">True</property>
39 <property name="layout_style">GTK_BUTTONBOX_END</property>
40 <child>
41 <widget class="GtkButton" id="button2">
42 <property name="visible">True</property>
43 <property name="can_focus">True</property>
44 <property name="receives_default">True</property>
45 <property name="label" translatable="yes">gtk-ok</property>
46 <property name="use_stock">True</property>
47 <property name="response_id">0</property>
48 </widget>
49 </child>
50 <child>
51 <placeholder/>
52 </child>
53 </widget>
54 <packing>
55 <property name="expand">False</property>
56 <property name="pack_type">GTK_PACK_END</property>
57 </packing>
58 </child>
59 </widget>
60 </child>
61 </widget>
62</glade-interface>