Object Oriented GUI Programming
To install the package, just issue the following command:
Before using this package, you can test that everything works with the following command:
Various demo programs are available when running the
stklos-gtklos package test.
Hereafter is an example of interface built with
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)))
window is the application container. It contains a vertically arranged box called
box. This box contains three children:
line1, a horizontally arranged box container;
line2, another horizontally arranged box container and
quit, a button which stops the program when it is pressed (by calling the
entry1are a label and an entry box embedded in
entry2are a label and an entry box embedded in
Each entry has its own event handler:
- the first entry accepts only numerical characters.
- the second entry converts lowercase characters to uppercase on the fly.
You can run this program with the followwing command (provided you have installed the