|
今天看到GUI for (shell-)script languages,发现又多了一种 shell 下编写和控制 gui 的方法:GTK-server。
从它的介绍来看,这是一个很容易掌握和移植的语言:How does it work? The GTK-server is a standalone binary, which is able to
communicate by a 2-way pipe or by a TCP port. The script invokes this binary,
sets up a pipe or a TCP connection and prints the GTK call in plain text to the pipe
or socket. The server then sends information back which can be used in the script. 看了一下 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
- #
- event="0"
- ./gtk-server 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_widget_show(" $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($but)" >&3; read -r tmp <&3
- echo -e "gtk_widget_show($win)" >&3; read -r tmp <&3
- while [ $event != "1" ]; do
- echo -e "gtk_main_iteration()" >&3; read -r tmp <&3
- echo -e "gtk_server_callback(" $but ")" >&3; read -r event <&3
- done
- echo -e "gtk_exit()" >&3
- echo "Enjoy the day..."
复制代码 但 python 的例子就太丑陋了,如果用这个就有点活受罪了。
因为 GTK-server 本身的设计架构,所以容易和任何一门 script 语言接合,而不需要语言为配合它做任何改变,这是它最大的优点!光看看它的主页上列出的十来种不同脚本语言应用的例子,就够壮观了。不错,有前途。 |
|