diff --git a/lib/thread_tk.rb b/lib/thread_tk.rb new file mode 100644 index 0000000..57be25c --- /dev/null +++ b/lib/thread_tk.rb @@ -0,0 +1,8 @@ +# +# thread_tk.rb : +# The eventloop of Tk (Tk.mainloop) can run on a thread other than the +# main thread. That is, when "require 'thread_tk'" is executed instead +# of or before "require 'tk'", "Thread.new{Tk.mainloop}" works properly. +# +module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD = false; end +require 'tk' diff --git a/sample/demos-en/knightstour.rb b/sample/demos-en/knightstour.rb index 1ad82fc..d3d436e 100644 --- a/sample/demos-en/knightstour.rb +++ b/sample/demos-en/knightstour.rb @@ -1,3 +1,4 @@ +#!/usr/bin/env ruby -r thread_tk # frozen_string_literal: false # Based on the widget demo of Tcl/Tk8.5.2 # The following is the original copyright text. diff --git a/sample/demos-jp/knightstour.rb b/sample/demos-jp/knightstour.rb index f4de10b..205ccad 100644 --- a/sample/demos-jp/knightstour.rb +++ b/sample/demos-jp/knightstour.rb @@ -1,3 +1,4 @@ +#!/usr/bin/env ruby -r thread_tk # -*- coding: utf-8 -*- # frozen_string_literal: false # diff --git a/sample/irbtk.rb b/sample/irbtk.rb index 8665b20..91137cd 100644 --- a/sample/irbtk.rb +++ b/sample/irbtk.rb @@ -9,6 +9,8 @@ # 'remote-tk.rb' includes 'multi-tk.rb'. # ( There is no trouble even if you give both options. ) # +require "thread_tk" + require 'remote-tk' if ARGV.delete('--remote-tk') require 'multi-tk' if ARGV.delete('--multi-tk') diff --git a/sample/irbtkw.rbw b/sample/irbtkw.rbw index b75ebca..8f49074 100644 --- a/sample/irbtkw.rbw +++ b/sample/irbtkw.rbw @@ -6,6 +6,7 @@ # release = '2008/03/08' +require 'thread_tk' require 'tk' begin require 'tktextio' @@ -13,8 +14,6 @@ rescue LoadError require File.join(File.dirname(File.expand_path(__FILE__)), 'tktextio.rb') end -require 'irb' - if TkCore::WITH_ENCODING else # $KCODE setup @@ -110,8 +109,15 @@ def STDIN.tty? end # IRB setup +require 'irb' + IRB.init_config(nil) IRB.conf[:USE_READLINE] = false +IRB.conf[:USE_MULTILINE] = false +IRB.conf[:USE_SINGLELINE] = false +IRB.conf[:USE_COLORIZE] = false +IRB.conf[:PROMPT_MODE] = :DEFAULT +IRB.conf[:VERBOSE] = false IRB.init_error irb = IRB::Irb.new IRB.conf[:MAIN_CONTEXT] = irb.context @@ -152,5 +158,8 @@ console.bind('Control-c'){ irb_thread.join # exit -ev_loop.kill -Tk.exit +begin + ev_loop.kill + Tk.exit +rescue +end diff --git a/sample/tktextio.rb b/sample/tktextio.rb index cc0326e..1096393 100644 --- a/sample/tktextio.rb +++ b/sample/tktextio.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby -r thread_tk # frozen_string_literal: false # # TkTextIO class :: handling I/O stream on a TkText widget @@ -395,6 +395,10 @@ def _block_write #################################### + def set_encoding(extern, intern = nil) + # not suppot -> do nothing + end + def <<(obj) _write(obj) self