diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-06-04 07:03:33 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-06-04 07:03:33 +0000 |
commit | 4cb164ee2a30ecb59ce93670e569f384c7da7521 (patch) | |
tree | b72a391e53110bb8b216ef9d16741b314f148ce6 /ext/tk/lib/tkafter.rb | |
parent | dc010ff5157787b80ed35410587d0b988d55dda4 (diff) | |
download | ruby-4cb164ee2a30ecb59ce93670e569f384c7da7521.tar.gz |
* tkfont.rb: Fix bugs on TkFont.init_widget_font for Tk8.x.
* tkafter.rb: Add self to 1st argument of interval- and loop-proc
TkAfter#current_interval returns an interval (sleep) time value
TkAfter#current_args returns an array of arguments
TkAfter#return_value returns a return value of last loop-proc
e.g.
TkAfter.new(
proc{|obj| 500 - obj.current_interval}, 10,
[proc{|obj| p obj.current_args}, 'proc', 1],
proc{|obj| p obj.current_args; ['return', 2]},
[proc{|obj|
p obj.return_value
p ['proc', obj.current_args[0].call(obj.return_value[1],
obj.current_args[1])]},
proc{|*args| args[0] + args[1]}, 1],
proc{p ['proc', 4]} ).start(100)
* tk*.rb: Allow to use Symbols for parameters.
Allow new notation of constructor (also allow old notation).
e.g.
TkFrame.new('classname'=>'User'){|base|
pack
f = TkFrame.new(base, :classname=>'ButtonFrame').pack
TkButton.new(
:parent => f,
:text => 'Quit',
:command => proc{exit}
).pack(
:fill => :x,
:pady => 2
)
}
* tkcanvas.rb: (TkcItem) Add 'coords' parameter to the canvas item
constructor (for new notation of constructor).
e.g.
c = TkCanvas.new.pack
l = TkcLine.new(c, :coords=>[[0,0], [100,100]])
* tcltklib.c: New 'mainloop' and 'mainloop_watchdog'.
The priority of their event-loop can be controlled.
They accept an optional argument.
If it false, they don't exit although the root widget is destroyed.
This function is sometimes useful, if it is used with 'restart'.
'mainloop' can't treat Thread#join/value in a callback routine.
(e.g. TkButton.new(:command=>proc{p Thread.new{button.invoke}.value}) )
'mainloop_watchdog' can treat them, but watchdog thread is always running
(so, a little heavier than 'mainloop').
If the purpose of using Thread#join/value is to do something under some
safe-level, please use Proc object.
(e.g. :command=>proc{$SAFE=1;proc{$SAFE=2;button.invoke}.call;p $SAFE})
* tk.rb: Support functions of new 'mainloop' and 'mainloop_watchdog'.
* tk.rb: (Tk.restart) Add 'app-name' paramater and 'use' parameter.
'app-name' specifies the name and the resource class of the
application. If 'app-name' is specified to 'xxx', the application
class on the resource database is set to 'Xxx' and the application
name is changed by the same rule of Tk.appname method. 'use'
specifies the main window for embedding the root widget instead of
generating a new window.
* tk.rb: Add new parameter 'widgetname' to the widget constructor to
support effective use of Resource Database. For example, the
resource 'Xxx*quit.text: QUIT' can set the text of the button
generated by the following code.
e.g.
Tk.restart('Xxx')
TkButton.new(nil, 'widgetname'=>'quit', 'command'=>proc{exit}).pack
Tk.mainloop
* tk.rb: TkOption::get always returns a tainted string.
Add TkOption::new_proc_class.
It generates a class to import procedures defined on the resource
database. For example, there is a following resource file.
----< resource-test >------------
*CMD.foo: {|*args| p [$SAFE, :foo, args]}
*CMD.XXX.bar: {|*args| p [$SAFE, :bar, args]}
*Button.command: ruby {p self; p $SAFE; TkOption::CMD::XXX.bar(1,2,3)}
---------------------------------
The following code is a sample of use of the resource file.
e.g.
require 'tk'
TkOption.readfile 'resource-test'
p TkOption.new_proc_class(:CMD, [:foo], 1)
p TkOption.new_proc_class(:XXX, [:bar], 2, false, TkOption::CMD)
TkButton.new(:text=>'test').pack
Tk.mainloop
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tkafter.rb')
-rw-r--r-- | ext/tk/lib/tkafter.rb | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb index fe3ee38740..ec39d9957f 100644 --- a/ext/tk/lib/tkafter.rb +++ b/ext/tk/lib/tkafter.rb @@ -1,6 +1,7 @@ # # tkafter.rb : methods for Tcl/Tk after command -# 2000/08/01 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp> +# +# $Id$ # require 'tk' @@ -11,18 +12,16 @@ class TkAfter Tk_CBID = [0] Tk_CBTBL = {} - INTERP._invoke("proc", "rb_after", "args", "ruby [format \"TkAfter.callback %%Q!%s!\" $args]") + INTERP._invoke("proc", "rb_after", "id", "ruby [format \"TkAfter.callback %%Q!%s!\" $id]") ############################### # class methods ############################### - def TkAfter.callback(arg) + def TkAfter.callback(obj_id) @after_id = nil - arg = Array(tk_split_list(arg)) - obj_id = arg.shift ex_obj = Tk_CBTBL[obj_id] return nil if ex_obj == nil; # canceled - _get_eval_string(ex_obj.do_callback(*arg)) + _get_eval_string(ex_obj.do_callback) end def TkAfter.info @@ -35,10 +34,10 @@ class TkAfter ############################### # instance methods ############################### - def do_callback(*args) + def do_callback @in_callback = true begin - ret = @current_proc.call(*args) + @return_value = @current_proc.call(self) rescue StandardError, NameError if @cancel_on_exception cancel @@ -48,21 +47,22 @@ class TkAfter end end if @set_next - set_next_callback(*args) + set_next_callback(@current_args) else @set_next = true end @in_callback = false - ret + @return_value end def set_callback(sleep, args=nil) - @after_script = "rb_after #{@id} #{_get_eval_string(args)}" + @after_script = "rb_after #{@id}" @after_id = tk_call('after', sleep, @after_script) + @current_args = args @current_script = [sleep, @after_script] end - def set_next_callback(*args) + def set_next_callback(args) if @running == false || @proc_max == 0 || @do_loop == 0 Tk_CBTBL[@id] = nil ;# for GC @running = false @@ -81,7 +81,7 @@ class TkAfter @current_args = args if @sleep_time.kind_of? Proc - sleep = @sleep_time.call(*args) + sleep = @sleep_time.call(self) else sleep = @sleep_time end @@ -91,15 +91,7 @@ class TkAfter @current_pos += 1 @current_proc = cmd - if cmd_args[0].kind_of? Proc - #c = cmd_args.shift - #cb_args = c.call(*(cmd_args + args)) - cb_args = cmd_args[0].call(*args) - else - cb_args = cmd_args - end - - set_callback(sleep, cb_args) + set_callback(sleep, cmd_args) end def initialize(*args) @@ -115,6 +107,7 @@ class TkAfter @current_script = [] @current_proc = nil @current_args = nil + @return_value = nil @sleep_time = 0 @current_sleep = 0 @@ -137,7 +130,10 @@ class TkAfter attr :after_id attr :after_script attr :current_proc + attr :current_args attr :current_sleep + alias :current_interval :current_sleep + attr :return_value attr_accessor :loop_exec @@ -257,7 +253,7 @@ class TkAfter set_callback(sleep, @init_args) @set_next = false if @in_callback else - set_next_callback(*@init_args) + set_next_callback(@init_args) end self |