OSDN Git Service

データを追加
[stux/ultron.git] / venv / tcl / tk8.6 / demos / menu.tcl
1 # menu.tcl --
2 #
3 # This demonstration script creates a window with a bunch of menus
4 # and cascaded menus using menubars.
5
6 if {![info exists widgetDemo]} {
7     error "This script should be run from the \"widget\" demo."
8 }
9
10 package require Tk
11
12 set w .menu
13 catch {destroy $w}
14 toplevel $w
15 wm title $w "Menu Demonstration"
16 wm iconname $w "menu"
17 positionWindow $w
18
19 label $w.msg -font $font -wraplength 4i -justify left
20 if {[tk windowingsystem] eq "aqua"} {
21     catch {set origUseCustomMDEF $::tk::mac::useCustomMDEF; set ::tk::mac::useCustomMDEF 1}
22     $w.msg configure -text "This window has a menubar with cascaded menus.  You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by selecting the first item in the menu."
23 } else {
24     $w.msg configure -text "This window contains a menubar with cascaded menus.  You can post a menu from the keyboard by typing Alt+x, where \"x\" is the character underlined on the menu.  You can then traverse among the menus using the arrow keys.  When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character.  If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu."
25 }
26 pack $w.msg -side top
27
28 set menustatus "    "
29 frame $w.statusBar
30 label $w.statusBar.label -textvariable menustatus -relief sunken -bd 1 -font "Helvetica 10" -anchor w
31 pack $w.statusBar.label -side left -padx 2 -expand yes -fill both
32 pack $w.statusBar -side bottom -fill x -pady 2
33
34 ## See Code / Dismiss buttons
35 set btns [addSeeDismiss $w.buttons $w]
36 pack $btns -side bottom -fill x
37
38 menu $w.menu -tearoff 0
39
40 set m $w.menu.file
41 menu $m -tearoff 0
42 $w.menu add cascade -label "File" -menu $m -underline 0
43 $m add command -label "Open..." -command {error "this is just a demo: no action has been defined for the \"Open...\" entry"}
44 $m add command -label "New" -command {error "this is just a demo: no action has been defined for the \"New\" entry"}
45 $m add command -label "Save" -command {error "this is just a demo: no action has been defined for the \"Save\" entry"}
46 $m add command -label "Save As..." -command {error "this is just a demo: no action has been defined for the \"Save As...\" entry"}
47 $m add separator
48 $m add command -label "Print Setup..." -command {error "this is just a demo: no action has been defined for the \"Print Setup...\" entry"}
49 $m add command -label "Print..." -command {error "this is just a demo: no action has been defined for the \"Print...\" entry"}
50 $m add separator
51 $m add command -label "Dismiss Menus Demo" -command "destroy $w"
52
53 set m $w.menu.basic
54 $w.menu add cascade -label "Basic" -menu $m -underline 0
55 menu $m -tearoff 0
56 $m add command -label "Long entry that does nothing"
57 if {[tk windowingsystem] eq "aqua"} {
58     set modifier Command
59 } elseif {[tk windowingsystem] == "win32"} {
60     set modifier Control
61 } else {
62     set modifier Meta
63 }
64 foreach i {A B C D E F} {
65     $m add command -label "Print letter \"$i\"" -underline 14 \
66             -accelerator Meta+$i -command "puts $i" -accelerator $modifier+$i
67     bind $w <$modifier-[string tolower $i]> "puts $i"
68 }
69
70 set m $w.menu.cascade
71 $w.menu add cascade -label "Cascades" -menu $m -underline 0
72 menu $m -tearoff 0
73 $m add command -label "Print hello" \
74         -command {puts stdout "Hello"} -accelerator $modifier+H -underline 6
75 bind $w <$modifier-h> {puts stdout "Hello"}
76 $m add command -label "Print goodbye" -command {\
77     puts stdout "Goodbye"} -accelerator $modifier+G -underline 6
78 bind $w <$modifier-g> {puts stdout "Goodbye"}
79 $m add cascade -label "Check buttons" \
80         -menu $w.menu.cascade.check -underline 0
81 $m add cascade -label "Radio buttons" \
82         -menu $w.menu.cascade.radio -underline 0
83
84 set m $w.menu.cascade.check
85 menu $m -tearoff 0
86 $m add check -label "Oil checked" -variable oil
87 $m add check -label "Transmission checked" -variable trans
88 $m add check -label "Brakes checked" -variable brakes
89 $m add check -label "Lights checked" -variable lights
90 $m add separator
91 $m add command -label "Show current values" \
92     -command "showVars $w.menu.cascade.dialog oil trans brakes lights"
93 $m invoke 1
94 $m invoke 3
95
96 set m $w.menu.cascade.radio
97 menu $m -tearoff 0
98 $m add radio -label "10 point" -variable pointSize -value 10
99 $m add radio -label "14 point" -variable pointSize -value 14
100 $m add radio -label "18 point" -variable pointSize -value 18
101 $m add radio -label "24 point" -variable pointSize -value 24
102 $m add radio -label "32 point" -variable pointSize -value 32
103 $m add sep
104 $m add radio -label "Roman" -variable style -value roman
105 $m add radio -label "Bold" -variable style -value bold
106 $m add radio -label "Italic" -variable style -value italic
107 $m add sep
108 $m add command -label "Show current values" \
109         -command "showVars $w.menu.cascade.dialog pointSize style"
110 $m invoke 1
111 $m invoke 7
112
113 set m $w.menu.icon
114 $w.menu add cascade -label "Icons" -menu $m -underline 0
115 menu $m -tearoff 0
116 # Main widget program sets variable tk_demoDirectory
117 $m add command -bitmap @[file join $tk_demoDirectory images pattern.xbm] \
118     -hidemargin 1 -command [list \
119         tk_dialog $w.pattern {Bitmap Menu Entry} \
120                 "The menu entry you invoked displays a bitmap rather than\
121                 a text string.  Other than this, it is just like any other\
122                 menu entry." {} 0 OK ]
123 foreach i {info questhead error} {
124     $m add command -bitmap $i -hidemargin 1 -command [list \
125             puts "You invoked the $i bitmap" ]
126 }
127 $m entryconfigure 2 -columnbreak 1
128
129 set m $w.menu.more
130 $w.menu add cascade -label "More" -menu $m -underline 0
131 menu $m -tearoff 0
132 foreach i {{An entry} {Another entry} {Does nothing} {Does almost nothing} {Make life meaningful}} {
133     $m add command -label $i -command [list puts "You invoked \"$i\""]
134 }
135 $m entryconfigure "Does almost nothing" -bitmap questhead -compound left \
136         -command [list \
137         tk_dialog $w.compound {Compound Menu Entry} \
138                 "The menu entry you invoked displays both a bitmap and a\
139                 text string.  Other than this, it is just like any other\
140                 menu entry." {} 0 OK ]
141
142 set m $w.menu.colors
143 $w.menu add cascade -label "Colors" -menu $m -underline 1
144 menu $m -tearoff 1
145 foreach i {red orange yellow green blue} {
146     $m add command -label $i -background $i -command [list \
147             puts "You invoked \"$i\"" ]
148 }
149
150 $w configure -menu $w.menu
151
152 bind Menu <<MenuSelect>> {
153     global $menustatus
154     if {[catch {%W entrycget active -label} label]} {
155         set label "    "
156     }
157     set menustatus $label
158     update idletasks
159 }
160
161 if {[tk windowingsystem] eq "aqua"} {catch {set ::tk::mac::useCustomMDEF $origUseCustomMDEF}}