summaryrefslogtreecommitdiffstats
path: root/ext/tk/sample
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-21 12:55:17 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-21 12:55:17 +0000
commita4dbd5560500d6706c0ff516def851d0934b4b2b (patch)
tree27d9b56f85b13be8924e56ccc1f6009d5bd666d9 /ext/tk/sample
parentfd3d8570054621e5bfcb7a4d9e47b304f32c7a2f (diff)
downloadruby-a4dbd5560500d6706c0ff516def851d0934b4b2b.tar.gz
ruby-a4dbd5560500d6706c0ff516def851d0934b4b2b.tar.xz
ruby-a4dbd5560500d6706c0ff516def851d0934b4b2b.zip
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: http://svn.ruby-lang.org/repos/ruby/trunk@3974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r--ext/tk/sample/tktimer2.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/tk/sample/tktimer2.rb b/ext/tk/sample/tktimer2.rb
index 0359ac4d0..dc4e8a696 100644
--- a/ext/tk/sample/tktimer2.rb
+++ b/ext/tk/sample/tktimer2.rb
@@ -3,16 +3,30 @@
require "tk"
-label = TkLabel.new(:relief=>: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? }