Add a script to clean up after Tcl/Tk installation
[msysgit/kusma.git] / mingw / lib / tk8.5 / demos / filebox.tcl
blobd9144560bfee8aa215460ab48cdb48e223166a8e
1 # filebox.tcl --
3 # This demonstration script prompts the user to select a file.
5 # RCS: @(#) $Id: filebox.tcl,v 1.9 2007/12/13 15:27:07 dgp Exp $
7 if {![info exists widgetDemo]} {
8 error "This script should be run from the \"widget\" demo."
11 package require Tk
13 set w .filebox
14 catch {destroy $w}
15 toplevel $w
16 wm title $w "File Selection Dialogs"
17 wm iconname $w "filebox"
18 positionWindow $w
20 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."
21 pack $w.msg -side top
23 ## See Code / Dismiss buttons
24 set btns [addSeeDismiss $w.buttons $w]
25 pack $btns -side bottom -fill x
27 foreach i {open save} {
28 set f [frame $w.$i]
29 label $f.lab -text "Select a file to $i: " -anchor e
30 entry $f.ent -width 20
31 button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
32 pack $f.lab -side left
33 pack $f.ent -side left -expand yes -fill x
34 pack $f.but -side left
35 pack $f -fill x -padx 1c -pady 3
38 if {$tcl_platform(platform) eq "unix"} {
39 checkbutton $w.strict -text "Use Motif Style Dialog" \
40 -variable tk_strictMotif -onvalue 1 -offvalue 0
41 pack $w.strict -anchor c
43 # This binding ensures that we don't run the rest of the demos
44 # with motif style interactions
45 bind $w.strict <Destroy> {set tk_strictMotif 0}
48 proc fileDialog {w ent operation} {
49 # Type names Extension(s) Mac File Type(s)
51 #---------------------------------------------------------
52 set types {
53 {"Text files" {.txt .doc} }
54 {"Text files" {} TEXT}
55 {"Tcl Scripts" {.tcl} TEXT}
56 {"C Source Files" {.c .h} }
57 {"All Source Files" {.tcl .c .h} }
58 {"Image Files" {.gif} }
59 {"Image Files" {.jpeg .jpg} }
60 {"Image Files" "" {GIFF JPEG}}
61 {"All files" *}
63 if {$operation == "open"} {
64 global selected_type
65 if {![info exists selected_type]} {
66 set selected_type "Tcl Scripts"
68 set file [tk_getOpenFile -filetypes $types -parent $w \
69 -typevariable selected_type]
70 puts "You selected filetype \"$selected_type\""
71 } else {
72 set file [tk_getSaveFile -filetypes $types -parent $w \
73 -initialfile Untitled -defaultextension .txt]
75 if {[string compare $file ""]} {
76 $ent delete 0 end
77 $ent insert 0 $file
78 $ent xview end