Next: Gdk Module, Previous: Reporting Bugs, Up: Top
Unless otherwise stated, Gtk+ functions and variables are made available in Guile with names transformed to Scheme style. This means underscores become hyphens, and only lower case is used.
For instance the C function gtk_label_new
is gtk-label-new
in
Guile, or GTK_WIDGET_FLAGS
is gtk-widget-flags
.
The following general rules are applied to parameters and return values.
NULL
NULL
is represented as #f
, for functions which accept or return
that.
int
, gint
, etcgboolean
#t
and #f
. For
parameters, any non-#f
value is taken to be true.
GList
, GSList
etcgtk-container-children
returns a list of widgets. In parameters,
either a Guile list or vector can be given.
gtk-curve-set-vector
takes a
list or vector of floats.
For instance GtkWindowType
value GTK_WINDOW_TOPLEVEL
is just the
symbol toplevel
, hence a call (gtk-window-new 'toplevel)
.
For example a GdkModifierType
value could be the list (shift-mask
control-mask)
.
For example at the C level gtk_pixmap_get
returns a GdkPixmap
and a GdkBitmap
via pointers. Guile Gtk function gtk-pixmap-get
returns these in a two-element list.
Or for example gdk_window_at_pointer
returns a GdkWindow
and
stores an x
and y
through pointers. These are returned from
gdk-window-at-pointer
in a three element list.
Converting to GdkWChar
with gdk-mbstowc
(see Gdk Module) is
one way to identify character boundaries at least.
GType
GType
(and GtkType
which is the same thing) values are
represented as a distinct kind of Scheme level objects, except for
GTK_TYPE_INVALID
which is represented as #f
. Types can be
compared with equal?
.
As a convenience, functions expecting a GtkType
can be passed a symbol
which is the name of the type. For example,
(gtk-widget-new 'GtkLabel)
For types known to Guile Gtk (anything appearing in the defs files), Guile Gtk
will call the type initialization functions when necessary. Other types will
be available only once relevant C code has created them.
GObject
GObject
is represented uniquely at the Scheme level, so widgets
etc can be compared or hashed with eq?
. An object is destroyed when
garbage collected, if it's not otherwise in use by Gtk.
Type predicates like GTK_IS_CHECK_BUTTON
are implemented as for
instance gtk-check-button?
. There are no type checking casts like in
C, Guile Gtk functions expecting a particular object class always check they
get it or a sub-class.
GError
GError
parameters at the C level are implemented as scm-error
style throws see Procedures for Signaling Errors. For example gdk-pixbuf-new-from-file
(see GdkPixbuf Module) is called as
(gdk-pixbuf-new-from-file "myfile.png")
and if an error occurs it may throw for instance
(scm-error 'g-error "gdk-pixbuf-new-from-file" "Failed to open file 'myfile.png': No such file or directory" '(g-file-error-quark 4))
The data parameter is a list of error domain and code number.
gdk-threads-enter
and gdk-threads-leave
are available though,
and can be used the same as in a C program.
Perhaps in the future additional threading protection will be provided by Guile Gtk. Presently two threads both calling Gtk/Gdk can crash the interpreter, the idea would be to guard against that.