1#!/usr/bin/env ruby 2require 'tk' 3require 'tkextlib/iwidgets' 4 5helpvar = TkVariable.new 6viewmode = TkVariable.new 7 8menu_spec = [ 9 [:menubutton, 'file', { 10 :text=>'File', :menu=>[ 11 [:options, {:tearoff=>false}], 12 13 [:command, 'new', { 14 :label=>'New', :helpstr=>'Open new document', 15 :command=>proc{puts 'NEW'} 16 } 17 ], 18 19 [:command, 'close', { 20 :label=>'Close', :helpstr=>'Close current document', 21 :command=>proc{puts 'CLOSE'} 22 } 23 ], 24 25 [:separator, 'sep1'], 26 27 [:command, 'exit', { 28 :label=>'Exit', :helpstr=>'Exit application', 29 :command=>proc{exit} 30 } 31 ] 32 ] 33 } 34 ], 35 36 [:menubutton, 'edit', { 37 :text=>'Edit', :menu=>[ 38 [:options, {:tearoff=>false}], 39 40 [:command, 'undo', { 41 :label=>'Undo', :underline=>0, 42 :helpstr=>'Undo last command', 43 :command=>proc{puts 'UNDO'} 44 } 45 ], 46 47 [:separator, 'sep2'], 48 49 [:command, 'cut', { 50 :label=>'Cut', :underline=>1, 51 :helpstr=>'Cut selection to clipboard', 52 :command=>proc{puts 'CUT'} 53 } 54 ], 55 56 [:command, 'copy', { 57 :label=>'Copy', :underline=>1, 58 :helpstr=>'Copy selection to clipboard', 59 :command=>proc{puts 'COPY'} 60 } 61 ], 62 63 [:command, 'paste', { 64 :label=>'Paste', :underline=>0, 65 :helpstr=>'Paste clipboard contents', 66 :command=>proc{puts 'PASTE'} 67 } 68 ] 69 ] 70 } 71 ], 72 73 [:menubutton, 'options', { 74 :text=>'Options', :menu=>[ 75 [:options, {:tearoff=>false, :selectcolor=>'blue'}], 76 77 [:radiobutton, 'byName', { 78 :variable=>viewmode, :value=>'NAME', 79 :label=>'by Name', :helpstr=>'View files by name order', 80 :command=>proc{puts 'NAME'} 81 } 82 ], 83 84 [:radiobutton, 'byDate', { 85 :variable=>viewmode, :value=>'DATE', 86 :label=>'by Date', :helpstr=>'View files by date order', 87 :command=>proc{puts 'DATE'} 88 } 89 ], 90 91 [:cascade, 'prefs', { 92 :label=>'Preferences', :menu=>[ 93 [:command, 'colors', { 94 :label=>'Colors...', :helpstr=>'Change text colors', 95 :command=>proc{puts 'COLORS'} 96 } 97 ], 98 99 [:command, 'fonts', { 100 :label=>'Fonts...', :helpstr=>'Change text font', 101 :command=>proc{puts 'COLORS'} 102 } 103 ] 104 ] 105 } 106 ] 107 ] 108 } 109 ] 110] 111 112#mb = Tk::Iwidgets::Menubar.new(:helpvariable=>helpvar, 113# :menubuttons=>menu_spec) 114mb = Tk::Iwidgets::Menubar.new(:helpvariable=>helpvar) 115mb.configure(:menubuttons=>menu_spec) 116 117fr = TkFrame.new(:width=>300, :height=>300) 118ef = TkEntry.new(:textvariable=>helpvar) 119 120mb.pack(:anchor=>:nw, :fill=>:x, :expand=>true) 121fr.pack(:fill=>:both, :expand=>true) 122ef.pack(:anchor=>:sw, :fill=>:x, :expand=>true) 123 124Tk.mainloop 125