Hi,
I hope someone finds the idea of GUI's for KSH and AWK usefull. If not, please don't read.
After searching for a 'dtksh' replacement in Linux, I found disappointing results. There is a thing called "xdialog" which is able to show GUI's, but only dialog-type, and using GTK1.2 (see http://xdialog.dyns.net/). There is a project called "guis" (http://www.starynkevitch.net/Basile/guisdoc.html), which is a GUI server, but this is embedded in a scripting language called LUA. Furthermore there are projects like PicoGUI (http://picogui.org/) and Entity (http://entity.cx/index.html) but these projects use XML to define the widgets.
All in all, unless you are using CDE, there seems to be no easy possibility to create Graphical User Interfaces with KSH or AWK. It seems there is no other way than to adjust the source code of KSH or AWK, so a GUI implementation is possible. With Gnu AWK there is a module-structure which allows a programmer to add functionality to AWK. However, this structure will be revised in the 3.2 release of Gnu AWK.
So there was nothing else to do than to create an all-round widgetserver myself. Do not take a close look at the source code, actually it is a quick hack to see if it is possible to create a 'gtk-server', with which AWK and KSH scripts can communicate. I am not using TCP or UDP sockets, just plain stdin and stdout. I think of my implementation as a proposition, on how GUI-programming can be implemented without too much fuzz.
Below an example of a KSH script, showing a small dialog box. I also wrote an AWK example. Of course you need to know how GTK works, since the gtk-server is implementing original gtk API calls. Please refer to the GTK Reference Manual for further explanation (http://www.gtk.org).
Finally, the gtk-server is implementing just a few API calls right now, and it needs a lot of work before it is complete. If anyone finds the examples below interesting, please respond to this posting in this newsgroup and I will e-mail the C source code and Makefile of the gtk-server to this newsgroup. You need GTK 2.0 or higher to compile it. Not suitable for Windows of course.
Best regards
Peter.
==================================================================
#!/bin/ksh
#
# KSH demo on how to use the gtk-server
#
./gtk-server |&
print -p "gtk_init()"; read -p TMP
print -p "gtk_window_new"; read -p WINDOW
print -p "gtk_window_set_title (" $WINDOW ", This is a title)"; read -p TMP
print -p "gtk_table_new (10, 10, TRUE )"; read -p TABLE
print -p "gtk_container_add(" $WINDOW "," $TABLE ")"; read -p TMP
print -p "gtk_widget_show(" $TABLE ")"; read -p TMP
print -p "gtk_button_new_with_label(Button with label)"; read -p BUTTON
print -p "gtk_table_attach_defaults(" $TABLE ", " $BUTTON ", 5, 9, 5, 9)"; read -p TMP
print -p "gtk_widget_show(" $BUTTON ")"; read -p TMP
print -p "gtk_widget_show(" $WINDOW ")"; read -p TMP
EVENT=0
while [[ $EVENT -eq 0 ]]
do
print -p "gtk_main_iteration"; read -p TMP
print -p "gtk_server_clicked_event(" $BUTTON ")"; read -p EVENT
done
==================================================================
#!/usr/bin/gawk -f
BEGIN{
GTK_SERVER = "gtk-server"
print "gtk_init" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_window_new" |& GTK_SERVER; GTK_SERVER |& getline WINDOW
print "gtk_window_set_title (" WINDOW ", This is a title)" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_window_set_default_size (" WINDOW ", 100, 100)" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_window_set_position (" WINDOW ", GTK_WIN_POS_CENTER )" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_table_new(30, 30, TRUE )" |& GTK_SERVER; GTK_SERVER |& getline TABLE
print "gtk_container_add (" WINDOW "," TABLE ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_widget_show (" TABLE ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_button_new_with_label (Exit)" |& GTK_SERVER; GTK_SERVER |& getline BUTTON1
print "gtk_table_attach_defaults(" TABLE ", " BUTTON1 ", 17, 28, 20, 25)" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_widget_show(" BUTTON1 ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_button_new_with_label (Print text)" |& GTK_SERVER; GTK_SERVER |& getline BUTTON2
print "gtk_table_attach_defaults (" TABLE ", " BUTTON2 ", 2, 13, 20, 25)" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_widget_show(" BUTTON2 ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_entry_new" |& GTK_SERVER; GTK_SERVER |& getline ENTRY
print "gtk_table_attach_defaults (" TABLE ", " ENTRY ", 2, 28, 5, 15)" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_widget_show(" ENTRY ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_widget_show(" WINDOW ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
event = 0
do {
print "gtk_main_iteration" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "gtk_server_clicked_event(" BUTTON2 ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
if (TMP){
print "gtk_entry_get_text(" ENTRY ")" |& GTK_SERVER; GTK_SERVER |& getline TMP
print "This is the contents: " TMP
}
print "gtk_server_clicked_event(" BUTTON1 ")" |& GTK_SERVER; GTK_SERVER |& getline event
close(GTK_SERVER)Quote:} while (event == 0)
Quote:}