Puppy Linux Discussion Forum
"THE" alternative forum : puppylinux.info

 The time now is Wed 29 Jun 2016, 23:18 All times are UTC - 4
 Page 1 of 3 [31 Posts] Goto page: 1, 2, 3 Next
Author Message
jamesbond

Joined: 26 Feb 2007
Posts: 2855
Location: The Blue Marble

 Posted: Fri 30 Sep 2011, 23:25    Post subject:  From the creator of BaCon - gtk-serverSubject description: Yet another GUI dialog maker

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

According to the Introduction page:
 Quote: 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:
 Quote: 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)?

cheers!

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread.
sunburnt

Joined: 08 Jun 2005
Posts: 5056
Location: Arizona, U.S.A.

 Posted: Sat 01 Oct 2011, 15:45    Post subject:

Looks very interesting, Ill check this out for sure.
I dislike the underline_syntax_of_GTK. But a wrapper will fix that.
 Quote: GUI component and the actual application code is totally separate

This is how Ive written most of my gtkDialog apps.
jamesbond

Joined: 26 Feb 2007
Posts: 2855
Location: The Blue Marble

 Posted: Sat 01 Oct 2011, 20:59    Post subject:

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, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread.
sunburnt

Joined: 08 Jun 2005
Posts: 5056
Location: Arizona, U.S.A.

 Posted: Sun 02 Oct 2011, 11:20    Post subject:

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.
Isnt just "gtk-server.cfg.new" renamed to "gtk-server.cfg" in "/usr/local/etc" good?
jamesbond

Joined: 26 Feb 2007
Posts: 2855
Location: The Blue Marble

 Posted: Tue 04 Oct 2011, 17:54    Post subject:

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!
 gtk-server-2.3.1-i486.pet Description Compiled in Wary 5.0 Download Filename gtk-server-2.3.1-i486.pet Filesize 71.36 KB Downloaded 483 Time(s)

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread.
sunburnt

Joined: 08 Jun 2005
Posts: 5056
Location: Arizona, U.S.A.

 Posted: Tue 04 Oct 2011, 22:41    Post subject:

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

Now I need to get a handle on whats going on with it. The big picture...
Whats 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 its pretty clear how the code works, but this is a bit more complex.

Thanks again... Terry
mcewanw

Joined: 16 Aug 2007
Posts: 2790
Location: New Zealand

 Posted: Mon 10 Oct 2011, 17:49    Post subject: simplest bash code example from gtk-server website

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: #!/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:

 Quote: 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.php?p=151783&search_id=1573530550#151783

http://wiak.org

Last edited by mcewanw on Tue 11 Oct 2011, 18:21; edited 3 times in total
sunburnt

Joined: 08 Jun 2005
Posts: 5056
Location: Arizona, U.S.A.

 Posted: Mon 10 Oct 2011, 18:33    Post subject:

I tried to make gtk-server work for stdin, but apparently it wont 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, Ive worked with pipes before and theyre finicky.

Im working on a mod. to simplify the syntax so "define" isnt needed to
create widgets, and .gtk4bash and the config. files arent needed also.
But Im 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 users GUI code in a second "gui" file, just the widgets and properties.
And then theres 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 Id like to write a Visual IDE for the whole thing ( kinda like Glade ).
mcewanw

Joined: 16 Aug 2007
Posts: 2790
Location: New Zealand

 Posted: Mon 10 Oct 2011, 20:20    Post subject:

 sunburnt wrote: ... Ive worked with pipes before and theyre 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: # 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.html#Advanced-Features  Quote: 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: function GTK(str) { print str |& GTK_SERVER GTK_SERVER |& getline TMP return TMP } Lobster Official Crustacean Joined: 04 May 2005 Posts: 15159 Location: Paradox Realm  Posted: Mon 10 Oct 2011, 22:09 Post subject:  Quote: simplest bash usage example This and the pet provided by James Bond worked in Slacko RC++ _________________ Puppy WIKI mcewanw Joined: 16 Aug 2007 Posts: 2790 Location: New Zealand  Posted: Mon 10 Oct 2011, 22:46 Post subject: Lobster wrote:  Quote: 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: #!/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: 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.
mcewanw

Joined: 16 Aug 2007
Posts: 2790
Location: New Zealand

 Posted: Mon 10 Oct 2011, 23:13    Post subject:

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: "gtk_init NULL NULL" "gtk_window_new 0" "gtk_window_set_default_size $WIN 400 200" ... and so on... sunburnt Joined: 08 Jun 2005 Posts: 5056 Location: Arizona, U.S.A.  Posted: Tue 11 Oct 2011, 00:52 Post subject: 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 doesnt 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 Ill find out why my mod. wont 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: (: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: gtk_window_set_title \$winMAIN "Win._Title"
mcewanw

Joined: 16 Aug 2007
Posts: 2790
Location: New Zealand

 Posted: Tue 11 Oct 2011, 03:32    Post subject:

 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/unix/ksh.html#coprocesses

 Quote: 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:

 Quote: 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_node/Coprocesses.html

http://tldp.org/LDP/abs/html/bashver4.html

 Quote: 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.
jamesbond

Joined: 26 Feb 2007
Posts: 2855
Location: The Blue Marble

 Posted: Tue 11 Oct 2011, 05:56    Post subject:

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_node/Coprocesses.html

http://tldp.org/LDP/abs/html/bashver4.html

 Quote: 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, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year  Sort by: Post TimePost SubjectAuthor AscendingDescending
 Page 1 of 3 [31 Posts] Goto page: 1, 2, 3 Next
 Jump to: Select a forum ------------------- Forum index |___ House Training |   |___ Beginners Help ( Start Here) |   |___ Users ( For the regulars ) |   |   |___ Usuarios de habla Hispana |   |   |___ Für deutschsprachige Anhänger |   |   |___ Pour les francophones |   |     |   |___ HOWTO ( Solutions ) |   |___ Bugs ( Submit bugs ) |     |___ Advanced Topics |   |___ Additional Software (PETs, n' stuff) |   |   |___ Package Collections / Repositories |   |   |___ REQUESTS |   |   |___ Browsers and Internet |   |   |___ Business |   |   |___ Compiling |   |   |___ Desktop |   |   |___ Documents |   |   |___ Drivers |   |   |___ Educational |   |   |___ Engineering/Science/Simulation |   |   |___ Eye Candy |   |   |___ Filesystem |   |   |___ Games |   |   |___ Graphics |   |   |___ Multimedia |   |   |___ Network |   |   |___ Security/Privacy |   |   |___ System |   |   |___ Utilities |   |   |___ Virtualization |   |   |___ Unsorted |   |     |   |___ Cutting edge |   |   |___ Multi-session live-CD/DVD |   |     |   |___ Hardware |   |   |___ Audio |   |   |___ Networking |   |   |   |___ Dialup |   |   |   |___ Ethernet |   |   |   |___ Wireless |   |   |     |   |   |___ Printers |   |   |___ Video |   |     |   |___ Puppy Derivatives |   |___ Puppy Projects |       |___ Next Puppy Development |       |   |___ 4.x |       |   |   |___ Bugs (4.x dev) |       |   |   |___ Usability Issues (4.x dev) |       |   |     |       |   |___ 5.x |       |       |___ Bugs (5.x dev) |       |       |___ Usability Issues (5.x dev) |       |     |       |___ Localization Project |       |___ Documentation Project |     |___ Taking the Puppy out for a walk |   |___ Announcements |   |___ Puppy Power |   |___ Suggestions |   |___ Misc |     |___ Off-Topic Area     |___ Programming     |___ Security

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum