From 334b2c9f855ca8e4a36d34c6e600f5203ec017a5 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 21 Jul 1998 09:18:05 +0000 Subject: st.c(rehash) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/tk.rb | 313 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 288 insertions(+), 25 deletions(-) (limited to 'lib/tk.rb') diff --git a/lib/tk.rb b/lib/tk.rb index dc52675d59..7c04798222 100644 --- a/lib/tk.rb +++ b/lib/tk.rb @@ -25,6 +25,28 @@ module TkComm end private :error_at + def _genobj_for_tkwidget(path) + return TkRoot.new if path == '.' + + begin + tk_class = TkCore::INTERP._invoke('winfo', 'class', path) + rescue + return path + end + + ruby_class = TkClassBind::WidgetClassNameTBL[tk_class] + gen_class_name = ruby_class.name + 'GeneratedOnTk' + unless Object.const_defined? gen_class_name + eval "class #{gen_class_name}<#{ruby_class.name} + def initialize(path) + @path=path + Tk_WINDOWS[@path] = self + end + end" + end + eval "#{gen_class_name}.new('#{path}')" + end + def tk_tcl2ruby(val) if val =~ /^rb_out (c\d+)/ return Tk_CMDTBL[$1] @@ -38,7 +60,7 @@ module TkComm when /^-?\d+$/ val.to_i when /^\./ - Tk_WINDOWS[val] + Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val) when / / val.split.collect{|elt| tk_tcl2ruby(elt) @@ -74,7 +96,33 @@ module TkComm list += tk_split_list(str[i+1..-1]) list end - private :tk_tcl2ruby, :tk_split_list + + def tk_split_simplelist(str) + return [] if str == "" + idx = str.index('{') + return str.split unless idx + + list = str[0,idx].split + str = str[idx+1..-1] + i = -1 + brace = 1 + str.each_byte {|c| + i += 1 + brace += 1 if c == ?{ + brace -= 1 if c == ?} + break if brace == 0 + } + if i == 0 + list.push '' + elsif str[0, i] == ' ' + list.push ' ' + else + list.push str[0..i-1] + end + list += tk_split_simplelist(str[i+1..-1]) + list + end + private :tk_tcl2ruby, :tk_split_list, :tk_split_simplelist def hash_kv(keys) conf = [] @@ -425,6 +473,10 @@ module TkCore appsend_displayof(interp, win, async, *args) end + def info(*args) + tk_call('info', *args) + end + def mainloop TclTkLib.mainloop end @@ -661,7 +713,7 @@ class TkVariable def value begin - INTERP._eval(format('global %s; set %s', @id, @id)) + tk_tcl2ruby(INTERP._eval(format('global %s; set %s', @id, @id))) rescue if INTERP._eval(format('global %s; array exists %s', @id, @id)) != "1" raise @@ -1029,7 +1081,7 @@ module TkWinfo TkWinfo.classname self end def TkWinfo.containing(rootX, rootY) - path = tk_call('winfo', 'class', window.path) + path = tk_call('winfo', 'containing', rootX, rootY) window(path) end def winfo_containing(x, y) @@ -1073,22 +1125,10 @@ module TkWinfo end def TkWinfo.interps(window=nil) if window - tk_split_list(tk_call('winfo', '-displayof', window.path, - 'interps')).collect{|ip| - if ip.kind_of? Array - ip.flatten.join(' ') - else - ip - end - } + tk_split_simplelist(tk_call('winfo', '-displayof', window.path, + 'interps')) else - tk_split_list(tk_call('winfo', 'interps')).collect{|ip| - if ip.kind_of? Array - ip.flatten.join(' ') - else - ip - end - } + tk_split_simplelist(tk_call('winfo', 'interps')) end end def winfo_interps @@ -1100,6 +1140,12 @@ module TkWinfo def winfo_mapped? TkWinfo.mapped? self end + def TkWinfo.appname(window) + bool(tk_call('winfo', 'name', window.path)) + end + def winfo_appname + TkWinfo.appname self + end def TkWinfo.parent(window) window(tk_call('winfo', 'parent', window.path)) end @@ -1803,16 +1849,51 @@ class TkToplevelval}) + else + tk_call 'entryconfigure', index, "-#{key}", val + end + end + end + + def entryconfiginfo(index, key=nil) + if key + conf = tk_split_list(tk_send('entryconfigure',index,"-#{key}")) + conf[0] = conf[0][1..-1] + conf + else + tk_split_list(tk_send('entryconfigure', index)).collect{|conf| + conf[0] = conf[0][1..-1] + conf + } + end + end end class TkMenubutton