diff options
| author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 05:04:30 +0000 |
|---|---|---|
| committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-02 05:04:30 +0000 |
| commit | 01d614d05fa34345e9c8e1521684984aaaa05658 (patch) | |
| tree | 92b661314bdfd045882e365e3e43b77f57244725 /ext/tk/sample/tktimer3.rb | |
| parent | e3689350394195b3d82013f58a586d5f461cc6b8 (diff) | |
| download | ruby-01d614d05fa34345e9c8e1521684984aaaa05658.tar.gz ruby-01d614d05fa34345e9c8e1521684984aaaa05658.tar.xz ruby-01d614d05fa34345e9c8e1521684984aaaa05658.zip | |
* (bug fix) TkEntry#delete
* (bug fix) some widget demos
* support <TkVariable object> == <Symbol>
( "coerce TkVariable" add to the TODO list :-) )
* freeze some object for security reason
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tktimer3.rb')
| -rw-r--r-- | ext/tk/sample/tktimer3.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ext/tk/sample/tktimer3.rb b/ext/tk/sample/tktimer3.rb new file mode 100644 index 000000000..e3bb4c3e4 --- /dev/null +++ b/ext/tk/sample/tktimer3.rb @@ -0,0 +1,59 @@ +#!/usr/bin/env ruby +# This script is a re-implementation of tktimer.rb with TkTimer(TkAfter) class. + +require "tk" + +# 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) + +# 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 #==> 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 ->.... + +b_start = TkButton.new(:text=>'Start', :state=>:disabled) { + pack(:side=>:left, :fill=>:both, :expand=>true) +} + +b_stop = TkButton.new(:text=>'Stop', :state=>:normal) { + pack('side'=>'left', 'fill'=>'both', 'expand'=>'yes') +} + +b_start.command { + timer.continue + b_stop.state(:normal) + b_start.state(:disabled) +} + +b_stop.command { + timer.stop + b_start.state(:normal) + b_stop.state(:disabled) +} + +TkButton.new(:text=>'Reset', :state=>:normal) { + command { timer.reset } + pack(:side=>:right, :fill=>:both, :expand=>:yes) +} + +ev_quit = TkVirtualEvent.new('Control-c', 'Control-q') +Tk.root.bind(ev_quit, proc{Tk.exit}).focus + +Tk.mainloop |
