diff options
Diffstat (limited to 'ext/tk/sample/demos-en/widget')
-rw-r--r-- | ext/tk/sample/demos-en/widget | 181 |
1 files changed, 141 insertions, 40 deletions
diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index 4456f8ab5b..dc40f0a95f 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -14,6 +14,8 @@ require 'tk' ### $DEBUG=1 ########## +$RubyTk_WidgetDemo = true + #---------------------------------------------------------------- # The code below create the main window, consisting of a menu bar # and a text widget that explains how to use the program, plus lists @@ -103,14 +105,22 @@ EOD end # -TkMenubar.new($root, - [[['File', 0], - ['About ... ', proc{aboutBox}, 0, '<F1>'], - '---', - ['Quit', proc{exit}, 0, 'Meta-Q'] - ]]).pack('side'=>'top', 'fill'=>'x') +if $tk_major_ver >= 8 + $root.add_menubar([[['File', 0], + ['About ... ', proc{aboutBox}, 0, '<F1>'], + '---', + ['Quit', proc{exit}, 0, 'Ctrl-Q'] + ]]) +else + TkMenubar.new($root, + [[['File', 0], + ['About ... ', proc{aboutBox}, 0, '<F1>'], + '---', + ['Quit', proc{exit}, 0, 'Ctrl-Q'] + ]]).pack('side'=>'top', 'fill'=>'x') +end $root.bind('F1', proc{aboutBox}) -$root.bind('Meta-q', proc{exit}) +$root.bind('Control-q', proc{exit}) =begin TkFrame.new($root){|frame| @@ -316,6 +326,8 @@ txt.insert('end', "13. A simple user interface for viewing images. (if supported txt.insert('end', " \n ", tag_demospace) txt.insert('end', "14. Labelled frames (if supported)\n", tag_demo, "demo-labelframe") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "15. The simple Themed Tk widgets (require Tile/Ttk extension)\n", tag_demo, "demo-ttkbut") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") txt.insert('end', "Listboxes\n", tag_title) @@ -326,6 +338,10 @@ txt.insert('end', "2. Colors: change the color scheme for the application.\n", " txt.insert('end', " \n ", tag_demospace) txt.insert('end', "3. A collection of famous sayings.\n", tag_demo, "demo-sayings") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. A multi-column list of contries. (require Tile/Ttk extension)\n", tag_demo, "demo-mclist") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "5. A directory browser tree. (require Tile/Ttk extension)\n", tag_demo, "demo-tree") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") txt.insert('end', "Entries and Spin-boxes\n", tag_title) @@ -340,7 +356,9 @@ txt.insert('end', txt.insert('end', " \n ", tag_demospace) txt.insert('end', "4. Spin-boxes. (if supported)\n", tag_demo, "demo-spin") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "5. Simple Rolodex-like form.\n", tag_demo, "demo-form") +txt.insert('end', "5. Combo-boxes. (require Tile/Ttk extension)\n", tag_demo, "demo-combo") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "6. Simple Rolodex-like form.\n", tag_demo, "demo-form") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -380,31 +398,43 @@ txt.insert('end', "7. A building floor plan. (another way to create canvas items txt.insert('end', " \n ", tag_demospace) txt.insert('end', "8. A simple scrollable canvas.\n", tag_demo, "demo-cscroll") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "9. A Knight's tour of the chess board. (require Tile/Ttk extension)\n", tag_demo, "demo-knightstour") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Scales\n", tag_title) +txt.insert('end', "Scales and Progress Bars\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Vertical scale.\n", tag_demo.id, "demo-vscale") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. Horizontal scale.\n", tag_demo.id, "demo-hscale") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. Progress bar. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttkprogress") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Paned Windows\n", tag_title) +txt.insert('end', "Paned Windows and Notebooks\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Horizontal paned window. (if supported)\n", tag_demo.id, "demo-paned1") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. Vertical paned window. (if supported)\n", tag_demo.id, "demo-paned2") txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. Themed nested panes. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttkpane") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. Notebook widget. (require Tile/Ttk extension)\n", tag_demo.id, "demo-ttknote") +txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") -txt.insert('end', "Menus\n", tag_title) +txt.insert('end', "Menus and Toolbars\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Menus and cascades.\n", tag_demo, "demo-menu") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "2. Menus and cascades. (if supported)\n", tag_demo, "demo-menu84") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. Menubuttons\n", tag_demo, "demo-menubu") +txt.insert('end', "3. Menubuttons.\n", tag_demo, "demo-menubu") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "4. Themed menu buttons. (require Tile/Ttk extension)\n", tag_demo, "demo-ttkmenu") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "5. Themed toolbar. (require Tile/Ttk extension)\n", tag_demo, "demo-toolbar") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -412,9 +442,11 @@ txt.insert('end', "Common Dialogs\n", tag_title) txt.insert('end', " \n ", tag_demospace) txt.insert('end', "1. Message boxes.\n", tag_demo, "demo-msgbox") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "2. File selection dialog.\n", tag_demo, "demo-filebox") +txt.insert('end', "2. Message boxes with detail text. (if supported)\n", tag_demo, "demo-msgbox2") +txt.insert('end', " \n ", tag_demospace) +txt.insert('end', "3. File selection dialog.\n", tag_demo, "demo-filebox") txt.insert('end', " \n ", tag_demospace) -txt.insert('end', "3. Color picker.\n", tag_demo, "demo-clrpick") +txt.insert('end', "4. Color picker.\n", tag_demo, "demo-clrpick") txt.insert('end', " \n ", tag_demospace) txt.insert('end', "\n") @@ -470,7 +502,8 @@ def showVars1(parent, *args) end w = TkToplevel.new(parent) {|w| title "Variable values" - TkLabel.new(w) { + base = TkFrame.new(w).pack(:fill=>:both, :expand=>true) + TkLabel.new(base) { text "Variable values:" width 20 anchor 'center' @@ -492,7 +525,7 @@ def showVars1(parent, *args) .pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x') }.pack('side'=>'top', 'anchor'=>'w', 'fill'=>'x') } - TkButton.new(w) { + TkButton.new(base) { text "OK" command proc{w.destroy} }.pack('side'=>'bottom', 'pady'=>2) @@ -507,10 +540,12 @@ def showVars2(parent, *args) rescue end end - $showVarsWin[parent.path] = TkToplevel.new(parent) {|w| + $showVarsWin[parent.path] = TkToplevel.new(parent) {|top| title "Variable values" - TkLabelFrame.new(w, :text=>"Variable values:", + base = TkFrame.new(top).pack(:fill=>:both, :expand=>true) + + TkLabelFrame.new(base, :text=>"Variable values:", :font=>{:family=>'Helvetica', :size=>14}){|f| args.each{|vnam,vbody| TkGrid(TkLabel.new(f, :text=>"#{vnam}: ", :anchor=>'w'), @@ -522,15 +557,15 @@ def showVars2(parent, *args) f.grid_columnconfig(1, :weight=>1) f.grid_rowconfig(100, :weight=>1) } - TkButton.new(w, :text=>"OK", :width=>8, :default=>:active, - :command=>proc{w.destroy}){|b| - w.bind('Return', proc{b.invoke}) - w.bind('Escape', proc{b.invoke}) + TkButton.new(base, :text=>"OK", :width=>8, :default=>:active, + :command=>proc{top.destroy}){|b| + top.bind('Return', proc{b.invoke}) + top.bind('Escape', proc{b.invoke}) b.grid(:sticky=>'e', :padx=>4, :pady=>[6, 4]) } - w.grid_columnconfig(0, :weight=>1) - w.grid_rowconfig(0, :weight=>1) + base.grid_columnconfig(0, :weight=>1) + base.grid_rowconfig(0, :weight=>1) } end @@ -624,10 +659,27 @@ def _null_binding end private :_null_binding -def eval_samplecode(code) +def eval_samplecode(code, file=nil) #eval(code) #_null_binding.pseudo_toplevel_eval{ eval(code) } - Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } + #Thread.new{ _null_binding.pseudo_toplevel_eval{ eval(code) } } + Thread.new{ + _null_binding.pseudo_toplevel_eval{ + begin + if file + eval(code, binding, "(eval:#{file})") + else + eval(code) + end + rescue Exception=>e + #p e + TkBgError.show(e.class.inspect + ': ' + e.message + "\n" + + "\n---< backtrace of Ruby side >-----\n" + + e.backtrace.join("\n") + + "\n---< backtrace of Tk side >-------") + end + } + } Tk.update end @@ -647,7 +699,7 @@ def invoke(txt, idx) Tk.update # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding) # Tk.update - eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join) + eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb') txt.cursor(cursor) $tag_visited.add("#{idx} linestart +1 chars", "#{idx} lineend +1 chars") @@ -704,20 +756,26 @@ def showCode1(demo) if $code_window == nil || TkWinfo.exist?($code_window) == false $code_window = TkToplevel.new(nil) f = TkFrame.new($code_window) + TkButton.new(f) { text "Dismiss" command proc{ $code_window.destroy $code_window = nil } - }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2) + }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2, 'padx'=>25) TkButton.new(f) { text "Rerun Demo" # command proc{eval($code_text.get('1.0','end'), _null_binding)} - command proc{eval_samplecode($code_text.get('1.0','end'))} - }.pack('side'=>'left', 'expand'=>'yes', 'pady'=>2) -# f.pack('side'=>'bottom', 'expand'=>'yes', 'fill'=>'x') - f.pack('side'=>'bottom', 'fill'=>'x') + command proc{eval_samplecode($code_text.get('1.0','end'), '<viewer>')} + }.pack('side'=>'right', 'expand'=>'false', 'pady'=>2) + + TkLabel.new(f,'text'=>'line:').pack('side'=>'left') + linenum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + TkLabel.new(f,'text'=>' pos:').pack('side'=>'left') + posnum =TkLabel.new(f,'text'=>'').pack('side'=>'left') + + f.pack('side'=>'bottom', 'expand'=>'true', 'fill'=>'x') if $tk_version =~ /^4\.[01]/ s = TkScrollbar.new($code_window, 'orient'=>'vertical') @@ -776,6 +834,24 @@ def showCode1(demo) #$code_mark = TkTextMark.new($code_text, '1.0') #$code_text.set_insert('1.0') TkTextMarkInsert.new($code_text,'1.0') + + btag = TkBindTag.new + + set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + + btag.bind('Key', set_linenum, '%W') + btag.bind('Button', set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + + set_linenum.call($code_text) + fid.close end @@ -796,7 +872,13 @@ def showCode2(demo) tf.grid_columnconfigure(0, :weight=>1) bf = TkFrame.new($code_window) - + + lf = TkFrame.new(bf) + TkLabel.new(lf, :text=>'line:').pack(:side=>:left) + linenum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + TkLabel.new(lf, :text=>' pos:').pack(:side=>:left) + posnum =TkLabel.new(lf, :text=>'').pack(:side=>:left) + b_dis = TkButton.new(bf, :text=>'Dismiss', :default=>:active, :command=>proc{ $code_window.destroy @@ -809,12 +891,12 @@ def showCode2(demo) b_run = TkButton.new(bf, :text=>'Rerun Demo', :command=>proc{ # eval($code_text.get('1.0','end'), _null_binding) - eval_samplecode($code_text.get('1.0','end')) + eval_samplecode($code_text.get('1.0','end'), '<viewer>') }, :image=>$image['refresh'], :compound=>:left) - TkGrid('x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) - bf.grid_columnconfigure(0, :weight=>1) + TkGrid(lf, 'x', b_run, b_prn, b_dis, :padx=>4, :pady=>[6,4]) + bf.grid_columnconfigure(1, :weight=>1) TkGrid(tf, :sticky=>'news') TkGrid(bf, :sticky=>'ew') @@ -838,6 +920,24 @@ def showCode2(demo) $code_text.delete('1.0', 'end') $code_text.insert('1.0', fid.read) TkTextMarkInsert.new($code_text,'1.0') + + btag = TkBindTag.new + + set_linenum = proc{|w| + line, pos = w.index('insert').split('.') + linenum.text = line + posnum.text = pos + } + + btag.bind('Key', set_linenum, '%W') + btag.bind('Button', set_linenum, '%W') + + btags = $code_text.bindtags + btags.insert(btags.index($code_text.class) + 1, btag) + $code_text.bindtags = btags + + set_linenum.call($code_text) + fid.close end @@ -931,12 +1031,13 @@ end # def aboutBox Tk.messageBox('icon'=>'info', 'type'=>'ok', 'title'=>'About Widget Demo', - 'message'=>"Ruby/Tk widget demonstration Ver.1.6.4-en\n\n" + + 'message'=>"Ruby/Tk widget demonstration Ver.1.7.0-en\n\n" + "based on demos of Tk8.1 -- 8.5 " + - "( Copyright:: " + + "( Copyright of Tcl/Tk demos:: " + "(c) 1996-1997 Sun Microsystems, Inc. / " + "(c) 1997-2000 Ajuba Solutions, Inc. / " + - "(c) 2001-2003 Donal K. Fellows )\n\n" + + "(c) 2001-2007 Donal K. Fellows / " + + "(c) 2002-2007 Daniel A. Steffen )\n\n" + "Your Ruby & Tk Version ::\n" + "Ruby#{RUBY_VERSION}(#{RUBY_RELEASE_DATE})[#{RUBY_PLATFORM}] / Tk#{$tk_patchlevel}#{(Tk::JAPANIZED_TK)? '-jp': ''}\n\n" + "Ruby/Tk release date :: tcltklib #{TclTkLib::RELEASE_DATE}; tk #{Tk::RELEASE_DATE}") @@ -958,7 +1059,7 @@ ARGV.each{|cmd| end #eval(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, # _null_binding) - eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join) + eval_samplecode(IO.readlines("#{[$demo_dir, cmd].join(File::Separator)}.rb").join, cmd + '.rb') } if no_launcher $root.withdraw # hide root window |