#!/usr/bin/expect -f # # Demo script using Expect with GTK-server on STDIN # # Probably this script can be optimized. # Tested with "expect version 5.41.0" on Slackware 10 # # February 22, 2005 - PvE. #---------------------------------------------------- # Set timeout to 1 second set timeout 1 # Disable session to stdout log_user 0 # Start GTK-server in stdin mode spawn gtk-server -stdin # Create GUI send "gtk_init NULL NULL\n"; expect ok send "gtk_window_new 0\n"; expect -re \[0-9\]{6,} set WIN $expect_out(0,string) send "gtk_widget_set_usize $WIN 300 100\n"; expect ok send "gtk_window_set_title $WIN \"Expect with GTK\"\n"; expect ok send "gtk_window_set_position $WIN 1\n"; expect ok send "gtk_table_new 20 20 1\n"; expect -re \[0-9]{6,} set TBL $expect_out(0,string) send "gtk_container_add $WIN $TBL\n"; expect ok send "gtk_button_new_with_label \"Click to Quit\"\n"; expect -re \[0-9]{6,} set BUT $expect_out(0,string) send "gtk_table_attach_defaults $TBL $BUT 12 19 12 19\n"; expect ok send "gtk_label_new \"Expect uses GTK now!!\"\n"; expect -re \[0-9]{6,} set LAB $expect_out(0,string) send "gtk_table_attach_defaults $TBL $LAB 1 15 1 10\n"; expect ok send "gtk_widget_show_all $WIN\n"; expect ok # Mainloop set EVENT 0 while {$EVENT != $BUT && $EVENT != $WIN} { send "gtk_server_callback wait\n"; expect -re \[0-9\]{6,} set EVENT $expect_out(0,string) } # Exit GTK-server send "gtk_server_exit\n"