From: NAGAI Hidetoshi Date: 1998-07-07T18:52:34+09:00 Subject: [ruby-dev:3232] Re: Ruby/Tk unofficial patch 永井@知能.九工大です. >>>>> "N" == NAGAI Hidetoshi writes: N> ありがとうございます.残る send の実装も急ぎます. send の実装,および kanjiInput の実装です. 先の patch をあてたものからの差分になっています. send についてはどうしようかと考えてましたが, 結局,ruby のスクリプトを渡す場合と,tk のスクリプトを渡す場合とを 別々に実装することにしました. ruby のスクリプトの場合は ruby { ... } で囲んでから, send で引き渡すようにしています. tk を意識させないための苦肉の策です.(^_^; 戻り値のことは迷いましたが,対策は施さないことにしました. send の仕様として,「戻り値は文字列しか許さない」とします. 勝手に中途半端な文字列加工をするよりは, 利用者が明確に戻り値を意識するようにすべきと思いましたので. # フォントについては未だ検討中で,これが解決されなければ, # widget_demo から tk_call を抹殺することができません.:-< # ちなみに widget_demo 移植は floor.tcl, bitmap.tcl が完了しました. -- 永井 秀利 (九工大 知能情報) nagai@ai.kyutech.ac.jp --- tk.rb.old Tue Jul 7 16:22:19 1998 +++ tk.rb Tue Jul 7 17:47:49 1998 @@ -379,6 +379,35 @@ tk_call('tk', 'appname', name) end + def appsend(interp, async, *args) + if async + tk_call('send', '-async', '--', interp, *args) + else + tk_call('send', '--', interp, *args) + end + end + + def rb_appsend(interp, async, *args) + args.unshift('ruby {') + args.push('}') + appsend(interp, async, *args) + end + + def appsend_displayof(interp, win, async, *args) + win = '.' if win == nil + if async + tk_call('send', '-async', '-displayof', win, '--', interp, *args) + else + tk_call('send', '-displayor', win, '--', interp, *args) + end + end + + def rb_appsend_displayof(interp, win, async, *args) + args.unshift('ruby {') + args.push('}') + appsend_displayof(interp, win, async, *args) + end + def mainloop TclTkLib.mainloop end @@ -851,6 +880,68 @@ module_function :clear, :get end +module TkKinput + include Tk + extend Tk + + def TkKinput.start(window, style=None) + tk_call 'kinput_start', window.path, style + end + def kinput_start(style=None) + TkKinput.start(self, style) + end + + def TkKinput.send_spot(window) + tk_call 'kinput_send_spot', window.path + end + def kinput_send_spot + TkKinput.send_spot(self) + end + + def TkKinput.input_start(window, keys=nil) + tk_call 'kanjiInput', 'start', window.path, *hash_kv(keys) + end + def kanji_input_start(keys=nil) + TkKinput.input_start(self, keys) + end + + def TkKinput.attribute_config(window, slot, value=None) + if slot.kind_of? Hash + tk_call 'kanjiInput', 'attribute', window.path, *hash_kv(slot) + else + tk_call 'kanjiInput', 'attribute', window.path, "-#{slot}", value + end + end + def kinput_attribute_config(slot, value=None) + TkKinput.attribute_config(self, slot, value) + end + + def TkKinput.attribute_info(window, slot=nil) + if slot + conf = tk_split_list(tk_call('kanjiInput', 'attribute', + window.path, "-#{slot}")) + conf[0] = conf[0][1..-1] + conf + else + tk_split_list(tk_call('kanjiInput', 'attribute', + window.path)).collect{|conf| + conf[0] = conf[0][1..-1] + conf + } + end + end + def kinput_attribute_info(slot=nil) + TkKinput.attribute_info(self, slot) + end + + def TkKinput.input_end(window) + tk_call 'kanjiInput', 'end', window.path + end + def kanji_input_end + TkKinput.input_end(self) + end +end + module TkWinfo include Tk extend Tk @@ -908,7 +999,7 @@ number(tk_call('winfo', 'fpixels', window.path, number)) end def winfo_fpixels(number) - TkWinfo.fpixels self + TkWinfo.fpixels self, number end def TkWinfo.geometry(window) list(tk_call('winfo', 'geometry', window.path)) @@ -927,6 +1018,29 @@ end def winfo_id TkWinfo.id self + 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 + } + else + tk_split_list(tk_call('winfo', 'interps')).collect{|ip| + if ip.kind_of? Array + ip.flatten.join(' ') + else + ip + end + } + end + end + def winfo_interps + TkWinfo.interps self end def TkWinfo.mapped?(window) bool(tk_call('winfo', 'ismapped', window.path))