home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / vrml / cp2b2x.exe / DATA.Z / image2.tcl < prev    next >
Text File  |  1996-04-23  |  2KB  |  77 lines

  1. # image2.tcl --
  2. #
  3. # This demonstration script creates a simple collection of widgets
  4. # that allow you to select and view images in a Tk label.
  5. #
  6. # @(#) image2.tcl 1.2 95/07/26 08:34:38
  7.  
  8. # loadDir --
  9. # This procedure reloads the directory listbox from the directory
  10. # named in the demo's entry.
  11. #
  12. # Arguments:
  13. # w -            Name of the toplevel window of the demo.
  14.  
  15. proc loadDir w {
  16.     global dirName
  17.  
  18.     $w.f.list delete 0 end
  19.     foreach i [lsort [glob $dirName/*]] {
  20.     $w.f.list insert end [file tail $i]
  21.     }
  22. }
  23.  
  24. # loadImage --
  25. # Given the name of the toplevel window of the demo and the mouse
  26. # position, extracts the directory entry under the mouse and loads
  27. # that file into a photo image for display.
  28. #
  29. # Arguments:
  30. # w -            Name of the toplevel window of the demo.
  31. # x, y-            Mouse position within the listbox.
  32.  
  33. proc loadImage {w x y} {
  34.     global dirName
  35.  
  36.     set file $dirName/[$w.f.list get @$x,$y]
  37.     image2a configure -file $file
  38. }
  39.  
  40. set w .image2
  41. catch {destroy $w}
  42. toplevel $w
  43. wm title $w "Image Demonstration #2"
  44. wm iconname $w "Image2"
  45. positionWindow $w
  46.  
  47. label $w.msg -font $font -wraplength 4i -justify left -text "This demonstration allows you to view images using a Tk \"photo\" image.  First type a directory name in the listbox, then type Return to load the directory into the listbox.  Then double-click on a file name in the listbox to see that image."
  48. pack $w.msg -side top
  49.  
  50. frame $w.buttons
  51. pack  $w.buttons -side bottom -expand y -fill x -pady 2m
  52. button $w.buttons.dismiss -text Dismiss -command "destroy $w"
  53. button $w.buttons.code -text "See Code" -command "showCode $w"
  54. pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
  55.  
  56. label $w.dirLabel -text "Directory:"
  57. set dirName $tk_library/demos/images
  58. entry $w.dirName -width 30 -textvariable dirName
  59. bind $w.dirName <Return> "loadDir $w"
  60. frame $w.spacer1 -height 3m -width 20
  61. label $w.fileLabel -text "File:"
  62. frame $w.f
  63. pack $w.dirLabel $w.dirName $w.spacer1 $w.fileLabel $w.f -side top -anchor w
  64.  
  65. listbox $w.f.list -width 20 -height 10 -yscrollcommand "$w.f.scroll set"
  66. scrollbar $w.f.scroll -command "$w.f.list yview"
  67. pack $w.f.list $w.f.scroll -side left -fill y -expand 1
  68. $w.f.list insert 0 earth.gif earthris.gif mickey.gif teapot.ppm
  69. bind $w.f.list <Double-1> "loadImage $w %x %y"
  70.  
  71. catch {image delete image2a}
  72. image create photo image2a
  73. frame $w.spacer2 -height 3m -width 20
  74. label $w.imageLabel -text "Image:"
  75. label $w.image -image image2a
  76. pack $w.spacer2 $w.imageLabel $w.image -side top -anchor w
  77.