From: Roger Pack <rogerdpack2 / gmail.com> Subject: [ruby-core:30550] Re: tk doesn't startup well in doze Date: Wed, 2 Jun 2010 02:00:37 +0900 Message-ID: <AANLkTikvMjqGfg9sp4Ac4uNoFaH98qLEFInw3vas6rqM / mail.gmail.com> > With 1.9.3 I now get this (exits fine, with mystery window, but > running an app yields:) > > irb(main):009:0> Tk.mainloop > RuntimeError: can't unset "__initail_state_of_rubytk__": no such variable Please give me one more help. Does the following patch work? Or does it need "RUN_EVENTLOOP_ON_MAIN_THREAD=true" to work fine? If the patch doesn't and "RUN_EVENTLOOP_ON_MAIN_THREAD=true" works, I set RUN_EVENTLOOP_ON_MAIN_THREAD to true as default on windows. Index: ext/tk/lib/tk.rb =================================================================== --- ext/tk/lib/tk.rb (revision 28127) +++ ext/tk/lib/tk.rb (working copy) @@ -1229,7 +1229,8 @@ INTERP_ROOT_CHECK = ConditionVariable.new INTERP_THREAD = Thread.new{ begin - Thread.current[:interp] = interp = TclTkIp.new(name, opts) + #Thread.current[:interp] = interp = TclTkIp.new(name, opts) + interp = TclTkIp.new(name, opts) rescue => e Thread.current[:interp] = e raise e @@ -1245,16 +1246,17 @@ Thread.current[:status] = status #sleep - # like as 1.8, withdraw a root widget before calling Tk.mainloop interp._eval <<EOS +wm withdraw . rename wm __wm_orig__ proc wm {subcmd win args} { - eval [list __wm_orig__ $subcmd $win] $args + set val [eval [list __wm_orig__ $subcmd $win] $args] if {[string equal $subcmd withdraw] && [string equal $win .]} { rename wm {} rename __wm_orig__ wm } + return val } proc __startup_rbtk_mainloop__ {args} { rename __startup_rbtk_mainloop__ {} @@ -1275,6 +1277,7 @@ #TclTkLib.mainloop_abort_on_exception = false #Thread.current[:status].value = TclTkLib.mainloop(true) interp.mainloop_abort_on_exception = true + Thread.current[:interp] = interp Thread.current[:status].value = interp.mainloop(true) rescue SystemExit=>e Thread.current[:status].value = e @@ -1836,7 +1839,7 @@ end # like as 1.8, withdraw a root widget before calling Tk.mainloop - TkCore::INTERP._eval_without_enc('unset __initail_state_of_rubytk__') + TkCore::INTERP._eval_without_enc('catch {unset __initial_state_of_rubytk__}') begin TclTkLib.set_eventloop_window_mode(true) -- Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)