From the creator of BaCon - gtk-server

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

From the creator of BaCon - gtk-server

#1 Post by jamesbond »

http://www.gtk-server.org/

According to the Introduction page:
This is the homepage of the GTK-server. The GTK-server is a free, open-source project, which offers a stream-oriented interface to the GTK libraries, enabling access to graphical user interfaces for shellscripts and interpreted programming languages using either GTK 1.x or 2.x. It was inspired by Sun's DeskTop KornShell (dtksh) of the Common Desktop Enviroment (CDE) for Unix.
And the benefits are:
Below a summary of advantages when using the GTK-server.
- No need to learn C or C++, you can stick to your favorite programming language
- No need to hack the source of existing interpreters to realize GUI programming
- High flexibility in creating GUI's, e.g. not limited to dialogs
- Full GTK API available, the user can extend the 'gtk-server.cfg' file by himself
- Access to both GTK 1.x and GTK 2.x
- Convenient GTK test tool, easy to learn GTK programming
- Mix 64-bit userinterfaces with your 32-bit client programs
What the difference between gtk-server and all other GUI dialogs?
1. Xdialog, yad, zenity, are more or less the same thing - they are all single-shot GUI dialog maker - display a dialog, user clicks something, close dialog and return values.
2. gtkdialog is much more flexible - it builds and runs the GUI. It responds to user interaction with GUI - either by executing internal actions, or calling external programs. It only quits then told to quit.
3. gtk-server is very much like gtkdialog - except, one has full access to entire GTK+ functions. The other difference is that the GUI component and the actual application code is totally separate, they are not inter-mixed as in gtkdialog.

gtk-server does require higher learning curve than gtkdialog because one needs to know GTK itself to write stuff with it. But the payback is that one has much more finer-grained control over the GUI compared to gtkdialog. gtk-server also opens the possibility of designing the GUI using a GUI builder (e.g. glade) instead of writing code, and only write code for interaction with the external applications. There are other interesting non-gtk stuff you can do with it - I won't spoil that for you, go and explore the site if you're interested :)

Did I mention this is also from the creator of BaCon (Peter van Eerten)? :D

cheers!
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#2 Post by sunburnt »

Looks very interesting, I`ll check this out for sure.
I dislike the underline_syntax_of_GTK. But a wrapper will fix that.
GUI component and the actual application code is totally separate
This is how I`ve written most of my gtkDialog apps.

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#3 Post by jamesbond »

sunburnt, you can change the names to anyone you want - for example, the clock.bash demo creates /root/.gtk4bash file that contains all the functions exported in gtk-server.cfg as bash functions. You can of course modify this process (using sed or something) and make them CamelCase and/or remove the underscores :)

For others - gtk-server comes many examples, I'll just mention two of them that I think is notable:
a) clock.bash - draw a working analog clock
b) tetris.bash - of course, the infamous tetris

Which, as far as I'm aware, require the level of flexibility and interaction won't be possible with gtkdialog. (Note the above are plain bash scripts - no tricks).

cheers!
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#4 Post by sunburnt »

Typical, did the setup and nothing works.

gtk-server and kill-gtk-server are in the path.
gtk-server.cfg is in: /usr/local/etc

Run any demo script and the error is: Arguments to GTK-server not recognized!

The docs talk about making the script and the cfg file both.
Isn`t just "gtk-server.cfg.new" renamed to "gtk-server.cfg" in "/usr/local/etc" good?

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#5 Post by jamesbond »

Pet compiled in Wary 5.0. One thing I like from here is that one can use glade to build the GUI instead of hand-coding it (the calculator example).

cheers!
Attachments
gtk-server-2.3.1-i486.pet
Compiled in Wary 5.0
(71.36 KiB) Downloaded 713 times
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#6 Post by sunburnt »

Hey J.B.; The demos work now! Running Puppy511, will try it in Puppy528 too.

Now I need to get a handle on what`s going on with it. The big picture...
What`s required for the header code to get a Bash script working with it.
And the structure of the widget creation code and the methods for them.
Usually it`s pretty clear how the code works, but this is a bit more complex.

Thanks again... Terry

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

simplest bash code example from gtk-server website

#7 Post by mcewanw »

The following is a copy of the simplest bash usage example for gtk-server from http://www.gtk-server.org/demo-fifo.bash.txt. This uses a FIFO (named PIPE called "/tmp/bash.gtk") for sending and receiving messages between the bash script and gtk-server. This is done in the function below called "gtk()". This simple example just draws a window with a single button on the screen. Note that for Puppy Wary, at least, the first line could be changed to #!/bin/bash though /usr/bin/bash is a symbolic link to that anyway:

Code: Select all

#!/usr/bin/bash
#
# Bourne shell named pipe demo with the GTK-server
# Tested with BASH 3.1 on Zenwalk Linux 4.2
#
# March 14, 2004 by Peter van Eerten
# Revised at july 25, 2004
# Revised for GTK-server 1.2 October 7, 2004
# Revised for GTK-server 1.3 December 4, 2004
# Revised for GTK-server 2.0.6 at december 17, 2005
# Revised for GTK-server 2.0.8 at january 7, 2006
# Revision at january 15, 2007
#------------------------------------------------

# Define SIGUSR1 in configfile to catch the signal
trap 'exit' SIGUSR1

# Name of PIPE file
declare PIPE=/tmp/bash.gtk

# Communicate with GTK-server
gtk()
{
echo $1 > $PIPE
read RESULT < $PIPE
}

#------------------------ Main starts here

# Start gtk-server
gtk-server -fifo=$PIPE -detach

# Setup GUI
gtk "gtk_init NULL NULL"
gtk "gtk_window_new 0"
WIN=$RESULT
gtk "gtk_window_set_title $WIN 'BASH GTK-server demo'"
gtk "gtk_window_set_default_size $WIN 400 200"
gtk "gtk_window_set_position $WIN 1"
gtk "gtk_table_new 10 10 1"
TBL=$RESULT
gtk "gtk_container_add $WIN $TBL"
gtk "gtk_button_new_with_label 'Click to Quit'"
BUT=$RESULT
gtk "gtk_table_attach_defaults $TBL $BUT 5 9 5 9"
gtk "gtk_widget_show_all $WIN"

EVENT=0

# Mainloop
while [[ $EVENT -ne $BUT && $EVENT -ne $WIN ]]
do 
    gtk "gtk_server_callback WAIT"
    EVENT=$RESULT
done

# Exit GTK
gtk "gtk_server_exit"
Quote from http://www.gtk-server.org/intro.html:
How does it work? The GTK-server can be compiled as a standalone binary, which is able to communicate by a message queue, a 2-way pipe, a named pipe or by a TCP/UDP port. The script invokes this binary, sets up a queue, pipe or a TCP/UDP connection and prints the GTK call in plain text to the queue, pipe or socket. The GTK-server then sends information back which can be used in the program or script.
Very interesting. I'm used to this type of programming having once developed an Inter Process Comms utility called wiak (written in C) which allows bash to use either message queues or pipes to communicate between separate processes (GPL license). I used wiak to communicate between a bash/gtkdialog3 client and a bash backend server(i.e. a client/server arrangement to simplify the client GUI side) using either message queues or named pipes (fifos):

http://murga-linux.com/puppy/viewtopic. ... 550#151783

http://wiak.org
Last edited by mcewanw on Tue 11 Oct 2011, 22:21, edited 3 times in total.
github mcewanw

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#8 Post by sunburnt »

I tried to make gtk-server work for stdin, but apparently it won`t work in Bash.
The only examples for stdin are for awk and a few others, but it should work.
Peter states that stdin is the most reliable communication method.
This makes sense, I`ve worked with pipes before and they`re finicky.

I`m working on a mod. to simplify the syntax so "define" isn`t needed to
create widgets, and .gtk4bash and the config. files aren`t needed also.
But I`m stuck...

And then I have a template for generic GUI creation
All the startup stuff in an "init" file, starting gtk-server and create first window.
Then the user`s GUI code in a second "gui" file, just the widgets and properties.
And then there`s the main display loop and quit code in the "main" file.
This way all the user does is write the gtk-server GUI code in the "gui" file.

Once this is working I will write a syntax wrapper to improve the coding.
And then I`d like to write a Visual IDE for the whole thing ( kinda like Glade ).

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#9 Post by mcewanw »

sunburnt wrote:... I`ve worked with pipes before and they`re finicky.
Yes, named pipes can be messy and have limitations.

However, the example below is in fact using stdin to get the gtk-server result back into the bash variable RESULT:

Code: Select all

# Communicate with GTK-server
gtk()
{
RESULT=`gtk-server msg=$$,"$@"`
}
This extract is from the ipc demonstration script:

http://www.turtle.dds.nl/gtk-server/demo-ipc.bash.txt

It seems to be using a message queue between two gtk-server processes, one of which writes RESULT to stdout for reading by bash. Bash itself only provides direct access to named pipes (FIFOS), not message queues (I wrote "wiak" to give bash message queue access).

EDIT:

The awk (gawk) "gtk-server -stdin" example(s) you refer to are presumably also using the special "two-way pipe" feature provided by gawk, not just stdin alone, which is presumably why bash needs to use named pipes or gtk-server message queues:

From http://www.gnu.org/s/gawk/manual/gawk.h ... d-Features
However, with gawk, it is possible to open a two-way pipe to another process. The second process is termed a coprocess, since it runs in parallel with gawk. The two-way connection is created using the ‘|&’ operator
The example gawk script (change top line #!/usr/bin/gawk -f so that it points to #!/bin/gawk on Puppy to make it work):

http://www.turtle.dds.nl/gtk-server/demo-stdin.awk.txt

code extract:

Code: Select all

function GTK(str)
{
print str |& GTK_SERVER
GTK_SERVER |& getline TMP
return TMP
}
github mcewanw

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#10 Post by Lobster »

simplest bash usage example
This and the pet provided by James Bond worked in Slacko RC++

8)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#11 Post by mcewanw »

Lobster wrote:
simplest bash usage example
This and the pet provided by James Bond worked in Slacko RC++

8)
Because named pipes can be messy, I would suggest that it is probably better to use the ipc message queue method in practice.

Here is a copy of the example of ipc message queue method from
http://www.turtle.dds.nl/gtk-server/demo-ipc.bash.txt. Note that bash itself uses stdin to read into variable RESULT:

Code: Select all

#!/bin/sh
#
# Bourne shell IPC demo with the GTK-server
#
# November 12, 2006 - (c) Peter van Eerten
#
# As unique communication channel the current PID
# number '$$' is used.
#------------------------------------------------

# Communicate with GTK-server
gtk()
{
RESULT=`gtk-server msg=$$,"$@"`
}

#------------------------ Main starts here

# Start gtk-server in IPC mode
gtk-server -ipc=$$ -detach

# Setup GUI
gtk "gtk_init NULL NULL"
gtk "gtk_window_new 0"
WIN=$RESULT
gtk "gtk_window_set_title $WIN 'Bourne GTK-SERVER demo'"
gtk "gtk_window_set_default_size $WIN 400 200"
gtk "gtk_window_set_position $WIN 1"
gtk "gtk_table_new 10 10 1"
TBL=$RESULT
gtk "gtk_container_add $WIN $TBL"
gtk "gtk_button_new_with_label 'Click to Quit'"
BUT=$RESULT
gtk "gtk_table_attach_defaults $TBL $BUT 5 9 5 9"
gtk "gtk_widget_show_all $WIN"

EVENT=0

# Mainloop
while [ $EVENT -ne $BUT ]
do 
    gtk "gtk_server_callback WAIT"
    EVENT=$RESULT
done

# Exit GTK-server
gtk "gtk_server_exit"
EDIT:

But there is one disadvantage to using the gtk-server -ipc mode instead of the gtk-server -fifo mode, it requires two gtk-server processes to be running simultaneously, which increases memory usage.:

Code: Select all

31683 root       0:00 gtk-server -ipc 31680 -detach
31702 root       0:11 gtk-server msg=31680 gtk_server_callback WAIT
You don't have that extra memory usage problem with the -fifo method because bash can talk directly to fifos, nor do you have it with the awk (gawk) version since, as I said in post up above, gawk can communicate directly via a two-way pipe with gtk-server.
github mcewanw

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#12 Post by mcewanw »

The key to how it all works is to send simple messages to the running gtk-server. As can be seen by the provided examples, the messages are of the form:

Code: Select all

"gtk_init NULL NULL"
"gtk_window_new 0"
"gtk_window_set_default_size $WIN 400 200"
...
and so on...
github mcewanw

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#13 Post by sunburnt »

The awk example you pointed to is the one I was thinking of.
It makes no named pipe at all, it only connects to gtk-server with stdin.
As Peter points out, it uses "|&" to communicate, Bash doesn`t like it.

Seems like there would be some way to connect simply with "|".
After all, gtk-server just takes GTK+ commands and returns the handle ID.

Hopefully I`ll find out why my mod. won`t work, code looks good.
Script reads the GTK code with a loop and communicates with gtk-server.
It errors at every "property" command ( ID problem I think...):

Code: Select all

(<unknown>:3802): Gtk-CRITICAL **: gtk_window_set_position: assertion `GTK_IS_WINDOW (window)' failed
This is the command line "echo", shouldn`t "$winMAIN" be the ID number?

Code: Select all

gtk_window_set_title $winMAIN "Win._Title"

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#14 Post by mcewanw »

sunburnt wrote:The awk example you pointed to is the one I was thinking of.
It makes no named pipe at all, it only connects to gtk-server with stdin.
As Peter points out, it uses "|&" to communicate
Bash doesn't make a pipe, but awk does.

As I said above, the construct "|&" is in fact a special pipe construct used in the awk programming language. There is no equivalent to it in bash. A simple "|" is not the same thing (it is not a fifo), and will not work here. Bash itself would need to use either a fifo or a message queue to communicate with gtk-server.

However, I see no reason why you could not combine the two ideas together, in the sense that you could call up awk (gawk) from within a standard bash script to handle the (piped) communication with gtk-server - using the awk "|&" construct. Of course the awk process will temporarily add to the resource usage, but otherwise, I feel that calling awk from inside bash might be quite an elegant approach.

I also wonder why gtk-server needs to use fifos or message queues. If I get round to looking at the source code I'll report back. Maybe the docs have some details - I haven't checked.

EDIT

Seems like should indeed be usable with stdin only.. There is a Korn shell example here. Should be trivial to modify it to bash:

http://en.wikipedia.org/wiki/GTK-server

EDIT2... Hmm... maybe not....

Korn shell also uses |& to provide a coprocess pipe sort of facility...

Quote from http://www.well.ox.ac.uk/~johnb/comp/un ... oprocesses
One can have one background process with which one can comunicate with read -p and print -p. It is started with command |&. If one uses: ksh |& then this shell in the background will do everything for us even telnet and so on: print -p "telnet hostname".
So I guess a named pipe or message queue is required to provide a "blocking buffer facility" whilst the receiving process waits on a message.

From the gtk-server "Quickstart Manual" at http://gtk-server.org/GTK-server_Manual.html we are informed:
Both the Linux version and the Windows version of the GTK-server support communication by a 2-way pipe, named pipe, TCP and UDP. In case of a 2-way pipe, the GTK-server must be started with the argument 'stdin'. In case of a named pipe, the GTK-server must be started with the argument 'fifo', after which the name of the pipe must be mentioned. In Windows, the name of the named pipe can be omitted; the GTK-server will setup 2 independent pipes, with the predefined names "\\.\pipe\out" and "\\.\pipe\in". Finally, to enable TCP or UDP communication, the argument must be of the format '<-tcp=ipaddress:port>' or '<-udp= ipaddress:port>'
I suspect the bash 4 coproc command could be used to replace the Korn sh |& syntax, but I haven't had time to try that yet:

http://www.gnu.org/s/bash/manual/html_n ... esses.html

http://tldp.org/LDP/abs/html/bashver4.html
There is a new 'coproc' reserved word that specifies a coprocess:
an asynchronous command run with two pipes connected to the creating
shell. Coprocs can be named. The input and output file descriptors
and the PID of the coprocess are available to the calling shell in
variables with coproc-specific names
Yep, that should do it. Easy to modify the above Korn shell example now. But I have to sleep now.
github mcewanw

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#15 Post by jamesbond »

mcewanw wrote:I suspect the bash 4 coproc command could be used to replace the Korn sh |& syntax, but I haven't had time to try that yet:

http://www.gnu.org/s/bash/manual/html_n ... esses.html

http://tldp.org/LDP/abs/html/bashver4.html
There is a new 'coproc' reserved word that specifies a coprocess:
an asynchronous command run with two pipes connected to the creating
shell. Coprocs can be named. The input and output file descriptors
and the PID of the coprocess are available to the calling shell in
variables with coproc-specific names
Yep, that should do it. Easy to modify the above Korn shell example now. But I have to sleep now.
If you can get this to work, it would be interesting. I don't like to trap SIGINT while the script is waiting to read the pipe - I'll end up having to kill both the scripts and the gtk-server manually :?
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#16 Post by mcewanw »

jamesbond wrote:If you can get this to work, it would be interesting.
Unfortunately, Puppy Wary uses bash 3.

coproc functionality comes with bash 4...

But it seems to me that using awk is fine anyway, or a mixture of awk and bash version 3.

Awk is a powerful programming language. Puppy users may be more familiar with bash, but awk is there on the system and not a memory hog when running, so perfectly good for programming gtk-server GUIs. So maybe this is a good time to practice/learn awk...

Quote from http://www.ibm.com/developerworks/linux ... index.html
Sure, awk doesn't have a great name. But it is a great language. Awk is geared toward text processing and report generation, yet features many well-designed features that allow for serious programming. And, unlike some languages, awk's syntax is familiar, and borrows some of the best parts of languages like C, python, and bash (although, technically, awk was created before both python and bash). Awk is one of those languages that, once learned, will become a key part of your strategic coding arsenal.
http://www.grymoire.com/Unix/Awk.html:
Why is AWK so important? It is an excellent filter and report writer. Many UNIX utilities generates rows and columns of information. AWK is an excellent tool for processing these rows and columns, and is easier to use AWK than most conventional programming languages. It can be considered to be a pseudo-C interpretor, as it understands the same arithmatic operators as C. AWK also has string manipulation functions, so it can search for particular strings and modify the output. AWK also has associative arrays, which are incredible useful, and is a feature most computing languages lack. Associative arrays can make a complex problem a trivial exercise.

http://www.vectorsite.net/tsawk_1.html#m1:
Awk statements comprise a programming language. In fact, Awk is useful for simple, quick-and-dirty computational programming. Anybody who can write a BASIC program can use Awk, although Awk's syntax is different from that of BASIC. Anybody who can write a C program can use Awk with little difficulty, and those who would like to learn C may find Awk a useful stepping stone -- with the caution that Awk and C have significant differences beyond their many similarities.

There are, however, things that Awk is not. It is not really well suited for extremely large, complicated tasks. It is also an "interpreted" language -- that is, an Awk program cannot run on its own, it must be executed by the Awk utility itself. That means that it is relatively slow, though it is efficient as interpretive languages go, and that the program can only be used on systems that have Awk.
As an example of memory usage, here is an extract from "top" showing the earlier gtk-server awk program running:

Code: Select all

PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND

 8624  8623 root     S    21544   8%   0   0% gtk-server -stdin
...
 8623 30060 root     S     2320   1%   0   0% /bin/gawk -f gtkprog.awk
Note that an instance of "bash" is heavier in terms of resource usage than gawk (from earlier running bash pipe example):

Code: Select all

PID  PPID USER     STAT   VSZ %MEM CPU %CPU COMMAND
13739     1 root     S    21432   8%   0   0% gtk-server -fifo /tmp/bash.gtk -detach
...
13737 30060 root     S     2948   1%   0   0% gtkprog.bash
So it seems to me like a good time to start writing new Puppy gui utilities using awk (gawk) plus gtk-server, as an alternative to bash/gtkdialogs. It will be interesting to compare awk as an interpretive programming language compared to bash in terms of speed. I think awk will do fine.
github mcewanw

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#17 Post by sunburnt »

Puppy524 uses Bash 4 or 4.2 ( I think...), a few other niceities too.

I dnlded the awk manual, but I wanted to see what Bash can do.
I didn`t think of using awk for just communicating. A simple fix...
Using stdin directly would be nice also ( no extra awk to run ).
In the end I`m speed testing all of this to see which is the winner.
As far as ram usage goes, the difference is so small it`s irrelivant.

Q... What GUIs / projects does anyone have planned for gtk-server?

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#18 Post by mcewanw »

sunburnt wrote: I didn`t think of using awk for just communicating. A simple fix...
Unfortunately, I don't think it is so simple to use gawk just to communicate with gtk-server afterall, in which case its as well just programming in gawk and calling commandline utils with the gawk "system" command as and when required (or accept using named pipes with bash versions less than 4).

I'll see if the older version of Lucid I have also has bash 4 - I'm pretty sure it is quite easy to get coproc to work with gtk-server. Unfortunately, that wouldn't help bash 3 users, of which I am currently one (using Puppy Wary).
github mcewanw

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

using wiakmv with gtk-server -ipc

#19 Post by mcewanw »

I commented earlier that I preferred using gtk-server -ipc which utilises an inter-process message queue rather than messy named pipes format. However, as I said, the problem is that the published example for doing that requires gtk-server to run two instances of itself, which is heavy on resource usage.

It turns out that the small wiakmv message queue utility can communicate directly with gtk-server message queue, and wiakmv has very low resource usage as the ps output at the bottom of this post illustrates.

I therefore wrote a demo of gtk-server -ipc using wiakmv, which is below. I've copied a pet of the small wiakmv utility here also (the dotpet puts the tiny wiakmv into /usr/local/bin). The source code for wiakmv is GPL and available at http://wiak.org downloads.

Code: Select all

#!/bin/sh
# Bourne shell gtk-server IPC demo using wiakmv (GPL)
#   for the message queue communications with gtk-server
#
# Creation date (YMD): 2011/10/12 (original version 1.0.0)                                        
# Revision date (YMD): 2011/10/12
# (C) Copyright 2011 William McEwan (http://wiak.org); GPL
#
# Using code from Bourne shell named pipe demo with the GTK-server
# by Peter van Eerten; Revision January 15, 2007 
#
# Current PID ($$) is used for the unique message queue comms channel
#------------------------------------------------

# Communicate with GTK-server
gtk()
{
  # send the gtk string to gtk-server 
  wiakmv --zid=$$ --type=1 --send "$@"
  # receive the gtk-server return string into RESULT
  RESULT=$(wiakmv --zid=$$ --type=1 --receive stdout)
}

# Main starts here

# Start gtk-server in InterProcessComms mode
gtk-server -ipc=$$ -detach

# Setup GUI
gtk "gtk_init NULL NULL"
gtk "gtk_window_new 0"
WIN=$RESULT
gtk "gtk_window_set_title $WIN 'BASH GTK-server demo'"
gtk "gtk_window_set_default_size $WIN 400 200"
gtk "gtk_window_set_position $WIN 1"
gtk "gtk_table_new 10 10 1"
TBL=$RESULT
gtk "gtk_container_add $WIN $TBL"
gtk "gtk_button_new_with_label 'Click to Quit'"
BUT=$RESULT
gtk "gtk_table_attach_defaults $TBL $BUT 5 9 5 9"
gtk "gtk_widget_show_all $WIN"

EVENT=0

# Mainloop
while [[ $EVENT -ne $BUT && $EVENT -ne $WIN ]]
do
    gtk "gtk_server_callback WAIT"
    EVENT=$RESULT
done

# Exit GTK-server
wiakmv --zid=$$ --type=1 --send "gtk_server_exit"
# exit wiakmv
wiakmv --zid=$$ --type=1 --quit
exit 0
Showing the low wiakmv resource usage with ps:

The running gtk-server here uses roughly 21 MByte RAM and wiakmv just 1.5 MB (half what awk would use) and being in memory, message queues are fast comms channel. This is on an old Pentium III 256 MByte system with Wary 5.1.4.1 os.

Code: Select all

# ps ao vsize,pmem,pcpu,cmd | egrep '(gtk-server|wiakmv)'
 21436  3.2  0.0 gtk-server -ipc 9438 -detach
  1508  0.1  0.0 wiakmv --zid=9438 --type=1 --receive stdout
Attachments
wiakmv-2.3.0.pet
wiakmv provides message queue facility to bash
(4.04 KiB) Downloaded 394 times
github mcewanw

mcewanw
Posts: 3169
Joined: Thu 16 Aug 2007, 10:48
Contact:

#20 Post by mcewanw »

An average gtkdialog3 gui seems to consume about the same amount of RAM as gtk-server.

The gtk-server binary occupies around 250 kB on disk, whereas gtkdialog3 occupies around 172kB. However, gtk-server appears to offer much more functionality (Full GTK API available, and more...) and doesn't see too difficult to program (and good for learning gtk more generally). gtk-server seems to be well-supported and under active development in a sizable community. Available for Linux and MS Windows it seems.

I expect a gui created with gtk-server to be faster than a gtkdialog3 one.

Bacon appears to occupy around 392 kB on disk.

The challenge would be to port some bash/gtkdialogs to bash(or awk)/gtk-server and compare the results.
github mcewanw

Post Reply