home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2x.zip / TclTk / lib / tk4.2 / demos / filebox.tcl < prev    next >
Text File  |  1999-07-27  |  2KB  |  67 lines

  1. # filebox.tcl --
  2. #
  3. # This demonstration script prompts the user to select a file.
  4. #
  5. # SCCS: @(#) filebox.tcl 1.2 96/08/27 15:03:26
  6.  
  7. set w .filebox
  8. catch {destroy $w}
  9. toplevel $w
  10. wm title $w "File Selection Dialogs"
  11. wm iconname $w "filebox"
  12. positionWindow $w
  13.  
  14. label $w.msg -font $font -wraplength 4i -justify left -text "Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog."
  15. pack $w.msg -side top
  16.  
  17. frame $w.buttons
  18. pack $w.buttons -side bottom -fill x -pady 2m
  19. button $w.buttons.dismiss -text Dismiss -command "destroy $w"
  20. button $w.buttons.code -text "See Code" -command "showCode $w"
  21. pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
  22.  
  23. foreach i {open save} {
  24.     set f [frame $w.$i]
  25.     label $f.lab -text "Select a file to $i: " -anchor e
  26.     entry $f.ent -width 20
  27.     button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
  28.     pack $f.lab -side left
  29.     pack $f.ent -side left -expand yes -fill x
  30.     pack $f.but -side left
  31.     pack $f -fill x -padx 1c -pady 3
  32. }
  33.  
  34. if ![string compare $tcl_platform(platform) unix] {
  35.     checkbutton $w.strict -text "Use Motif Style Dialog" \
  36.     -variable tk_strictMotif -onvalue 1 -offvalue 0
  37.     pack $w.strict -anchor c
  38. }
  39.  
  40. proc fileDialog {w ent operation} {
  41.     #   Type names        Extension(s)    Mac File Type(s)
  42.     #
  43.     #---------------------------------------------------------
  44.     set types {
  45.     {"Text files"        {.txt .doc}    }
  46.     {"Text files"        {}        TEXT}
  47.     {"Tcl Scripts"        {.tcl}        TEXT}
  48.     {"C Source Files"    {.c .h}        }
  49.     {"All Source Files"    {.tcl .c .h}    }
  50.     {"Image Files"        {.gif}        }
  51.     {"Image Files"        {.jpeg .jpg}    }
  52.     {"Image Files"        ""        {GIFF JPEG}}
  53.     {"All files"        *}
  54.     }
  55.     if {$operation == "open"} {
  56.     set file [tk_getOpenFile -filetypes $types -parent $w]
  57.     } else {
  58.     set file [tk_getSaveFile -filetypes $types -parent $w \
  59.         -initialfile Untitled -defaultextension .txt]
  60.     }
  61.     if [string compare $file ""] {
  62.     $ent delete 0 end
  63.     $ent insert 0 $file
  64.     $ent xview end
  65.     }
  66. }
  67.