[gtk-server] Re: Calendar Widget

  • From: "Bill Christiansen" <bill.christiansen@xxxxxxxxx>
  • To: gtk-server@xxxxxxxxxxxxx
  • Date: Fri, 13 Apr 2007 19:11:28 +1200

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 other
script languages I tried, all the basic stuff is working but I still can't
retrieve the date from the calendar.

# Demonstration on how to use the GTK-server as Shared Object with newLISP
# 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
#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 exit")))
# 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
# 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 " " "day-selected

(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 "
   (println  tmp)

(gtk "gtk_exit 0")

With the "(get-string" there I'm getting "ok" returned for any date I click
on and if I take out the "(get-string" I get a number returned that
corresponds to the number for the click event.


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

Hi Bill,

In newLisp you can append additional quotes, as follows:

(gtk_window_set_title win (append {"} tmp {"}))


(gtk_window_set_title win (append {'} tmp {'}))


(gtk_window_set_title win (append "'" tmp "'"))


Quoting Bill Christiansen <bill.christiansen@xxxxxxxxx>:

> Hi Peter,
> I decided to try your tip about newLISP as the other languages I tried
> didn't get me any further than with BASH. (I may have been doing it
> Just wondered though if you know of a simple fix for the following
> situation:
> (set 'tmp (gtk_entry_get_text entry))
>        (println "This is the contents: " tmp)
>        (gtk_window_set_title win " " tmp)
> I read the text from a text entry widget and print it to the console as
> as changing the window title  with the same variable which works except
> the string in tmp contains any spaces only the first word goes to the
> In BASH I could fix that with double and single quotes: "'$tmp'", but
> doesn't work in newLISP.
> Bill
> On 4/8/07, Peter van Eerten <administrator@xxxxxxxxxxxxxx> wrote:
>> Hi there,
>> The reason for the '-1' returnvalue is, that you need to add the
>> prototype of the call 'gtk_calender_get_date' to the configfile of the
>> GTK-server.
>> I would define it as follows:
>> FUNCTION_NAME = gtk_calender_get_date, NONE, NONE, 4, WIDGET, LONG,
>> However, the last three arguments are in fact pointers to memory, as
>> you also mention yourself. With BASH I do not see how the memory
>> pointed to can be read. There are some interpreted languages though,
>> which can 'read' memory assigned by C-pointers, like Perl, or newLisp.
>> In most situations, when a signal occurs on the widget, it is possible
>> to read the data which was sent with the signal. But with the calender
>> widget also no additional data is sent.
>> For BASH, as workaround you could write a small C program and compile
>> it as a binary. When this binary is invoked within a BASH script, it
>> reads the argument which in fact is the pointer to the address, and it
>> returns the value kept in this address. But this is probably not what
>> you want.
>> Regards
>> Peter
>> Quoting Bill Christiansen <bill.christiansen@xxxxxxxxx>:
>>> Hi,
>>> I'm not a very experienced programmer but just giving the Gtk-server,
>> BASH,
>>> Glade combination a try.
>>> The GUI I made in Glade has a calendar widget and I can retrieve it's
>> widget
>>> ID and access it's day_clicked event:
>>> # Get calendar widget ID and connect signal
>>> gtk "gtk_server_glade_widget calendar1"
>>> calendar1_ID=$RESULT
>>> gtk "gtk_server_connect $calendar1_ID day-selected calendar_clicked"
>>> But when I try to use get_date I am getting "-1" returned:
>>> # Initialize EVENT variable
>>> EVENT=0
>>> # Mainloop
>>> while [[ $EVENT != "main_window" && $EVENT != "button_exit" ]]
>>> do
>>>    gtk "gtk_server_callback WAIT"
>>>    if [[ $EVENT = "calendar_clicked" ]]
>>>    then
>>>        gtk "gtk_calendar_get_date $calendar1_ID"
>>>        text="'$RESULT'"
>>>        echo $text  # this is printing "-1" on console
>>>    fi
>>> done
>>> It may be that I need to process the $RESULT more as the GTK docs say
>>> returns a tuplet of three integers for year month day, but may BASH
>> knowlege
>>> is also limited at this stage, or is it because the calendar widget
>> needs to
>>> be setup in the gtk-server.cfg to be usable. Anyone else have
>>> with this widget?
>>> Regards
>>> Bill
>> --
>> http://www.gtk-server.org


Other related posts: