#!/usr/bin/wish8.0 #!/home/jmc/bin/wish4.2 # # NAME # gifdemo # # SYNOPSIS # gifdemo dir/*.gif & # # DESCRIPTION # Sample script that takes one or more graphic-file names on the # command line and pops up windows that show the pictures. # # This is a prototype (or demo) script. What it does is fill the # main window with a list of the file namess, with an "open" button # next to each. If you push the button, a window is popped up that # contains the picture, and the button's text changes to "close". # Pushing again closes the picture. # # INSTRUCTIONS # Collect a number of gif files in a directory. Then run this demo # with the files' names on the command line: # gifdemo foo/*.gif & # A window should pop up listing the file names, with some buttons # at the left. Push one of the "open" buttons, and a window should # pop up showing the picture. The button's text will change to # "close". If you push the "close" button, the picture should # disappear. # # REQUIRES # This probably needs at least wish4.2 to work properly. # # AUTHOR # John Chambers set me [lindex [wm title .] 0] set pwd [exec pwd] wm title . $pwd # Get some things from the environment: if [info exists env(D_$me)] {set D $env(D_$me)} else {set D 0} if [info exists env(B_$me)] {set B $env(B_$me)} else {set B 0} if [info exists env(R_$me)] {set R $env(R_$me)} else {set R ridge} if [info exists env(W_$me)] {set W $env(W_$me)} else {set W text} if {$D>0} {puts "me=\"$me\" B=\"$B\" D=\"$D\" R=\"$R\""} # Create a button bar at the top. frame .b -bd 3 -relief ridge pack .b -side top -fill x frame .b.bd -bd 3 -relief ridge label .b.bd.l -text border entry .b.bd.v -textvariable B -width 0 pack .b.bd.l .b.bd.v -in .b.bd -side left pack .b.bd -in .b -side left -expand 1 frame .b.rl -bd 3 -relief ridge label .b.rl.l -text relief menubutton .b.rl.b -textvariable R -menu .b.rl.b.m pack .b.rl.l .b.rl.b -in .b.rl -side left pack .b.rl -in .b -side left -expand 1 menu .b.rl.b.m .b.rl.b.m add command -label flat -command {set R flat} .b.rl.b.m add command -label ridge -command {set R ridge} .b.rl.b.m add command -label groove -command {set R groove} .b.rl.b.m add command -label raised -command {set R raised} .b.rl.b.m add command -label sunken -command {set R sunken} # Create a frame to hold the list of file names: frame .f -bd $B -relief $R pack .f -in . -fill both -expand 1 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # We use the variable W to decide on several possible ways of doing # # the job. Eventually, when we find the perfect way, the other # # choices should disappear. The default is what works best so far. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # switch $W { grid { text .f.lst -bd $B -relief $R -height 50 -width 0 \ -yscrollcommand {.f.vsb set} grid .f.lst -row 0 -column 0 -sticky nws scrollbar .f.vsb -width 8 -command {.f.lst yview} pack .f.vsb -in .f -side left -fill y pack .f.lst -in .f -side right -fill both -expand 1 } default { text .f.lst -bd $B -relief $R -height 50 -width 0 \ -yscrollcommand {.f.vsb set} scrollbar .f.vsb -width 8 -command {.f.lst yview} pack .f.vsb -in .f -side left -fill y pack .f.lst -in .f -side right -fill both -expand 1 } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Now we fill in the list of file names, with buttons to the left of # # each name. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # set n 0 foreach f $argv { incr n set f$n $f switch $W { grid { button .f.lst.x$n -text gif -command "exec xv $f &" button .f.lst.b$n -text open -command "OpenPic $n $f" -width 5 entry .f.lst.l$n -textvariable f$n -bd $B -relief ridge -width 0 set ob($n) .f.lst.b$n grid .f.lst.x$n -row $n -column 0 -sticky nws grid .f.lst.b$n -row $n -column 1 -sticky nws grid .f.lst.l$n -row $n -column 2 -sticky nws } default { set fr [frame .f.lst.f$n -bd $B -relief ridge] set fx [button .f.lst.f$n.x -text gif -command "exec xv $f &"] set fb [button .f.lst.f$n.b -text open -command "OpenPic $n $f" -width 5] set fe [entry .f.lst.f$n.l -textvariable f$n -bd $B -relief ridge -width 0] set fl [label .f.lst.f$n.f -text {} -bd $B -relief flat] set ob($n) $fb pack $fx $fb $fe -in $fr -side left pack $fl -in $fr -side right -fill x -expand 1 pack $fr -in .f.lst -side top -fill x -expand 1 set ff [.f.lst window create end -window $fr] .f.lst insert end \n # This doesn't work: # pack .f.lst.f$n.b .f.lst.f$n.l -in .f.lst.f$n -side left # pack .f.lst.f$n.f -in .f.lst.f$n -side right -fill x -expand 1 # pack .f.lst.f$n -in .f.lst -side top -fill x -expand 1 } } } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Close a picture window. We destroy both the window and the image, # # to recycle the memory that it used. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc ClosePic {n f} { global B R image$n ob set w .w$n if [winfo exists $w] {destroy $w} if [info exists image$n] {catch {image delete image$n}} $ob($n) config -text open -command "OpenPic $n $f" } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # Open a picture window. We put the file name in the title bar. Then # # we fetch the contents of the file and put them in the window. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # proc OpenPic {n f} { global B R image$n ob set w .w$n if ![winfo exists $w] {toplevel $w} wm title $w $f if [info exists image$n] {catch {image delete image$n}} image create photo image$n -file $f label $w.l1 -image image$n -bd $B -relief $R pack $w.l1 -side top -padx .5m -pady .5m -expand 1 $ob($n) config -text close -command "ClosePic $n $f" }