1# ttkmenu.rb -- 2# 3# This demonstration script creates a toplevel window containing several Ttk 4# menubutton widgets. 5# 6# based on "Id: ttkmenu.tcl,v 1.3 2007/12/13 15:27:07 dgp Exp" 7 8if defined?($ttkmenu_demo) && $ttkmenu_demo 9 $ttkmenu_demo.destroy 10 $ttkmenu_demo = nil 11end 12 13$ttkmenu_demo = TkToplevel.new {|w| 14 title("Ttk Menu Buttons") 15 iconname("ttkmenu") 16 positionWindow(w) 17} 18 19base_frame = Ttk::Frame.new($ttkmenu_demo).pack(:fill=>:both, :expand=>true) 20 21Ttk::Label.new(base_frame, :font=>$font, :wraplength=>'4i', :justify=>:left, 22 :text=><<EOL).pack(:side=>:top, :fill=>:x) 23Ttk is the new Tk themed widget set, \ 24and one widget that is available in themed form is the menubutton. \ 25Below are some themed menu buttons \ 26that allow you to pick the current theme in use. \ 27Notice how picking a theme changes the way \ 28that the menu buttons themselves look, \ 29and that the central menu button is styled differently \ 30(in a way that is normally suitable for toolbars). \ 31However, there are no themed menus; the standard Tk menus were judged \ 32to have a sufficiently good look-and-feel on all platforms, \ 33especially as they are implemented as native controls in many places. 34EOL 35 36Ttk::Separator.new(base_frame).pack(:side=>:top, :fill=>:x) 37 38## See Code / Dismiss 39Ttk::Frame.new($ttkmenu_demo) {|frame| 40 sep = Ttk::Separator.new(frame) 41 Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) 42 TkGrid('x', 43 Ttk::Button.new(frame, :text=>'See Code', 44 :image=>$image['view'], :compound=>:left, 45 :command=>proc{showCode 'ttkmenu'}), 46 Ttk::Button.new(frame, :text=>'Dismiss', 47 :image=>$image['delete'], :compound=>:left, 48 :command=>proc{ 49 $ttkmenu_demo.destroy 50 $ttkmenu_demo = nil 51 }), 52 :padx=>4, :pady=>4) 53 grid_columnconfigure(0, :weight=>1) 54 pack(:side=>:bottom, :fill=>:x) 55} 56 57b1 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:above) 58b2 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:left) 59b3 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:right) 60b4 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:flush, 61 :style=>Ttk::Menubutton.style('Toolbutton')) 62b5 = Ttk::Menubutton.new(base_frame,:text=>'Select a theme',:direction=>:below) 63 64b1.menu(m1 = Tk::Menu.new(b1, :tearoff=>false)) 65b2.menu(m2 = Tk::Menu.new(b2, :tearoff=>false)) 66b3.menu(m3 = Tk::Menu.new(b3, :tearoff=>false)) 67b4.menu(m4 = Tk::Menu.new(b4, :tearoff=>false)) 68b5.menu(m5 = Tk::Menu.new(b5, :tearoff=>false)) 69 70Ttk.themes.each{|theme| 71 m1.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) 72 m2.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) 73 m3.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) 74 m4.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) 75 m5.add(:command, :label=>theme, :command=>proc{Ttk.set_theme theme}) 76} 77 78f = Ttk::Frame.new(base_frame).pack(:fill=>:x) 79f1 = Ttk::Frame.new(base_frame).pack(:fill=>:both, :expand=>true) 80f.lower 81 82f.grid_anchor(:center) 83TkGrid('x', b1, 'x', :in=>f, :padx=>3, :pady=>2) 84TkGrid(b2, b4, b3, :in=>f, :padx=>3, :pady=>2) 85TkGrid('x', b5, 'x', :in=>f, :padx=>3, :pady=>2) 86