1# ttknote.rb -- 2# 3# This demonstration script creates a toplevel window containing a Ttk 4# notebook widget. 5# 6# based on "Id: ttknote.tcl,v 1.5 2007/12/13 15:27:07 dgp Exp" 7 8if defined?($ttknote_demo) && $ttknote_demo 9 $ttknote_demo.destroy 10 $ttknote_demo = nil 11end 12 13$ttknote_demo = TkToplevel.new {|w| 14 title("Ttk Notebook Widget") 15 iconname("ttknote") 16 positionWindow(w) 17} 18 19## See Code / Dismiss 20Ttk::Frame.new($ttknote_demo) {|frame| 21 sep = Ttk::Separator.new(frame) 22 Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2) 23 TkGrid('x', 24 Ttk::Button.new(frame, :text=>'See Code', 25 :image=>$image['view'], :compound=>:left, 26 :command=>proc{showCode 'ttknote'}), 27 Ttk::Button.new(frame, :text=>'Dismiss', 28 :image=>$image['delete'], :compound=>:left, 29 :command=>proc{ 30 $ttknote_demo.destroy 31 $ttknote_demo = nil 32 }), 33 :padx=>4, :pady=>4) 34 grid_columnconfigure(0, :weight=>1) 35 pack(:side=>:bottom, :fill=>:x) 36} 37 38base_frame = Ttk::Frame.new($ttknote_demo).pack(:fill=>:both, :expand=>true) 39 40## Make the notebook and set up Ctrl+Tab traversal 41notebook = Ttk::Notebook.new(base_frame).pack(:fill=>:both, :expand=>true, 42 :padx=>2, :pady=>3) 43notebook.enable_traversal 44 45## Popuplate the first pane 46f_msg = Ttk::Frame.new(notebook) 47msg_m = Ttk::Label.new(f_msg, :font=>$font, :wraplength=>'4i', 48 :justify=>:left, :anchor=>'n', :text=><<EOL) 49Ttk is the new Tk themed widget set. \ 50One of the widgets it includes is the notebook widget, \ 51which provides a set of tabs that allow the selection of a group of panels, \ 52each with distinct content. \ 53They are a feature of many modern user interfaces. \ 54Not only can the tabs be selected with the mouse, \ 55but they can also be switched between using Ctrl+Tab \ 56when the notebook page heading itself is selected. \ 57Note that the second tab is disabled, and cannot be selected. 58EOL 59neat = TkVariable.new 60after_id = nil 61msg_b = Ttk::Button.new(f_msg, :text=>'Neat!', :underline=>0, 62 :command=>proc{ 63 neat.value = 'Yeah, I know...' 64 Tk.after_cancel(after_id) if after_id 65 after_id = Tk.after(500){neat.value = ''} 66 }) 67msg_b.winfo_toplevel.bind('Alt-n'){ msg_b.focus; msg_b.invoke } 68msg_l = Ttk::Label.new(f_msg, :textvariable=>neat) 69notebook.add(f_msg, :text=>'Description', :underline=>0, :padding=>2) 70Tk.grid(msg_m, '-', :sticky=>'new', :pady=>2) 71Tk.grid(msg_b, msg_l, :pady=>[2, 4]) 72f_msg.grid_rowconfigure(1, :weight=>1) 73f_msg.grid_columnconfigure([0, 1], :weight=>1, :uniform=>1) 74 75## Populate the second pane. Note that the content doesn't really matter 76f_disabled = Ttk::Frame.new(notebook) 77notebook.add(f_disabled, :text=>'Disabled', :state=>:disabled) 78 79## Popuplate the third pane 80f_editor = Ttk::Frame.new(notebook) 81notebook.add(f_editor, :text=>'Text Editor', :underline=>0) 82editor_t = Tk::Text.new(f_editor, :width=>40, :height=>10, :wrap=>:char) 83if Tk.windowingsystem != 'aqua' 84 editor_s = editor_t.yscrollbar(Ttk::Scrollbar.new(f_editor)) 85else 86 editor_s = editor_t.yscrollbar(Tk::Scrollbar.new(f_editor)) 87end 88editor_s.pack(:side=>:right, :fill=>:y, :padx=>[0,2], :pady=>2) 89editor_t.pack(:fill=>:both, :expand=>true, :padx=>[2,0], :pady=>2) 90