1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# -*- coding: utf-8 -*-
#
# menus widget demo (called by 'widget')
#
# toplevel widget
if defined?($menu84_demo) && $menu84_demo
$menu84_demo.destroy
$menu84_demo = nil
end
# demo toplevel widget
$menu84_demo = TkToplevel.new {|w|
title("File Selection Dialogs")
iconname("menu84")
positionWindow(w)
}
base_frame = TkFrame.new($menu84_demo).pack(:fill=>:both, :expand=>true)
begin
windowingsystem = Tk.windowingsystem()
rescue
windowingsystem = ""
end
# label
TkLabel.new(base_frame,'font'=>$font,'wraplength'=>'4i','justify'=>'left') {
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem == "classic" || windowingsystem == "aqua"
text("ãã®ã¦ã£ã³ãã¦ã«ã¯ã«ã¹ã±ã¼ãã¡ãã¥ã¼ãæã¤ã¡ãã¥ã¼ãã¼ãä»ãããã¦ãã¾ããCommand+x ('x'ã¯ã³ãã³ããã¼ã·ã³ãã«ã«ç¶ãã¦è¡¨ç¤ºããã¦ããæåã§ã) ã¨ã¿ã¤ããããã¨ã«ãã£ã¦ãé
ç®ã®æ©è½ãå¼ã³åºããã¨ãã§ãã¾ããæå¾ã®ã¡ãã¥ã¼ã¯ããã¦ã¹ã§ã¦ã£ã³ãã¦ã®å¤ã«ãã©ãã°ãããã¨ã«ãã£ã¦ãç¬ç«ãããã¬ããã¨ãªãããã«åãæ¾ããã¨ãå¯è½ã§ãã")
else
text("ãã®ã¦ã£ã³ãã¦ã«ã¯ã«ã¹ã±ã¼ãã¡ãã¥ã¼ãæã¤ã¡ãã¥ã¼ãã¼ãä»ãããã¦ãã¾ããAlt+x ('x'ã¯ã¡ãã¥ã¼ä¸ã§ä¸ç·ãå¼ãããæåã§ã) ã¨ã¿ã¤ããããã¨ã«ãã£ã¦ãã¡ãã¥ã¼ãå¼ã³åºããã¨ãã§ãã¾ããç¢å°ãã¼ã使ã£ã¦ãã¡ãã¥ã¼éã移åãããã¨ãå¯è½ã§ããã¡ãã¥ã¼ã表示ããã¦ããæã«ã¯ãç¾å¨ä½ç½®ã®é
ç®ãã¹ãã¼ã¹ãã¼ã§é¸æããããä¸ç·ãå¼ãããæåãå
¥åãããã¨ã§ãã®é
ç®ãé¸æããããããã¨ãã§ãã¾ããããé
ç®ã«ã¢ã¯ã»ã©ã¬ã¼ã¿ã®æå®ããªããã¦ãããªãã°ããã®æå®ããããã¼å
¥åãè¡ããã¨ã§ãã¡ãã¥ã¼ã表示ããããã¨ãªãç´æ¥ãã®é
ç®ã®æ©è½ãå¼ã³åºãã¾ããæå¾ã®ã¡ãã¥ã¼ã¯ãã¡ãã¥ã¼ã®æåã®é
ç®ãé¸æãããã¨ã«ãã£ã¦ãç¬ç«ãããã¬ããã¨ãªãããã«åãæ¾ããã¨ãå¯è½ã§ãã")
end
}.pack('side'=>'top')
menustatus = TkVariable.new(" ")
TkFrame.new(base_frame) {|frame|
TkLabel.new(frame, 'textvariable'=>menustatus, 'relief'=>'sunken',
'bd'=>1, 'font'=>['Helvetica', '10'],
'anchor'=>'w').pack('side'=>'left', 'padx'=>2,
'expand'=>true, 'fill'=>'both')
pack('side'=>'bottom', 'fill'=>'x', 'pady'=>2)
}
# frame
TkFrame.new(base_frame) {|frame|
TkButton.new(frame) {
#text 'äºè§£'
text 'éãã'
command proc{
tmppath = $menu84_demo
$menu84_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text 'ã³ã¼ãåç
§'
command proc{showCode 'menu84'}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# create menu frame
$menu84_frame = TkMenu.new($menu84_demo, 'tearoff'=>false)
# menu
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'File', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Open...', 'command'=>proc{fail 'ããã¯åãªããã¢ã§ãããã"Open..." é
ç®ã®æ©è½ã¯ç¹ã«å®ç¾©ããã¦ã¯ãã¾ããã'})
add('command', 'label'=>'New', 'command'=>proc{fail 'ããã¯åãªããã¢ã§ãããã"New" é
ç®ã®æ©è½ã¯ç¹ã«å®ç¾©ããã¦ã¯ãã¾ããã'})
add('command', 'label'=>'Save', 'command'=>proc{fail 'ããã¯åãªããã¢ã§ãããã"Save" é
ç®ã®æ©è½ã¯ç¹ã«å®ç¾©ããã¦ã¯ãã¾ããã'})
add('command', 'label'=>'Save As...', 'command'=>proc{fail 'ããã¯åãªããã¢ã§ãããã"Save As..." é
ç®ã®æ©è½ã¯ç¹ã«å®ç¾©ããã¦ã¯ãã¾ããã'})
add('separator')
add('command', 'label'=>'Print Setup...', 'command'=>proc{fail 'ããã¯åãªããã¢ã§ãããã"Print Setup..." é
ç®ã®æ©è½ã¯ç¹ã«å®ç¾©ããã¦ã¯ãã¾ããã'})
add('command', 'label'=>'Print...', 'command'=>proc{fail 'ããã¯åãªããã¢ã§ãããã"Print..." é
ç®ã®æ©è½ã¯ç¹ã«å®ç¾©ããã¦ã¯ãã¾ããã'})
add('separator')
add('command', 'label'=>'Dismiss Menus Demo', 'command'=>proc{$menu84_demo.destroy})
}
if $tk_platform['platform'] == 'macintosh' ||
windowingsystem = "classic" || windowingsystem = "aqua"
modifier = 'Command'
elsif $tk_platform['platform'] == 'windows'
modifier = 'Control'
else
modifier = 'Meta'
end
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Basic', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Long entry that does nothing')
['A','B','C','D','E','F','G'].each{|c|
add('command', 'label'=>"Print letter \"#{c}\"",
'underline'=>14, 'accelerator'=>"Meta+#{c}",
'command'=>proc{print c,"\n"}, 'accelerator'=>"#{modifier}+#{c}")
$menu84_demo.bind("#{modifier}-#{c.downcase}", proc{print c,"\n"})
}
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Cascades', 'menu'=>m, 'underline'=>0)
add('command', 'label'=>'Print hello',
'command'=>proc{print "Hello\n"},
'accelerator'=>"#{modifier}+H", 'underline'=>6)
$menu84_demo.bind("#{modifier}-h", proc{print "Hello\n"})
add('command', 'label'=>'Print goodbye',
'command'=>proc{print "Goodbye\n"},
'accelerator'=>"#{modifier}+G", 'underline'=>6)
$menu84_demo.bind("#{modifier}-g", proc{print "Goodbye\n"})
TkMenu.new(m, 'tearoff'=>false) {|cascade_check|
m.add('cascade', 'label'=>'Check button',
'menu'=>cascade_check, 'underline'=>0)
oil = TkVariable.new(0)
add('check', 'label'=>'ãªã¤ã«æ¤æ»', 'variable'=>oil)
trans = TkVariable.new(0)
add('check', 'label'=>'ãã©ã³ã¹ããã·ã§ã³æ¤æ»', 'variable'=>trans)
brakes = TkVariable.new(0)
add('check', 'label'=>'ãã¬ã¼ãæ¤æ»', 'variable'=>brakes)
lights = TkVariable.new(0)
add('check', 'label'=>'ã©ã¤ãæ¤æ»', 'variable'=>lights)
add('separator')
add('command', 'label'=>'Show current values',
'command'=>proc{showVars($menu84_demo,
['ãªã¤ã«', oil],
['ãã©ã³ã¹ããã·ã§ã³', trans],
['ãã¬ã¼ã', brakes],
['ã©ã¤ã', lights])} )
invoke 1
invoke 3
}
TkMenu.new(m, 'tearoff'=>false) {|cascade_radio|
m.add('cascade', 'label'=>'Radio buttons',
'menu'=>cascade_radio, 'underline'=>0)
pointSize = TkVariable.new
add('radio', 'label'=>'10 point', 'variable'=>pointSize, 'value'=>10)
add('radio', 'label'=>'14 point', 'variable'=>pointSize, 'value'=>14)
add('radio', 'label'=>'18 point', 'variable'=>pointSize, 'value'=>18)
add('radio', 'label'=>'24 point', 'variable'=>pointSize, 'value'=>24)
add('radio', 'label'=>'32 point', 'variable'=>pointSize, 'value'=>32)
add('separator')
style = TkVariable.new
add('radio', 'label'=>'Roman', 'variable'=>style, 'value'=>'roman')
add('radio', 'label'=>'Bold', 'variable'=>style, 'value'=>'bold')
add('radio', 'label'=>'Italic', 'variable'=>style, 'value'=>'italic')
add('separator')
add('command', 'label'=>'ç¾å¨å¤ã®è¡¨ç¤º',
'command'=>proc{showVars($menu84_demo,
['pointSize', pointSize],
['style', style])} )
invoke 1
invoke 7
}
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'Icons', 'menu'=>m, 'underline'=>0)
add('command', 'hidemargin'=>1,
'bitmap'=>'@'+[$demo_dir,'..',
'images','pattern.xbm'].join(File::Separator),
'command'=>proc{TkDialog.new('title'=>'Bitmap Menu Entry',
'text'=>'ããªããé¸æããã¡ãã¥ã¼é
ç®ã¯ãæååã®ä»£ããã«ããããããã¤ã¡ã¼ã¸ã§é
ç®ã表示ãããã®ã§ãããã以å¤ã®ç¹ã§ã¯ãã»ãã®ã¡ãã¥ã¼é
ç®ã¨ã®éã§ç¹ã«éããããããã§ã¯ããã¾ããã',
'bitmap'=>'', 'default'=>0,
'buttons'=>'éãã')} )
['info', 'questhead', 'error'].each{|icon|
add('command', 'bitmap'=>icon, 'hidemargin'=>1,
'command'=>proc{print "You invoked the #{icon} bitmap\n"})
}
entryconfigure(2, :columnbreak=>true)
}
TkMenu.new($menu84_frame, 'tearoff'=>false) {|m|
$menu84_frame.add('cascade', 'label'=>'More', 'menu'=>m, 'underline'=>0)
[ 'An entry','Another entry','Does nothing','Does almost nothing',
'Make life meaningful' ].each{|i|
add('command', 'label'=>i,
'command'=>proc{print "You invoked \"#{i}\"\n"})
}
m.entryconfigure('Does almost nothing',
'bitmap'=>'questhead', 'compound'=>'left',
'command'=>proc{
TkDialog.new('title'=>'Compound Menu Entry',
'message'=>'ããªããé¸æããã¡ãã¥ã¼é
ç®ã¯ãããããããã¤ã¡ã¼ã¸ã¨æååã¨ãåæã«ä¸ã¤ã®é
ç®ã«è¡¨ç¤ºããããã«ãããã®ã§ãããã以å¤ã®ç¹ã§ã¯ãã»ãã®ã¡ãã¥ã¼é
ç®ã¨ã®éã§ç¹ã«éããããããã§ã¯ããã¾ããã',
'buttons'=>['äºè§£'], 'bitmap'=>'')
})
}
TkMenu.new($menu84_frame) {|m|
$menu84_frame.add('cascade', 'label'=>'Colors', 'menu'=>m, 'underline'=>0)
['red', 'orange', 'yellow', 'green', 'blue'].each{|c|
add('command', 'label'=>c, 'background'=>c,
'command'=>proc{print "You invoked \"#{c}\"\n"})
}
}
$menu84_demo.menu($menu84_frame)
TkMenu.bind('<MenuSelect>', proc{|w|
begin
label = w.entrycget('active', 'label')
rescue
label = " "
end
menustatus.value = label
Tk.update(true)
}, '%W')
|