summaryrefslogtreecommitdiff
path: root/ext/tk/sample/tktimer2.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk/sample/tktimer2.rb')
-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 0359ac4d08..dc4e8a6964 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? }