summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/timer.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-15 09:06:52 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-15 09:06:52 +0000
commitc00d928b3e90b3b3cae414d88e3f3f957e507922 (patch)
tree71943504d8cc539dc54c9bd0df2c5cf5e26b031f /ext/tk/lib/tk/timer.rb
parent84ce932c031a92230b8dd8db14d7a28ad3cd36f4 (diff)
* ext/tk/lib/tk/timer.rb: TkTimer.new(interval, loop){ ... } is acceptable.
Add TkTimer.start ( == new + start ). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk/timer.rb')
-rw-r--r--ext/tk/lib/tk/timer.rb51
1 files changed, 37 insertions, 14 deletions
diff --git a/ext/tk/lib/tk/timer.rb b/ext/tk/lib/tk/timer.rb
index a6d7efa..27c40e5 100644
--- a/ext/tk/lib/tk/timer.rb
+++ b/ext/tk/lib/tk/timer.rb
@@ -27,6 +27,10 @@ class TkTimer
###############################
# class methods
###############################
+ def self.start(*args, &b)
+ self.new(*args, &b).start
+ end
+
def self.callback(obj_id)
ex_obj = Tk_CBTBL[obj_id]
return "" if ex_obj == nil; # canceled
@@ -53,6 +57,7 @@ class TkTimer
end
end
+
###############################
# instance methods
###############################
@@ -131,7 +136,7 @@ class TkTimer
set_callback(sleep, cmd_args)
end
- def initialize(*args)
+ def initialize(*args, &b)
# @id = Tk_CBID.join('')
@id = Tk_CBID.join(TkCore::INTERP._ip_id_)
Tk_CBID[1].succ!
@@ -170,6 +175,17 @@ class TkTimer
# callback procedures silently (TkTimer#cancel is called and no dialog is
# shown).
+ if b
+ case args.size
+ when 0
+ add_procs(b)
+ when 1
+ args << -1 << b
+ else
+ args << b
+ end
+ end
+
set_procs(*args) if args != []
@running = false
@@ -227,8 +243,16 @@ class TkTimer
#self
end
+ def set_interval(interval)
+ if interval != 'idle' \
+ && !interval.kind_of?(Integer) && !interval.kind_of?(Proc)
+ fail ArguemntError, "expect Integer or Proc"
+ end
+ @sleep_time = interval
+ end
+
def set_procs(interval, loop_exec, *procs)
- if !interval == 'idle' \
+ if interval != 'idle' \
&& !interval.kind_of?(Integer) && !interval.kind_of?(Proc)
fail ArguemntError, "expect Integer or Proc for 1st argument"
end
@@ -245,20 +269,19 @@ class TkTimer
@proc_max = @loop_proc.size
@current_pos = 0
- @do_loop = 0
- if loop_exec
- if loop_exec.kind_of?(Integer) && loop_exec < 0
- @loop_exec = -1
- elsif loop_exec == nil || loop_exec == false || loop_exec == 0
- @loop_exec = 1
- else
- if not loop_exec.kind_of?(Integer)
- fail ArguemntError, "expect Integer for 2nd argument"
- end
- @loop_exec = loop_exec
+ if loop_exec.kind_of?(Integer) && loop_exec < 0
+ @loop_exec = -1
+ elsif loop_exec == true
+ @loop_exec = -1
+ elsif loop_exec == nil || loop_exec == false || loop_exec == 0
+ @loop_exec = 0
+ else
+ if not loop_exec.kind_of?(Integer)
+ fail ArguemntError, "expect Integer for 2nd argument"
end
- @do_loop = @loop_exec
+ @loop_exec = loop_exec
end
+ @do_loop = @loop_exec
self
end