GUI Programming with an Interface Builder

Glade is an interface builder described as “a RAD tool to enable quick & easy development of user interfaces for the GTK+ toolkit and the GNOME desktop environment, released under the GNU GPL License. The user interfaces designed in Glade are saved as XML, and by using the libglade library these can be loaded by applications dynamically as needed.”

The following screenshot shows the design of a simple GUI with glade:

Once the XML interface description is saved in file interface.glade, the following program permits to load this description file and run the GUI. Note here that 3 callbacks have been defined here:

To install the package, just issue the following command:

$ stklos-pkg --install stklos-gtk-glade
Note:
The package stklos-gtk-glade searches the system GUI toolkit libraries in some standard places (mainly /usr/lib and /usr/local/lib). If your libraries are installed in another directory, you can set the shell variable STKLOS_GTK_DIR to that directory name. This variable is used both for installing the ScmPkg and for running your program.

Before using this package, you can test that everything works with the following command:

$ stklos-pkg --test stklos-gtk-glade

The execution of this test produces the following interface:

Example

The code of the previous exemaple is:

;;;;
;;;; glade-interface.stk
;;;;

(require "stklos-gtk-glade")
(import stklos-gtk-base
        stklos-gtk-glade)

;; ======================================================================
;;      Callbacks ...
;; ======================================================================

;; Dialog close
(define (dialog-destroy-cb widget data)
  (eprintf "Destroying dialog\n")
  (gtk-main-quit))

;; Button OK 
(define (ok-clicked-cb widget data)
  (eprintf "You have clicked the OK button\n")
  (gtk-main-quit))

;; Button Cancel
(define (cancel-clicked-cb widget data)
  (eprintf "You have clicked the Cancel button\n"))


;; ======================================================================
;;      Glade GUI ...
;; ======================================================================
(define (gtk-gui)
  (gtk-init (void) (void))
  (let* ((xml    (glade-xml-new "./interface.glade" (void) (void)))
         (widget (glade-xml-get-widget xml "dialog1")))
    (gtk-widget-show-all widget)
    (glade-xml-signal-autoconnect xml)
    (gtk-main)))

;; ======================================================================
(define (main args)
  (gtk-gui)
  (eprintf "GTk+ GUI is destroyed.\nBye\n")
  (exit 0))

Download glade-interface.stk

Provided you have the interface.glade file in the current directory, you can run the previous program with:

$ stklos -f glade-interface.stk

Back to Screenshots