First, the "plain vanilla" variant: Believe it or not, there is even an experimental multithreaded variant of this program among the examples bundled with lgtk. |
;; Hello World #1 from the GTK+tutorial.
(use-package :gtk)
(defun hello-world ()
(labels ((hw (&rest args)
(format t "Hello world!~%"))
(delete-event (&rest args)
(format t "delete-event ocurred~%")
nil)
(destroy (&rest args)
(format t "self-destruct.~%")
(gtk-main-quit)))
(let ((window (gtk-window-new :gtk-window-toplevel))
(button (gtk-button-new-with-label "Hello World!")))
(gtk-container-add window button)
(gtk-container-set-border-width window 10)
(gtk-widget-show button)
(gtk-widget-show window)
(g-signal-connect button gtkclicked #'hw)
(g-signal-connect window gtkdelete-event #'delete-event)
(g-signal-connect window gtkdestroy #'destroy)
(gtk-main))))
|
Then, we have the two-way bibuttoned multidispatch "Hello World" featuring
a different messages on each button.![]() The source code to this one is also on the right. |
(use-package :gtk)
(defun hello-world2 ()
(labels ((callback (wid num)
(declare (ignore wid))
(format t "Hello again - ~s was pressed.~%" num))
(delete-handler (&rest stuff)
(declare (ignore stuff))
(gtk-main-quit)
nil)) ;; aka false
(let ((window (gtk-window-new :gtk-window-toplevel))
(button1 (gtk-button-new-with-label "Button 1"))
(button2 (gtk-button-new-with-label "Button 2"))
;; This is a bit different. Arguments with a reasonable
;; default where transformed into keyword args.
(box (gtk-hbox-new :homogeneous t :spacing 4)))
;; Title
(gtk-window-set-title window "Hello Buttons!")
;; Border width
(gtk-container-set-border-width window 10)
;; Put things together
(gtk-container-add window box)
(gtk-box-pack-start box button1 :expand t :fill t :padding 10)
(gtk-box-pack-start box button2)
;; Handlers and callbacks
(g-signal-connect window gtkdelete-event #'delete-handler)
(g-signal-connect button1 gtkclicked #'callback :data 1)
(g-signal-connect button2 gtkclicked #'callback :data 2)
;; display
(gtk-widget-show button1)
(gtk-widget-show button2)
(gtk-widget-show box)
(gtk-widget-show window)
;; main loop
(gtk-main))))
|
Mario
S. Mommer
Last modified: 27.10.2003