From 07cff4bd71d4d71e4901aac5df11746ce96f009b Mon Sep 17 00:00:00 2001 From: nagai Date: Sat, 21 Jun 2003 12:55:17 +0000 Subject: tk.rb : * TkRoot.new and TkToplevel.new accept Wm commands as elements of a hash argument. e.g. TkRoot.new(:title=>'App Title') TkToplevel.new(:parent=>Tk.root, :title=>'XXX', :class=>'ZZZ') sample/tktimer2.rb * add comments about the usage of a TkTimer object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 36 ++++++++++++++++++++++++++++++++++-- ext/tk/sample/tktimer2.rb | 22 ++++++++++++++++++---- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index bfa435f326..0afaa07d35 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -3538,12 +3538,13 @@ end class TkRoottrue, :widgetname=>'.') + keys.each{|k,v| new.send(k,v)} if keys # wm commands ROOT[0] = new Tk_WINDOWS["."] = new end @@ -3597,11 +3598,38 @@ class TkToplevel:raised, :width=>10) \ +# new notation : +# * symbols are acceptable as keys or values of the option hash +# * the parent widget can be given by :parent key on the option hash +root = TkRoot.new(:title=>'timer sample') +label = TkLabel.new(:parent=>root, :relief=>:raised, :width=>10) \ .pack(:side=>:bottom, :fill=>:both) -tick = proc{|aobj| - cnt = aobj.return_value + 5 +# define the procedure repeated by the TkTimer object +tick = proc{|aobj| #<== TkTimer object + cnt = aobj.return_value + 5 # return_value keeps a result of the last proc label.text format("%d.%02d", *(cnt.divmod(100))) - cnt + cnt #==> return value is kept by TkTimer object + # (so, can be send to the next repeat-proc) } timer = TkTimer.new(50, -1, tick).start(0, proc{ label.text('0.00'); 0 }) + # ==> repeat-interval : (about) 50 ms, + # repeat : infinite (-1) times, + # repeat-procedure : tick (only one, in this case) + # + # ==> wait-before-call-init-proc : 0 ms, + # init_proc : proc{ label.text('0.00'); 0 } + # + # (0ms)-> init_proc ->(50ms)-> tick ->(50ms)-> tick ->.... TkButton.new(:text=>'Start') { command proc{ timer.continue unless timer.running? } -- cgit v1.2.3