mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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/trunk@7039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5677755bae
commit
bb4e34110b
2 changed files with 42 additions and 14 deletions
|
@ -1,3 +1,8 @@
|
|||
Fri Oct 15 18:04:35 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||
|
||||
* ext/tk/lib/tk/timer.rb: TkTimer.new(interval, loop){ ... } is
|
||||
acceptable. Add TkTimer.start ( == new + start ).
|
||||
|
||||
Fri Oct 15 12:43:09 2004 Tanaka Akira <akr@m17n.org>
|
||||
|
||||
* eval.c (Init_stack): make prototype declaration consistent with
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue