#!/usr/bin/newlisp # # Create embedded GTK functions for newLisp - see the demo down below how it looks :-) # # (c) Peter van Eerten 2006, GPL license # # Tested with: # - newLisp on Zenwalk 3.0 # - newLisp on Windows2000 # # October 8, 2006: Initial release #--------------------------------------------------------------------------------------- # Import GTK-server for Unix or Windows and create global symbols for GTK function names (if (= (last (sys-info)) 6) (begin (import "gtk-server.dll" "gtk") (set 'cfgfile (open "C:\\GTK-server\\gtk-server.cfg" "read"))) (begin (import "libgtk-server.so" "gtk") (set 'cfgfile (open "/etc/gtk-server.cfg" "read")))) (cond ((not cfgfile)(println "No GTK-server configfile found! Exiting...")(exit))) (while (read-line cfgfile) (when (starts-with (current-line) "FUNCTION_NAME") (set 'func (chop ((parse (current-line) " ") 2))) (set 'lb (append {(lambda()(setq s "} func {")(dolist (x (args))(setq s (string s " " x)))(get-string (gtk s)))})) (constant (global (sym func)) (eval-string lb)))) (close cfgfile) (constant (global 'NULL) "NULL") #------------------------------------------------------- Demo program (gtk_server_cfg "log") (gtk_init NULL NULL) (set 'win (gtk_window_new 0)) (gtk_window_set_title win "'This is a title'") (gtk_window_set_default_size win 100 100) (gtk_window_set_position win 1) (set 'table (gtk_table_new 30 30 1)) (gtk_container_add win table) (set 'button1 (gtk_button_new_with_label "Exit")) (gtk_table_attach_defaults table button1 17 28 20 25) (set 'button2 (gtk_button_new_with_label "'Print text'")) (gtk_table_attach_defaults table button2 2 13 20 25) (set 'entry (gtk_entry_new)) (gtk_table_attach_defaults table entry 2 28 5 15) (gtk_widget_show_all win) # Mainloop starts here (set 'event 0) (while (and (!= event button1) (!= event win)) (set 'event (gtk_server_callback "WAIT")) (if (= event button2) (begin (set 'tmp (gtk_entry_get_text entry)) (println "This is the contents: " tmp) ) ) ) (gtk_exit 0) (exit)