summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-25 16:43:03 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-25 16:43:03 +0000
commitcc66b1fae449cd360ab33fbbe8b598510e3fec26 (patch)
treecbdd5cce8ccbe910203e03c97b4542e7240d8329 /ext/tk/lib/tk.rb
parent2b15bd05d3ec35390b07e1305a118040a4c320b3 (diff)
tcltklib.c : add TclTkIp#create_slave , TclTkIp#_make_safe and TclTkIp#safe?
MANUAL.euc : modify descriptions tk.rb : bug fix [ruby-talk:76980] and modify to support multi Tk IPs tkafter.rb : modify to support multi Tk IPs git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk.rb')
-rw-r--r--ext/tk/lib/tk.rb69
1 files changed, 46 insertions, 23 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index e0c11c1c0d..b84b0a7c48 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -1,4 +1,4 @@
-#
+
# tk.rb - Tk interface module using tcltklib
# $Date$
# by Yukihiro Matsumoto <matz@netlab.jp>
@@ -251,7 +251,8 @@ module TkComm
def procedure(val)
if val =~ /^rb_out (c\d+)/
#Tk_CMDTBL[$1]
- TkCore::INTERP.tk_cmd_tbl[$1]
+ #TkCore::INTERP.tk_cmd_tbl[$1]
+ TkCore::INTERP.tk_cmd_tbl[$1].cmd
else
#nil
val
@@ -291,6 +292,7 @@ module TkComm
return str
end
private :_get_eval_string
+ module_function :_get_eval_string
def ruby2tcl(v)
if v.kind_of?(Hash)
@@ -319,7 +321,7 @@ module TkComm
return '' if cmd == ''
id = _next_cmd_id
#Tk_CMDTBL[id] = cmd
- TkCore::INTERP.tk_cmd_tbl[id] = cmd
+ TkCore::INTERP.tk_cmd_tbl[id] = TkCore::INTERP.get_cb_entry(cmd)
@cmdtbl = [] unless defined? @cmdtbl
@cmdtbl.push id
return format("rb_out %s", id);
@@ -656,8 +658,8 @@ module TkCore
INTERP = TclTkIp.new(name, opts)
- def INTERP.__ip_id
- nil
+ def INTERP.__getip
+ self
end
INTERP.instance_eval{
@@ -667,8 +669,20 @@ module TkCore
@tk_table_list = []
@init_ip_env = [] # table of Procs
- @add_tk_procs = [] # table of [name, body]
+ @add_tk_procs = [] # table of [name, args, body]
+
+ @cb_entry_class = Class.new{|c|
+ def initialize(ip, cmd)
+ @ip = ip
+ @cmd = cmd
+ end
+ attr_reader :ip, :cmd
+ def call(*args)
+ @ip.cb_eval(@cmd, *args)
+ end
+ }
}
+
def INTERP.tk_cmd_tbl
@tk_cmd_tbl
end
@@ -691,13 +705,20 @@ module TkCore
return obj
end
+ def INTERP.get_cb_entry(cmd)
+ @cb_entry_class.new(__getip, cmd).freeze
+ end
+ def INTERP.cb_eval(cmd, *args)
+ TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *args))
+ end
+
def INTERP.init_ip_env(script = Proc.new)
@init_ip_env << script
script.call(self)
end
- def INTERP.add_tk_procs(name, args, body)
+ def INTERP.add_tk_procs(name, args = nil, body = nil)
@add_tk_procs << [name, args, body]
- self._invoke('proc', name, args, body)
+ self._invoke('proc', name, args, body) if args && body
end
def INTERP.init_ip_internal
ip = self
@@ -726,6 +747,20 @@ module TkCore
fail TkCallbackContinue, "Tk callback returns 'continue' status"
end
+ def TkCore.callback(arg)
+ # arg = tk_split_list(arg)
+ arg = tk_split_simplelist(arg)
+ #_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
+ #_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift],
+ # *arg))
+ cb_obj = TkCore::INTERP.tk_cmd_tbl[arg.shift]
+ cb_obj.call(*arg)
+ end
+
+ def load_cmd_on_ip(tk_cmd)
+ bool(tk_call('auto_load', tk_cmd))
+ end
+
def after(ms, cmd=Proc.new)
myid = _curr_cmd_id
cmdid = install_cmd(cmd)
@@ -794,14 +829,6 @@ module TkCore
tk_call('clock','seconds').to_i
end
- def TkCore.callback(arg)
- # arg = tk_split_list(arg)
- arg = tk_split_simplelist(arg)
- #_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
- _get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift],
- *arg))
- end
-
def windowingsystem
tk_call('tk', 'windowingsystem')
end
@@ -898,7 +925,7 @@ module TkCore
TkCore::INTERP.init_ip_internal
tk_call('set', 'argv0', app_name) if app_name
- if keys.kind_of?(Hash) && keys.size > 0
+ if keys.kind_of?(Hash)
# tk_call('set', 'argc', keys.size * 2)
tk_call('set', 'argv', hash_kv(keys).join(' '))
end
@@ -937,10 +964,6 @@ module TkCore
tk_call 'tk_chooseColor', *hash_kv(keys)
end
- def chooseDirectory(keys = nil)
- tk_call 'tk_chooseDirectory', *hash_kv(keys)
- end
-
def ip_eval(cmd_string)
res = INTERP._eval(cmd_string)
if INTERP._return_value() != 0
@@ -1484,11 +1507,11 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
TkCommandNames = ['encoding'.freeze].freeze
def encoding=(name)
- INTERP.encoding = name
+ TkCore::INTERP.encoding = name
end
def encoding
- INTERP.encoding
+ TkCore::INTERP.encoding
end
def encoding_names