#!/usr/local/bin/expectk # # gpshell.tcl: # # [1999/07/26] OSHIRO Naoki. # # $Log:$ # proc makeFloatMenuBase {{canv_id} {x} {y}} { destroy .helptmp set w .c$canv_id set mark c$canv_id set m [menu .helptmp -tearoff 0 -cursor hand2]; $m add command -label "Save" \ -command "$w postscript -file \[tk_getSaveFile -title Save -filetypes {{PS {.ps}} {ALL {*}}}\]" $m add command -label "Delete" -command "destroy $w; .t delete $mark" tk_popup $m $x $y } proc sendCommand {cur_com} { global canv_id global canv_width canv_height if {[regexp "^ *$" $cur_com]} { exp_send "$cur_com\r" expect "gnuplot>" regsub -all "\r" $expect_out(buffer) "" tmp regsub "^ *\[^\n\]*\n ?" $tmp "" tmp .t insert insert "\n$tmp" .t see end return } foreach cur_com [split $cur_com ";"] { regsub "^ *" $cur_com "" cur_com if {[regexp "^(rep(lot)?|s?plot|load)" $cur_com]==1} { exp_send "set term tkcanvas\r" expect "gnuplot>" } exp_send "$cur_com\r" expect "gnuplot>" regsub -all "\r" $expect_out(buffer) "" tmp regsub "^ *\[^\n\]*\n ?" $tmp "" tmp if {[regexp "proc gnuplot" $tmp]==1} { regsub "gnuplot>$" $tmp "" tmp canvas .c$canv_id \ -width $canv_width -height $canv_height \ -background white -cursor hand2 bind .c$canv_id "makeFloatMenuBase $canv_id %X %Y" eval $tmp gnuplot .c$canv_id set mark c$canv_id .t mark set $mark insert .t insert $mark "\n" .t window create $mark -window .c$canv_id .t tag add center "insert-1char" insert .t insert $mark "\n" .t insert insert "gnuplot>" incr canv_id } else { .t insert insert "\n$tmp" } .t see end } } log_user 0 text .t -yscrollcommand ".scry set" -background white .t tag configure center -justify center scrollbar .scry -orient vertical -command ".t yview" pack .scry -fill y -side right pack .t -fill both -expand yes match_max -d 30000 spawn gnuplot expect "gnuplot>" regsub -all "\r" $expect_out(buffer) "" tmp .t insert insert $tmp if {1} { exp_send "set term tkcanvas\r" expect "gnuplot>" regsub -all "\r" $expect_out(buffer) "" tmp .t insert insert $tmp } set canv_id 0 set canv_width 240 set canv_height 180 bind . exit bind .t {set cur_com [.t get "insert linestart" "insert lineend"]; regsub "^ *(gnuplot>|Press return for more:) *" $cur_com "" cur_com; sendCommand $cur_com; break} bind .t exit focus .t