Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To fix an issue that a library/executable script needs to run the eventloop other than the main thread only when it is executed as a command. #49

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/thread_tk.rb
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions sample/demos-en/knightstour.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions sample/demos-jp/knightstour.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env ruby -r thread_tk
# -*- coding: utf-8 -*-
# frozen_string_literal: false
#
Expand Down
2 changes: 2 additions & 0 deletions sample/irbtk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
17 changes: 13 additions & 4 deletions sample/irbtkw.rbw
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#
release = '2008/03/08'

require 'thread_tk'
require 'tk'
begin
require 'tktextio'
rescue LoadError
require File.join(File.dirname(File.expand_path(__FILE__)), 'tktextio.rb')
end

require 'irb'

if TkCore::WITH_ENCODING
else
# $KCODE setup
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion sample/tktextio.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -395,6 +395,10 @@ def _block_write

####################################

def set_encoding(extern, intern = nil)
# not suppot -> do nothing
end

def <<(obj)
_write(obj)
self
Expand Down