The New Cult of Dead Cow

January 3, 2007






Gtk en Bash

Navegando en el portage de gentoo a peticion de mi amigo acardenas, me tope con un programilla bastante interesante.

emerge x11-libs/gtk-serv


Este programa(servidor) nos permite crear una interfaz gráfica con GTK, para lenguajes en los cuales no hay un bindding de GTK, tales como bash, ash, clisp, octave, etc. y otros tambien como python y perl.

Como funciona pues muy simple, al servidor se le envian cadenas de caracteres que representán los comandos que se ejecutaran en gtk. El lenguaje debe ser cápaz  de escribir y leer en una tubería, o enviar y recibir paquetes en TCP o UDP.

Aca les copio un ejemplo del mismo usando bash

#!/usr/bin/bash
#
# Bash socket tcp demo on how to use the gtk-server - by nodep
#
# GNU bash, version 2.05b.0 needed for socket io
#
# Create as root: /dev/tcp/127.0.0.1/50000 and chmod for user access
# Revised for GTK-server 1.2 October 7, 2004
# Revised for GTK-server 1.3 December 4, 2004
#————————————————

if [ ! -f /dev/tcp/127.0.0.1/50000 ]
then
echo
echo “As user root, create TCP device first:”
echo
echo “touch /dev/tcp/127.0.0.1/50000″
echo “chmod 666 /dev/tcp/127.0.0.1/50000″
echo
exit
fi

gtk-server tcp=127.0.0.1:50000 &

sleep 1

IO=/dev/tcp/127.0.0.1/50000; exec 3<>$IO

echo -e “gtk_init NULL NULL” >&3; read -r tmp <&3
echo -e “gtk_window_new 0″ >&3; read -r win <&3
echo -e “gtk_window_set_title $win \”BASH GTK-SERVER\”" >&3; read -r tmp <&3
echo -e “gtk_table_new 10 10 1″ >&3; read -r tbl <&3
echo -e “gtk_container_add $win $tbl” >&3; read -r tmp <&3
echo -e “gtk_button_new_with_label \”Click to Quit\”" >&3; read -r but <&3
echo -e “gtk_table_attach_defaults $tbl $but 5 9 5 9″ >&3; read -r tmp <&3
echo -e “gtk_widget_show_all $win” >&3; read -r tmp <&3

event=”0″

while [ $event != $but ]; do
echo -e “gtk_server_callback WAIT” >&3; read -r event <&3
done

echo -e “gtk_exit 0″ >&3

echo “Enjoy the day…”

Para los interesados aca esta la direccion : gtk-server

1 Comment »

The URI to TrackBack this entry is: http://necudeco.blogsome.com/2007/01/03/gtk-en-bash/trackback/

  1. Que bien, esta tecnología permitirá al fin hacer scripts con ventanas, como en KDE. GNOME va avanzando.

    Comment by Bruno Espinoza — January 4, 2007 @ 12:53 am

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>























Get free blog up and running in minutes with Blogsome
Theme designed by B A Khan