OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / ext / tk / sample / tkextlib / iwidgets / sample / menubar.rb
1 #!/usr/bin/env ruby
2 require 'tk'
3 require 'tkextlib/iwidgets'
4
5 helpvar = TkVariable.new
6 viewmode = TkVariable.new
7
8 menu_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)
114 mb = Tk::Iwidgets::Menubar.new(:helpvariable=>helpvar)
115 mb.configure(:menubuttons=>menu_spec)
116
117 fr = TkFrame.new(:width=>300, :height=>300)
118 ef = TkEntry.new(:textvariable=>helpvar)
119
120 mb.pack(:anchor=>:nw, :fill=>:x, :expand=>true)
121 fr.pack(:fill=>:both, :expand=>true)
122 ef.pack(:anchor=>:sw, :fill=>:x, :expand=>true)
123
124 Tk.mainloop