OSDN Git Service

9fa1201d41e909aec264673982216a1283e952c7
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / ext / tk / sample / menubar1.rb
1 #
2 # menubar sample 1 : use frame and menubuttons
3 #
4
5 require 'tk'
6
7 radio_var = TkVariable.new('y')
8
9 menu_spec = [
10   [['File', 0],
11     {:label=>'Open', :command=>proc{puts('Open clicked')}, :underline=>0},
12     '---',
13     ['Check_A', TkVariable.new(true), 6],
14     {:type=>'checkbutton', :label=>'Check_B', 
15                 :variable=>TkVariable.new, :underline=>6},
16     '---',
17     ['Radio_X', [radio_var, 'x'], 6, '', {:foreground=>'black'}],
18     ['Radio_Y', [radio_var, 'y'], 6],
19     ['Radio_Z', [radio_var, 'z'], 6],
20     '---',
21     ['cascade', [ 
22                    ['sss', proc{p 'sss'}, 0], 
23                    ['ttt', proc{p 'ttt'}, 0], 
24                    ['uuu', proc{p 'uuu'}, 0], 
25                    ['vvv', proc{p 'vvv'}, 0], 
26                 ], 
27       0, '', 
28       {:font=>'Courier 16 italic', 
29        :menu_config=>{:font=>'Times -18 bold', :foreground=>'black'}}],
30     '---',
31     ['Quit', proc{exit}, 0]],
32
33   [['Edit', 0],
34     ['Cut', proc{puts('Cut clicked')}, 2],
35     ['Copy', proc{puts('Copy clicked')}, 0],
36     ['Paste', proc{puts('Paste clicked')}, 0]], 
37
38   [['Help', 0, {:menu_name=>'help'}],
39     ['About This', proc{puts('Ruby/Tk menubar sample 1')}, 6]]
40 ]
41
42 menubar = TkMenubar.new(nil, menu_spec,
43                        'tearoff'=>false,
44                        'foreground'=>'grey40',
45                        'activeforeground'=>'red',
46                        'font'=>'Helvetia 12 bold')
47 menubar.pack('side'=>'top', 'fill'=>'x')
48
49 TkText.new(:wrap=>'word').pack.insert('1.0', 'Please read the sample source, and check how to override default configure options of menu entries on a menu_spec. Maybe, on windows, this menubar does not work properly about keyboard shortcuts. Then, please use "menu" option of root/toplevel widget (see sample/menubar2.rb).')
50
51 Tk.mainloop