Subject: [clisp-list] A GUI for clisp

From: "Kalsbach, Jörg, fiscus GmbH, Bonn"<[email-masked]>
Date: Thu Apr 22 04:14:22 2004

Hello,

I just ported a script that enables clisp to work with a gui server
(gtk-server). The architecture is a bit clumsy but it works. Perhaps anyone
is interested in gui programming with clisp.

Regards

Jörg Kalsbach

Please don' t write to this mails adress but to:

[email-masked]

;;start of file
;;
;; Demonstration on how to use the GTK-server with clisp
;; Tested with clisp-2.33 on WinXP
;; Requirements: gtk-server installion in this scripts' directory
;; http://www.turtle.dds.nl/gtk-server/
;; April 22, 2004 by Jörg Kalsbach ported from:
;;
;; Demonstration on how to use the GTK-server with NEWLISP by FIFO.
;; Tested with newLISP 7.5.12 on Slackware Linux 9.1.
;;
;; March 28, 2004 by Peter van Eerten.
;;
;;------------------------------------------------

;; Start the gtk-server
(ext:run-program "gtk-server" :arguments '("localhost:50000") :wait nil)

;; Define communication function
(defun gtk (str)
  (princ str socket)
  (read-line socket))

;; Wait a little so the server can initialize
(sleep 1)

;; get a communication channel
(defconstant socket (socket:socket-connect 50000))

;; Design the GUI
(gtk "gtk_init(NULL, NULL)")
(set 'win (gtk "gtk_window_new(0)"))
(gtk (concatenate 'string "gtk_window_set_title (" win ", This is a
title)"))
(gtk (concatenate 'string "gtk_window_set_default_size (" win ", 100,
100)"))
(gtk (concatenate 'string "gtk_window_set_position (" win ", 1 )"))
(set 'table (gtk "gtk_table_new(30, 30, 1 )"))
(gtk (concatenate 'string "gtk_container_add (" win "," table ")"))
(set 'button1 (gtk "gtk_button_new_with_label (Exit)"))
(gtk (concatenate 'string "gtk_table_attach_defaults(" table ", " button1 ",
17, 28, 20, 25)"))
(set 'button2 (gtk "gtk_button_new_with_label (Print text)"))
(gtk (concatenate 'string "gtk_table_attach_defaults (" table ", " button2
", 2, 13, 20, 25)"))
(set 'entry (gtk "gtk_entry_new()"))
(gtk (concatenate 'string "gtk_table_attach_defaults (" table ", " entry ",
2, 28, 5, 15)"))
(gtk (concatenate 'string "gtk_widget_show_all(" win ")"))

;; This is the mainloop
(do ((event1 "0"(set 'event1 (gtk (concatenate 'string
"gtk_server_callback(" button1 ")")))) 
     (event2 "0" (set 'event2 (gtk (concatenate 'string
"gtk_server_callback(" win ")")))))
    ((not (and (= (parse-integer event1) 0) (= (parse-integer event2) 0))))
    (gtk "gtk_main_iteration()")
    (set 'tmp (gtk (concatenate 'string "gtk_server_callback(" button2
")")))
    (if (> (parse-integer tmp) 0)
	(progn
	  (set 'tmp (gtk (concatenate 'string "gtk_entry_get_text(" entry
")")))
	  (print (concatenate 'string "This is the contents: " tmp))))
    )

;; Exit GTK explicitly only with a write
(princ "gtk_exit(0)" socket)
;;end of file

---

From: Sam Steingold <[email-masked]>
Date: Thu Apr 22 07:07:18 2004

> * Kalsbach, Jörg, fiscus GmbH, Bonn <[email-masked]> [2004-04-22 13:13:26 +0200]:
>
> (gtk-server). The architecture is a bit clumsy but it works.

Thanks, I will add a reference to the CLISP FAQ!

some stylistic notes to make your code more like Common Lisp:

1.  define SOCKET before GTK to avoid compiler warning, define it with
    DEFVAR or DEFPARAMETER and name it with stars: *SOCKET*

2.  use SETQ instead of SET:
        (setq win (gtk "gtk_window_new(0)"))

3.  replace (if ... (progn ...)) with (when ... ...)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
If you think big enough, you'll never have to do it.