1# 2# menubar sample 3 : vertical layout menubar; use frame and menubuttons 3# 4 5require 'tk' 6 7radio_var = TkVariable.new('y') 8 9menu_spec = [ 10 [['&File', true], # when underline option is ture, '&' index is the position 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'], /[XYZ]/, '', {:foreground=>'black'}], 18 ['Radio_Y', [radio_var, 'y'], /[XYZ]/], 19 ['Radio_Z', [radio_var, 'z'], /[XYZ]/], # use Regexp for underline position 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 3')}, "This"]] 40 # use string index for underline position 41] 42 43layout_proc = 'vertical' 44# The following procedure is same to 'layout_proc'=>'vertical' 45=begin 46layout_proc = proc{|parent, mbtn| 47 mbtn.direction :right 48 mbtn.pack(:side=>:top, :fill=>:x) 49 50 menu = mbtn.menu 51 cmd = proc{|m, dir| 52 Tk::Menu::TkInternalFunction.next_menu(m, dir) rescue nil 53 # ignore error when the internal function doesn't exist 54 } 55 menu.bind('Tab', cmd, :widget, 'forward') 56 menu.bind('Alt-Tab', cmd, :widget, 'backward') 57} 58=end 59 60menubar = TkMenubar.new(nil, menu_spec, 61 'layout_proc'=>layout_proc, 62 'tearoff'=>false, 63 'foreground'=>'grey40', 64 'activeforeground'=>'red', 65 'font'=>'Helvetia 12 bold') 66menubar.pack('side'=>'left', 'fill'=>'y') 67 68TkText.new(:wrap=>'word').pack.insert('1.0', 'This sample script generates "Menu Sidebar". 69If "::tk::MenuNextMenuon" function is available your Tcl/Tk library, you will be able to move to the next menu by Tab key on the posted menu, or the previous menu by Alt + Tab key. 70Please 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/menubar3.rb).') 71 72Tk.mainloop 73