- Up - | Next >> |
This manual describes the GTK+ language binding for Oz.
Comparison to Tk
You may be wondering how GTK+ compares to Tk, for which a binding for Oz has been available for a long time. The reasons to provide another library for Graphical User Interfaces (GUIs) are as follows:
We wanted to provide a more modern widget set.
The Tcl/Tk binding uses an external process and inter-process communication to do the actual work. In contrast, the GTK+ widgets run in the Mozart process itself. It should therefore provide better performance.
Note that GTK+ should be available for all platforms supported by Mozart.
GTK+
GTK+ is a widget set for building graphical user interfaces. It provides windows, buttons, text editing widgets, and many more. Its official web site is at http://www.gtk.org/
. The binding makes use of Version 1.2 (Unix) or 1.3 (Windows).
GDK
GTK+ builds on a GDK, which provides low-level windowing functions, abstracting from the actual windowing environment used (X Window System or Microsoft Windows).
GTK+ Canvas
The GTK+ Canvas used here is a patched version of the Gnome Canvas ripped out of the Gnome sources.
GLib
GLib is a library of data types and utilities used by the other components. Only the support functions required to use GTK+ and GDK are available through the binding.
Let's look at a ``hello world'' type application using the GTK+ binding, to get a feeling of how this could look like.
functor
import
Application(exit)
System(show)
GTK
define
%% Define Toplevel window class
class MyToplevel from GTK.window
meth new()
GTK.window, new(GTK.'WINDOW_TOPLEVEL')
GTK.window, setBorderWidth(10)
GTK.window, setTitle("Hello, World!")
{self signalConnect('delete-event'
deleteEvent _)}
end
meth deleteEvent(Args)
%% Do cleanup stuff here
{System.show 'deleteEvent occured'}
{Application.exit 0}
end
end
%% Define HelloButton class
class HelloButton from GTK.button
meth new()
GTK.button, newWithLabel("Hello, World!")
GTK.button, signalConnect('clicked'
clickedEvent _)
end
meth clickedEvent(Args)
{System.show 'ClickedEvent occured'}
end
end
%% Create Class Instances
Toplevel = {New MyToplevel new()}
Button = {New HelloButton new()}
%% Make Butten child of Toplevel Container
{Toplevel add(Button)}
%% Make it all visible
{Toplevel showAll()}
end
If you are familiar with GUI programming, you will recognize a few things suchs as creating windows, adding children to them, and making them react to user input.
More Examples
A number of examples can be found in the examples/gtk
directory in Mozart's installation folder.
We will first summarize the basics of the GTK+ user interface model in Chapter 2. Next we'll explain how to access the actual API from Oz in Chapter 3 and give a reference of the additional procedures provided by the binding in Chapter 4. Finally, an abstraction is introduced in Chapter 5 that allows for declarative specification of user interfaces and obviates the need to know many of the fine details of the GTK+ API.
The GTK+ language binding is available as a source RPM
or can be obtained directly from cvs via
cvs -d :pserver:anoncvs@cvs.mozart-oz.org:/services/mozart/CVS get mozart-gtk
To compile the CVS sources, use the following option to configure:
configure --with-gtk-canvas-dir=
DIR
where DIR is the directory in which the GTK Canvas has been installed. Otherwise, issue the
rpm --rebuild mozart-gtk<version>.rpm
command.
Compiling the GTK Canvas
The GTK Canvas is available as a source RPM
or can be obtained directly from cvs via
cvs -d :pserver:anoncvs@cvs.mozart-oz.org:/services/mozart/CVS get gtk-canvas
To compile the CVS sources, use the standard configure; make; make install
procedure. The configure prefix used here yields the value of DIR above. Otherwise, issue the
rpm --rebuild gt-canvas<version>.rpm
command.
Windows
Compiling the sources on Windows requires a number of libraries
. After downloading and extracting the archive, edit the gtk-config and imlib-config files in the freshly created bin directory to match your setup. Make sure this binary directory is within your path. Afterwards, using the cvs sources you should be able to compile the binding.
For user convenience, the gtk binding is shipped as part of the binary window distribution of mozart.
- Up - | Next >> |