#!/usr/local/bin/tcsh # # Create embedded GTK functions for Cshell - see the demo down below how it looks :-) # # (c) Peter van Eerten May 2008, GPL license # # Tested with: # -TCSH 6.15.00 (Astron) on Zenwalk 4.8 and GTK-server 2.2.4 # # May 14, 2008: Initial release # # Put the first part of this file at the start of each of your scripts and # you can use GTK as if you are using the original API. # # Needs AWK because we must parse the configfile. #------------------------------------------------------------------------------------------------- # Pipe filename must be unique for your application set PIPE = /tmp/gtk.csh.\$$ # Find GTK-server configfile first, extend or make smaller if you want if ( -f gtk-server.cfg ) then set CFG=gtk-server.cfg else if ( -f /etc/gtk-server.cfg ) then set CFG=/etc/gtk-server.cfg else if ( -f /usr/local/etc/gtk-server.cfg ) then set CFG=/usr/local/etc/gtk-server.cfg else echo "No GTK-server configfile found! Please install GTK-server..." exit 1 endif # Now create global functionnames from GTK API if ( ! -f $HOME/.gtk4csh || -M $CFG > -M $HOME/.gtk4csh ) then echo "# CSH embedded GTK file" > $HOME/.gtk4csh echo "gtk-server -fifo=$PIPE -detach" >> $HOME/.gtk4csh set FUNCS = `awk '/FUNCTION_NAME/ {print substr($3,1,length($3)-1)}' $CFG` foreach N ($FUNCS) echo alias $N "'"'echo "'$N' \\!*" > '$PIPE'; set R=`cat '$PIPE'`; if ($R != "ok") echo $R'"'" >> $HOME/.gtk4csh end endif # Undeclare variables unset CFG PIPE FUNCS N # Wait for user - remove this line in real applications echo "Press to see the demo..."; set ANSWER = $< #------------------------------------------------------------------------------------------------- # Demo on how it works after integration - we can use genuine GTK functions now #------------------------------------------------------------------------------------------------- # Get all the embedded GTK functions source $HOME/.gtk4csh # Main program, define GUI gtk_init "NULL NULL" set WINDOW = `gtk_window_new 0` gtk_window_set_title $WINDOW 'This is a title' gtk_window_set_position $WINDOW 1 set TABLE = `gtk_table_new 10 10 1` gtk_container_add $WINDOW $TABLE set BUTTON = `gtk_button_new_with_label 'Click here!'` gtk_table_attach_defaults $TABLE $BUTTON 5 9 7 9 set CHECK = `gtk_check_button_new_with_label 'Check this out!'` gtk_table_attach_defaults $TABLE $CHECK 1 6 1 2 set ENTRY = `gtk_entry_new` gtk_table_attach_defaults $TABLE $ENTRY 1 6 3 4 gtk_widget_show_all $WINDOW # Initialize variables set EVENT = 0 # Mainloop while (($EVENT != $BUTTON) && ($EVENT != $WINDOW)) set EVENT = `gtk_server_callback wait` if ($EVENT == $ENTRY) then set TXT = `gtk_entry_get_text $ENTRY` echo $TXT endif end # Exit GTK-server gtk_server_exit