[gtk-server] Re: Calendar Widget

  • From: "Bill Christiansen" <bill.christiansen@xxxxxxxxx>
  • To: gtk-server@xxxxxxxxxxxxx
  • Date: Sat, 14 Apr 2007 08:17:08 +0800

Hi Peter,
Yes it works great on linux too! Thanks so much for your help and the
working example.

On 4/14/07, Peter van Eerten <administrator@xxxxxxxxxxxxxx> wrote:

Hi Bill,

I took the liberty to completely reorganize your program. First, I
defined the gtk_calender_get_date as follows in 'gtk-server.cfg':

FUNCTION_NAME = gtk_calendar_get_date, NONE, NONE, 4, WIDGET, LONG, LONG,

Then, your program looks as follows (I removed some comments to save
some space):

# Import GTK-server for Unix or Windows and create global symbols for
GTK function names

(if (= (last (sys-info)) 6)
        (import "gtk-server.dll" "gtk")
        (set 'cfgfile (open "gtk-server.cfg" "read")))
        (import "libgtk-server.so" "gtk")
        (set 'cfgfile (open "/etc/gtk-server.cfg" "read"))))

(cond ((not cfgfile)(println "No GTK-server configfile found!

(while (read-line cfgfile)
     (if (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_init NULL NULL)
(gtk_server_glade_file "puppydiary.glade")
(set 'winID (gtk_server_glade_widget "main_window"))
(set 'event (gtk_server_connect winID "delete-event win"))
(set 'exitID (gtk_server_glade_widget "button_exit"))
(set 'event (gtk_server_connect exitID "clicked exit"))
(set 'printID (gtk_server_glade_widget "button_print"))
(set 'event (gtk_server_connect printID "clicked print"))
(set 'entryID (gtk_server_glade_widget "entry1"))
(set 'calendarID (gtk_server_glade_widget "calendar1"))
(set 'event (gtk_server_connect calendarID "day-selected calclick"))

(println "Event: " event) # calclick event ID
(println "calenderID: " calendarID)

# Declare memory - 32 bits
(set 'arg1 (dup "\000" 4))
(set 'arg2 (dup "\000" 4))
(set 'arg3 (dup "\000" 4))

# Mainloop starts here
(while (and (!= event "exit") (!= event "win"))

     (set 'event (gtk_server_callback "wait"))

     (cond ((= event "calclick")
        (set 'tmp (gtk_calendar_get_date calendarID (address arg1)
arg2) (address arg3)))
        (println "Year is: " (get-int arg1))
        (println "Month is: " (get-int arg2))
        (println "Day is: " (get-int arg3))
        # A way of printing the result as a list:
        #(println (unpack "ld" arg1))
        #(println (unpack "ld" arg2))
        #(println (unpack "ld" arg3))
(gtk_exit 0)

Now, when you click on the calender widget, the year, month and date
will be printed on the console.

Please note:

1) This program was only tested in Windows, but should run on Linux as
2) The trick *only* works when using the GTK-server as a Shared Object.


Quoting Bill Christiansen <bill.christiansen@xxxxxxxxx>:

> Well, I set the basic gui up using newLISP and Glade this time but there
> must be something I'm not doing as so far it's working the same as the
> script languages I tried, all the basic stuff is working but I still
> retrieve the date from the calendar.
> #!/usr/bin/newlisp
> #
> # Demonstration on how to use the GTK-server as Shared Object with
> and
> # a glade file.
> # Tested with newLISP 9.1.1 on Puppy Linux 2.14.
> #
> # April 13, 2007, bill dot christiansen at gmail.com
> #------------------------------------------------------------------
> # Setup gtk-server
> (import "libgtk-server.so" "gtk")
> # Optionally enable GTK logging
> (gtk "gtk_server_cfg log")
> # Connect to the GTK-server
> (gtk "gtk_init NULL NULL")
> # Load a Glade File
> (gtk (append "gtk_server_glade_file puppydiary.glade"))
> # Get widget ID of window
> (set 'winID (get-string (gtk "gtk_server_glade_widget main_window")))
> # set the return string for window delete-event
> (set 'event (gtk (append "gtk_server_connect " winID " " "delete-event
> win")))
> #Get the widget ID of the exit button
> (set 'exitID (get-string (gtk "gtk_server_glade_widget button_exit")))
> # set the return string for exit button click event
> (set 'event (gtk (append "gtk_server_connect " exitID " " "clicked
> # Get the widget ID of the save button
> (set 'printID (get-string (gtk "gtk_server_glade_widget button_print")))
> # Set the return string for the save button click event
> (set 'event (gtk (append "gtk_server_connect " printID " " "clicked
> print")))
> # Get the widget ID of entry1
> (set 'entryID (get-string (gtk "gtk_server_glade_widget entry1")))
> # Get the widget ID of the calendar
> (set 'calendarID (get-string (gtk "gtk_server_glade_widget calendar1")))
> # Set the return string for the calendar day-selected event
> (set 'event (gtk (append "gtk_server_connect " calendarID " "
> calclick")))
> (println event) # calclick event ID
> (println calendarID)
> # Mainloop starts here
> (set 'event 0)
> (while (and (!= event "exit") (!= event "win"))
>    (set 'event (get-string (gtk (append "gtk_server_callback WAIT"))))
>    (cond ((= event "calclick")
>    (set 'tmp (get-string (gtk (append "gtk_calendar_get_date "
> calendarID))))
>    (println  tmp)
>    )
>  )
> )
> (gtk "gtk_exit 0")
> (exit)
> With the "(get-string" there I'm getting "ok" returned for any date I
> on and if I take out the "(get-string" I get a number returned that
> corresponds to the number for the click event.
> Bill

Other related posts: