1 the project has moved to Google.
3 http://code.google.com/p/gtknode/
6 Yet Another GUI framework for Erlang - gtkNode
10 * GUI separated from application by message passing
11 * distributed (application and GUI can run on different machines)
12 * centered around a GUI builder
13 * small volume of (hand-written) code
18 a c-node (a daemon that implements the Erlang distribution protocol)
19 that instantiates the GUI from a configuration file. the c-node sends
20 messages to the Erlang node when the user interacts with the GUI; the
21 Erlang application changes the state of the GUI by sending messages to
22 widgets in the c-node. the widgets should look like Erlang processes
23 with registered names. the protocol should look something like this.
25 CnodePid ! {aWidget,dosomething,Args} % erlang->cNode
26 ApplicationPid ! {reply, Val} % cNode->Erlang
27 ApplicationPid ! {signal,aWidget,eventType} % cNode->erlang
29 in this example aWidget is the name given to a widget in the
30 configration file. it can also be thought of as the registered name of
31 the process implementing the widget in the c-node.
32 the c-node is responsible for garbage-collecting all temporary data.
36 i chose GTK2 (www.gtk.org) as the framework. there were several reasons;
38 * it has an eminent GUI builder, Glade (glade.gnome.org)
39 * it has facilities for instantiating the GUI from the Glade (XML) files
40 * it has good documentation
41 * it supports run-time type checking
42 * its object orientation maps well to Erlang (Obj.meth(Arg) -> Obj!{meth,[Arg]})
43 * the Python binding provides useful tools for code generation
44 * seems to be the Future (tm) in the *nix world, and runs on Windows too.
46 there's three parts to the gtkNode. a main loop, some support
47 functions for object storage and marshalling, and a whole bunch of
48 generated wrapper functions.
49 The main loop is a pretty generic c-node that simple-mindedly
50 receives lists of 2-tuples;
52 {atom('Func'), list(boolean()|integer()|float()|atom()|string())}
54 it checks that there exists a function Func and calls it, passing a
55 pointer to the argument list. the Func's are wrapper functions
56 generated from the GTK header files, and unmarshalls and type checks
57 the arguments before the actual GTK functions are called.
58 the return value of the GTK function is sent back to the Erlang node.
60 a different kind of message is sent if there is an interesting event
61 in the GUI (e.g. a button is pressed), where "interesting" means specified
66 the c-node is started thus;
67 gtkNode node host regname cookie cnode-name
69 when started, gtkNode will connect to it's application by sending a
70 handshake message to {node@host, regname}.
71 the messsage looks like this;
72 {{GtkPid,handshake}, []}
74 the Erlang application sends messages to the gtkNode using
75 GtkPid. messages look like this;
77 list({'Gtk_function', [Args]})
79 E.g., if we have a GtkButton widget, named b1, and we want to use
82 const gchar* gtk_button_get_label (GtkButton *button);
83 void gtk_button_set_label (GtkButton *button, const gchar *label);
87 GtkPid ! [{'Gtk_button_set_label',[b1,"foo"]},{'Gtk_button_get_label',[b1]}].
89 and we would receive this;
91 {{GtkPid,reply}, [{ok,void},{ok,"foo"}]}
93 signals are sent from gtkNode if the signal handler for a specified
94 signal-widget combination is set to gn_sighandler. the signals look
97 {{GtkPid, signal}, {atom(WidgetName),atom(SignalName)}}
99 E.g., if we delete the GtkWindow named window1 we'll get this signal
101 {{GtkPid, signal},{window1,'GDK_DELETE'}}
103 given that we've requested it, of course.
107 the file src/gtkNode.erl implements a controller/middleman for the
108 gtkNode, it's quite instructive. it is recommended to use this instead of working directly against the c-node.
109 the file examples/simple/simple.erl implements the Erlang side of a
110 GUI for a simple 'top' application. the GUI is specified in
111 examples/simple/simple.glade
117 see www.trapexit.org or sourceforge.net
121 i can't see why the should be any real problems to get this to work
122 on Windows (if it can be said that anything works on Windows); alas, i
123 have no real wish to try it myself...
124 look here for more info;
125 www.gimp.org/~tml/gimp/win32
128 i myself run on solaris 8 and linux (debian).
130 cd jungerl/lib/gtkNode ; make
135 * there is a sane GTK environment
139 pkg-config --cflags libglade-2.0
141 works, i.e. returns a bunch of c-flags, you should be OK.
145 early beta. no major interface changes in the works, but (probably)