GTK for shell scripts: the gtk-server

GTK for shell scripts: the gtk-server

Post by Emphroo » Fri, 02 May 2003 06:24:27



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

Quote:} while (event == 0)

close(GTK_SERVER)
Quote:}

 
 
 

GTK for shell scripts: the gtk-server

Post by Adrian Dav » Fri, 02 May 2003 18:03:18



> Hi,

> I hope someone finds the idea of GUI's for KSH and AWK usefull. If not, please don't read.

Peter,

To create sh/ksh/bash GUI scripts, a little while back I wrote
SATSHELL (See: www.satisoft.com/satshell and for examples
www.satisoft.com/satshell/examples/examples.html). This also uses
STDIO to communicate with the GUI system. SATSHELL is not GTK specific
and will work on most Unix/Linux GUI systems. There's an all new
version due for release soon, which amongst other things, handles
multiple windows and has a number of new and enhanced widgets.

Regards,
   =Adrian=

 
 
 

GTK for shell scripts: the gtk-server

Post by Emphroo » Sat, 03 May 2003 03:44:57


Hey thanks! I am going to check this out.

Peter.

On 1 May 2003 02:03:18 -0700



> > Hi,

> > I hope someone finds the idea of GUI's for KSH and AWK usefull. If not, please don't read.

> Peter,

> To create sh/ksh/bash GUI scripts, a little while back I wrote
> SATSHELL (See: www.satisoft.com/satshell and for examples
> www.satisoft.com/satshell/examples/examples.html). This also uses
> STDIO to communicate with the GUI system. SATSHELL is not GTK specific
> and will work on most Unix/Linux GUI systems. There's an all new
> version due for release soon, which amongst other things, handles
> multiple windows and has a number of new and enhanced widgets.

> Regards,
>    =Adrian=

 
 
 

GTK for shell scripts: the gtk-server

Post by Emphroo » Sat, 03 May 2003 03:57:56


Well, I've received several requests for the source code, but unfortunately I cannot send e-mail with attachments to this newsgroup. If anyone is interested, I need to have the mail address.

I guess I have to setup a site for my gtk-server then.

P.

(PS my mail address is not fake.)

On Wed, 30 Apr 2003 23:24:27 +0200


> 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

> } while (event == 0)

> close(GTK_SERVER)

> }

 
 
 

GTK for shell scripts: the gtk-server

Post by one2001.. » Fri, 23 May 2003 14:57:25



> Hi,

> I hope someone finds the idea of GUI's for KSH and AWK usefull. If not, please don't read.

There is a Ch shell which supports GTK+ and shell programming
already. It is a combination of GTK+ and shell programming
features including awk, sed.

http://www.softintegration.com/docs/ch/shell/
http://www.softintegration.com/products/toolkit/gtk/

Quote:

> 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

> } while (event == 0)

> close(GTK_SERVER)

> }

 
 
 

GTK for shell scripts: the gtk-server

Post by Kevin Rodger » Thu, 25 Sep 2003 07:22:40



> I hope someone finds the idea of GUI's for KSH and AWK usefull. If
> not, please don't read.

When I need a GUI, I resort to Tcl/Tk (tclsh/wish).  Unfortunately, it's

not a POSIX shell...

--
Kevin Rodgers

 
 
 

1. GUI access for shell scripts: the gtk-server

Hi all,

Some time ago I asked if there is a possibility to have GUI access for shell scripts (KSH, AWK, etc...). I was thinking of something similar to DTKSH on Sun or Tru64 Unix (c.q. the Common Desktop Environment).

Though I received a lot of useful suggestions and reactions, none of them filled my needs (sorry...). I decided to program something myself. I did not want to change the sourcecode of existing script interpreters, and I did not feel like implementing 2000 GUI functions either. The concept I thought of, was a kind of server, to which GUI commands can be send (using stdin or a tcp-socket), after which this server takes care of the actual realization of the GUI function. The server in its turn sends info back to the script. I have used GTK as toolkit.

At my website http://www.turtle.dds.nl/gtk-server/ you can download my humble attempts in this direction. Maybe it is of use to somebody else.

Best regards

Peter.

2. RedHat 3.0.3 Hangs During Install

3. GTK guru -> program crashes complaining about gtk.......

4. Quotas on Mail

5. Problems compiling Gtk-0.5120 and Gtk-Perl-0.6123

6. University level class timetable (scheduling) software?

7. Missing gtk-config while blding gvim w/ gtk

8. Where could i get samba?

9. GTK and GTK+

10. rpm problems: gtk vs gtk+

11. xfce installation, gtk vs gtk+

12. guile-gtk and gtk+-1.1.13

13. gtk and gtk+