Next: , Previous: Gtk Module, Up: Top

8 Gtk Extras

The following extra Gtk level functions are provided by Guile Gtk.

— Function: gtk-callback-trampoline [tramp]

Get or set the trampoline procedure for Gtk callbacks. With no arguments, the current trampoline is returned. With an argument, the trampoline procedure is set, and the old procedure returned.

When making a callback for signals etc, Guile Gtk goes through this trampoline. tramp is called as (tramp proc args), where proc is the application procedure to call, and args is a list of arguments for it (possibly empty). A minimal trampoline would be,

          (define (my-trampoline proc args)
            (apply proc args))

(which of course is just apply itself, no need for a new definition).

The default trampoline uses catch to trap errors from the callback, and displays them in a window (see Catching Exceptions). The aim is to give the user some feedback in the GUI about what has gone wrong, rather than suddenly terminating. An application can set a new trampoline to do this in its preferred way.

— Function: gtk-class-new type name

Return a new GtkType with the given name (a string), created as a sub-class of type.

Instances of the new type can be created with gtk-widget-new in the usual way. The new type has the same size as the given type, there's no mechanism to add extra data fields. (The suggestion would be to use Guile object properties for such things, See Object Properties.)

The main advantage of a new class is that it can be type checked in a fashion similar to other Gtk objects. For instance,

          (define my-foo-button-type
            (gtk-class-new 'GtkButton "MyFooButton")))
          (define (my-foo-button-new)
            (gtk-widget-new my-foo-button-type #:label "something")))
          (define (my-foo-button? obj)
            (gtk-check-type obj my-foo-button-type))
          (define (my-foo-button-dosomething obj)
            (or (my-foo-button? obj)
                (error "Wrong object type: ~a" obj))

It also works to use 'MyFooButton like the builtin types, instead of holding the type in my-foo-button-type.

— Function: gtk-list-append-item list listitem
— Function: gtk-list-prepend-item list listitem

Append or prepend a single item to a GtkList.

— Function: gtk-pixmap-new-from-file filename parent

Return a new GtkPixmap widget, containing an XPM image loaded from filename as per gdk-pixmap-colormap-create-from-xpm. parent is an intended parent widget, used to get the colormap for the image.

— Function: gtk-signal-new-generic name flags objtype rettype paramtypes

Create a new signal name for use by objtype and return the signal ID (an integer). flags is GtkSignalRunType flags, rettype is the return type for the handler, and paramtypes is a list of parameter types for it (GType values or symbols).

This function is like the C function gtk_signal_newv, but doesn't setup any particular marshaller, rather it's for use with Scheme level handlers which are invoked “generically” based on the type information provided.

For instance the following adds a new signal to GtkAdjustment, taking a string and a boolean as parameters. Clearly Gtk itself won't use or emit something like this, it'd just be for an application.

          (gtk-signal-new-generic "big_change_soon" '(no-recurse)
                                  'void '(GtkString gboolean))

The following functions are provided by

     (use-modules (gtk threads))
— Function: gtk-threads-ensure-handler

Start a Gtk main loop in a new Guile thread, if this function has not previously done that. This is a convenient way for an application to ensure a main loop exists, but continue with other things.

The main loop is started within a gdk-threads-enter / gdk-threads-leave pair in the standard way for a threaded program, as per the following.

— Function: gtk-threads-handler?

Return true if gtk-threads-ensure-handler has started a Gtk main loop.