Object Oriented GUI Programming

To program a GUI using an OO aproach, you need the stklos-gtklos package. This package implemenet a model close to the one described iin the JFP and ISOTAS papers.

To install the package, just issue the following command:

$ stklos-pkg --install stklos-gtklos

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

$ stklos-pkg --test stklos-gtklos

Various demo programs are available when running the stklos-gtklos package test.

Exemple

Hereafter is an example of interface built with stklos-gtklos:

The code used to produce this screenshot is:

;;;;
;;;; entry.stk
;;;;

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


(define (main args)
  (let* ((window (make <window> :title "STklos Entry and Events" :border-width 15))
         (box    (make <vbox> :parent window :padding 5 :expand #t))

         (line1  (make <hbox> :parent box))
         (line2  (make <hbox> :parent box))
         (quit   (make <button> :parent box :text "Quit" :command (λ (_) (exit 0))))

         (lab1   (make <label> :parent line1 :text "Only digits: " :width 150))
         (entry1 (make <entry> :parent line1))

         (lab2   (make <label> :parent line2 :text "Convert to upper: " :width 150))
         (entry2 (make <entry> :parent line2)))

    ;; digits entry
    (event-connect entry1 "key-press-event"
                   (lambda (e) (not (char-numeric? (event-char e)))))
    ;; upper entry
    (event-connect entry2 "key-release-event"
                   (lambda (e)
                     (let* ((pos (cursor-position entry2))
                            (val (value entry2))
                            (up  (string-upper val)))
                       (unless (equal? val up)
                         (set! (value entry2) up)
                         (set! (cursor-position entry2) pos)))))

    (gtk-main)))

Download gtklos-entry.stk

Here window is the application container. It contains a vertically arranged box called box. This box contains three children:

Each entry has its own event handler:

You can run this program with the followwing command (provided you have installed the stklos-gtklos package:

$ stklos -f gtklos-entry.stk

Back to Screenshots