OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tk8.6.12 / library / demos / filebox.tcl
1 # filebox.tcl --
2 #
3 # This demonstration script prompts the user to select a file.
4
5 if {![info exists widgetDemo]} {
6     error "This script should be run from the \"widget\" demo."
7 }
8
9 package require Tk
10
11 set w .filebox
12 catch {destroy $w}
13 toplevel $w
14 wm title $w "File Selection Dialogs"
15 wm iconname $w "filebox"
16 positionWindow $w
17
18 ttk::frame $w._bg
19 place $w._bg -x 0 -y 0 -relwidth 1 -relheight 1
20
21 ttk::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."
22 pack $w.msg -side top
23
24 ## See Code / Dismiss buttons
25 set btns [addSeeDismiss $w.buttons $w]
26 pack $btns -side bottom -fill x
27
28 foreach i {open save} {
29     set f [ttk::frame $w.$i]
30     ttk::label $f.lab -text "Select a file to $i: " -anchor e
31     ttk::entry $f.ent -width 20
32     ttk::button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
33     pack $f.lab -side left
34     pack $f.ent -side left -expand yes -fill x
35     pack $f.but -side left
36     pack $f -fill x -padx 1c -pady 3
37 }
38
39 if {[tk windowingsystem] eq "x11"} {
40     ttk::checkbutton $w.strict -text "Use Motif Style Dialog" \
41         -variable tk_strictMotif -onvalue 1 -offvalue 0
42     pack $w.strict -anchor c
43
44     # This binding ensures that we don't run the rest of the demos
45     # with motif style interactions
46     bind $w.strict <Destroy> {set tk_strictMotif 0}
47 }
48
49 proc fileDialog {w ent operation} {
50     #   Type names              Extension(s)    Mac File Type(s)
51     #
52     #---------------------------------------------------------
53     set types {
54         {"Text files"           {.txt .doc}     }
55         {"Text files"           {}              TEXT}
56         {"Tcl Scripts"          {.tcl}          TEXT}
57         {"C Source Files"       {.c .h}         }
58         {"All Source Files"     {.tcl .c .h}    }
59         {"Image Files"          {.gif}          }
60         {"Image Files"          {.jpeg .jpg}    }
61         {"Image Files"          ""              {GIFF JPEG}}
62         {"All files"            *}
63     }
64     if {$operation == "open"} {
65         global selected_type
66         if {![info exists selected_type]} {
67             set selected_type "Tcl Scripts"
68         }
69         set file [tk_getOpenFile -filetypes $types -parent $w \
70                 -typevariable selected_type]
71         puts "You selected filetype \"$selected_type\""
72     } else {
73         set file [tk_getSaveFile -filetypes $types -parent $w \
74                 -initialfile Untitled -defaultextension .txt]
75     }
76     if {[string compare $file ""]} {
77         $ent delete 0 end
78         $ent insert 0 $file
79         $ent xview end
80     }
81 }