LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 736|回复: 1

又一种 shell 的 gui 方案:GTK-server

[复制链接]
发表于 2003-12-19 18:52:58 | 显示全部楼层 |阅读模式
今天看到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 的例子,感觉还可以一用:
  1. #
  2. # Bash socket tcp demo on how to use the gtk-server - by nodep
  3. #
  4. # GNU bash, version 2.05b.0 needed for socket io
  5. #
  6. # Create as root: /dev/tcp/127.0.0.1/50000 and  chmod for user access
  7. #
  8. event="0"
  9. ./gtk-server 127.0.0.1:50000 &
  10. sleep 1
  11. IO=/dev/tcp/127.0.0.1/50000                                        ;exec 3<>$IO
  12. echo -e "gtk_init(NULL, NULL)"                                         >&3; read -r tmp <&3
  13. echo -e "gtk_window_new(0)"                                         >&3; read -r win <&3
  14. echo -e "gtk_window_set_title(" $win ",BASH GTK-SERVER)"         >&3; read -r tmp <&3
  15. echo -e "gtk_table_new(10,10,1)"                                 >&3; read -r tbl <&3
  16. echo -e "gtk_container_add(" $win "," $tbl ")"                         >&3; read -r tmp <&3
  17. echo -e "gtk_widget_show(" $tbl ")"                                 >&3; read -r tmp <&3
  18. echo -e "gtk_button_new_with_label(Click to Quit)"                 >&3; read -r but <&3
  19. echo -e "gtk_table_attach_defaults(" $tbl "," $but ",5,9,5,9)"         >&3; read -r tmp <&3
  20. echo -e "gtk_widget_show($but)"                                 >&3; read -r tmp <&3
  21. echo -e "gtk_widget_show($win)"                                 >&3; read -r tmp <&3
  22. while [ $event != "1" ]; do
  23.         echo -e "gtk_main_iteration()"                                 >&3; read -r tmp <&3
  24.         echo -e "gtk_server_callback(" $but ")"         >&3; read -r event <&3
  25. done
  26. echo -e "gtk_exit()"                                                 >&3
  27. echo "Enjoy the day..."
复制代码
python 的例子就太丑陋了,如果用这个就有点活受罪了。

因为 GTK-server 本身的设计架构,所以容易和任何一门 script 语言接合,而不需要语言为配合它做任何改变,这是它最大的优点!光看看它的主页上列出的十来种不同脚本语言应用的例子,就够壮观了。不错,有前途。
发表于 2003-12-19 19:38:10 | 显示全部楼层
:thank idkey~~
看看这个 ;)
http://www.linuxjournal.com/article.php?sid=2643
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表