#!/bin/bash
#
# Demonstration on how to use the GTK-server with Gnu AWK by STDIN.
# Tested with Gnu AWK 3.1.3 on Slackware Linux 10.0.
#
# September 27, 2003 by Peter van Eerten.
# Revised for GTK-server 1.2 October 7, 2004
# Revised for GTK-server 1.3 December 4, 2004
#------------------------------------------------
# Start GTK-server in STDIN mode


GTK() {
echo | $GTK_SERVER
 $GTK_SERVER | read $TMP
return TMP
}

GTK_SERVER="gtk-server stdin"

# Design GUI
GTK "gtk_init NULL NULL"
WINDOW=GTK "gtk_window_new 0"
GTK "gtk_window_set_title " WINDOW " \"This is a title\""
GTK "gtk_window_set_default_size " WINDOW " 100 100"
GTK "gtk_window_set_position " WINDOW " 1"
TABLE=GTK "gtk_table_new 30 30 1"
GTK "gtk_container_add " WINDOW " " TABLE
BUTTON1=GTK "gtk_button_new_with_label Exit"
GTK "gtk_table_attach_defaults " TABLE " " BUTTON1 " 17 28 20 25"
BUTTON2=GTK "gtk_button_new_with_label \"Print text\""
GTK "gtk_table_attach_defaults " TABLE " " BUTTON2 " 2 13 20 25"
ENTRY=GTK "gtk_entry_new"
GTK "gtk_table_attach_defaults " TABLE " " ENTRY " 2 28 5 15"
GTK "gtk_widget_show_all " WINDOW

# Connect extra signal
GTK "gtk_server_connect " BUTTON1 " enter Blabla"
GTK "gtk_server_connect " BUTTON2 " enter \"Do not get here\""

# Mainloop
while [[ $EVENT != $BUTTON1 ]] ; do {
	EVENT=GTK "gtk_server_callback wait"

	if [[ $EVENT == $BUTTON2 ]]{
		TMP= GTK"gtk_entry_get_text " ENTRY
		echo "This is the contents: " TMP
	}

	if [[ $EVENT == "Blabla" ]] ; then
	echo "Extra signal for EXIT button!"
	fi
	if [[ $EVENT == "Do not get here" ]] ; then
	echo "Extra signal for PRINT button!"
fi
} 

# Exit GTK without waiting
echo "gtk_exit 0" | GTK_SERVER
close(GTK_SERVER)
fflush
}
