class TclTkIp
add ThreadGroup check to TclTkIp.new
Public Class Methods
new(*args)
click to toggle source
# File lib/multi-tk.rb, line 28 def new(*args) if Thread.current.group != ThreadGroup::Default raise SecurityError, 'only ThreadGroup::Default can call TclTkIp.new' end obj = __new__(*args) obj.instance_eval{ @force_default_encoding ||= TkUtil.untrust([false]) @encoding ||= TkUtil.untrust([nil]) def @encoding.to_s; self.join(nil); end } obj end
Also aliased as: __new__
new(*args)
click to toggle source
# File lib/tk.rb, line 31 def initialize(*args) __initialize__(*args) @force_default_encoding ||= TkUtil.untrust([false]) @encoding ||= TkUtil.untrust([nil]) def @encoding.to_s; self.join(nil); end end
Also aliased as: __initialize__
Public Instance Methods
_eval(cmd)
click to toggle source
# File lib/tk.rb, line 3008 def _eval(cmd) _fromUTF8(__eval(_toUTF8(cmd))) end
_fromUTF8(str, enc = nil)
click to toggle source
# File lib/tk.rb, line 2967 def _fromUTF8(str, enc = nil) # str must be UTF-8 or binary. enc_name = str.instance_variable_get(:@encoding) enc_name ||= Tk::Encoding::ENCODING_TABLE.get_name(str.encoding) rescue nil # is 'binary' encoding? if enc_name == Tk::Encoding::BINARY_NAME return str.dup.force_encoding(Tk::Encoding::BINARY_NAME) end # get target encoding name (if enc == nil, use default encoding) begin enc_name = Tk::Encoding::ENCODING_TABLE.get_name(enc) rescue # then, enc != nil # unknown encoding for Tk -> try to convert encoding on Ruby str = str.dup.force_encoding(Tk::Encoding::UTF8_NAME) str.encode!(enc) # modify self !! return str # if no error, probably succeed converting end encstr = __fromUTF8(str, enc_name) encstr.force_encoding(Tk::Encoding::ENCODING_TABLE.get_obj(enc_name)) encstr end
Also aliased as: __fromUTF8
_invoke(*cmds)
click to toggle source
# File lib/tk.rb, line 3012 def _invoke(*cmds) _fromUTF8(__invoke(*(cmds.collect{|cmd| _toUTF8(cmd)}))) end
Also aliased as: _invoke_without_enc, __invoke__, __invoke, _invoke_with_enc, __invoke, _invoke_with_enc
_ip_id_()
click to toggle source
# File lib/tk.rb, line 23 def _ip_id_ # for RemoteTkIp '' end
_toUTF8(str, enc = nil)
click to toggle source
with Encoding (Ruby 1.9+)
use functions on Tcl as default. but when unsupported encoding on Tcl, use methods on Ruby.
# File lib/tk.rb, line 2917 def _toUTF8(str, enc = nil) if enc # use given encoding begin enc_name = Tk::Encoding::ENCODING_TABLE.get_name(enc) rescue # unknown encoding for Tk -> try to convert encoding on Ruby str = str.dup.force_encoding(enc) str.encode!(Tk::Encoding::UTF8_NAME) # modify self !! return str # if no error, probably succeed converting end end enc_name ||= str.instance_variable_get(:@encoding) enc_name ||= Tk::Encoding::ENCODING_TABLE.get_name(str.encoding) rescue nil if enc_name # str has its encoding information encstr = __toUTF8(str, enc_name) encstr.force_encoding(Tk::Encoding::UTF8_NAME) return encstr else # str.encoding isn't supported by Tk -> try to convert on Ruby begin return str.encode(Tk::Encoding::UTF8_NAME) # new string rescue # error -> ignore, try to use default encoding of Ruby/Tk end end #enc_name ||= # Tk::Encoding::ENCODING_TABLE.get_name(Tk.encoding) rescue nil enc_name ||= Tk::Encoding::ENCODING_TABLE.get_name(nil) # is 'binary' encoding? if enc_name == Tk::Encoding::BINARY_NAME return str.dup.force_encoding(Tk::Encoding::BINARY_NAME) end # force default encoding? if ! str.kind_of?(Tk::EncodedString) && self.force_default_encoding? enc_name = Tk::Encoding::ENCODING_TABLE.get_name(Tk.default_encoding) end encstr = __toUTF8(str, enc_name) encstr.force_encoding(Tk::Encoding::UTF8_NAME) encstr end
Also aliased as: __toUTF8
default_encoding=(name)
click to toggle source
# File lib/tk.rb, line 2882 def default_encoding=(name) name = name.name if Tk::WITH_ENCODING && name.kind_of?(::Encoding) @encoding[0] = name.to_s.dup end
encoding=(name)
click to toggle source
from tkencoding.rb by ttate@jaist.ac.jp
attr_accessor :encoding
# File lib/tk.rb, line 2889 def encoding=(name) self.force_default_encoding = true # for compatibility self.default_encoding = name end
encoding_name()
click to toggle source
# File lib/tk.rb, line 2894 def encoding_name (@encoding[0])? @encoding[0].dup: nil end
Also aliased as: encoding, default_encoding
encoding_obj()
click to toggle source
# File lib/tk.rb, line 2900 def encoding_obj if Tk::WITH_ENCODING Tk::Encoding.tcl2rb_encoding(@encoding[0]) else (@encoding[0])? @encoding[0].dup: nil end end
force_default_encoding=(mode)
click to toggle source
# File lib/tk.rb, line 2874 def force_default_encoding=(mode) @force_default_encoding[0] = (mode)? true: false end
force_default_encoding?()
click to toggle source
# File lib/tk.rb, line 2878 def force_default_encoding? @force_default_encoding[0] ||= false end