class RemoteTkIp

Public Class Methods

do_one_event(flag = nil) click to toggle source
# File lib/remote-tk.rb, line 483
def do_one_event(flag = nil)
  fail RuntimeError, 'not support "do_one_event" on the remote interpreter'
end
get_eventloop_tick() click to toggle source
# File lib/remote-tk.rb, line 495
def get_eventloop_tick
  fail RuntimeError, 'not support "get_eventloop_tick" on the remote interpreter'
end
get_eventloop_weight() click to toggle source
# File lib/remote-tk.rb, line 507
def get_eventloop_weight
  fail RuntimeError, 'not support "get_eventloop_weight" on the remote interpreter'
end
get_no_event_wait() click to toggle source
# File lib/remote-tk.rb, line 501
def get_no_event_wait
  fail RuntimeError, 'not support "get_no_event_wait" on the remote interpreter'
end
mainloop(*args) click to toggle source
# File lib/remote-tk.rb, line 477
def mainloop(*args)
  fail RuntimeError, 'not support "mainloop" on the remote interpreter'
end
mainloop_abort_on_exception() click to toggle source
# File lib/remote-tk.rb, line 486
def mainloop_abort_on_exception
  fail RuntimeError, 'not support "mainloop_abort_on_exception" on the remote interpreter'
end
mainloop_abort_on_exception=(mode) click to toggle source
# File lib/remote-tk.rb, line 489
def mainloop_abort_on_exception=(mode)
  fail RuntimeError, 'not support "mainloop_abort_on_exception=" on the remote interpreter'
end
mainloop_watchdog(*args) click to toggle source
# File lib/remote-tk.rb, line 480
def mainloop_watchdog(*args)
  fail RuntimeError, 'not support "mainloop_watchdog" on the remote interpreter'
end
manipulable?() click to toggle source
# File lib/remote-tk.rb, line 128
def self.manipulable?
  true
end
new(*args, &b) click to toggle source
# File lib/remote-tk.rb, line 58
def new(*args, &b)
  ip = __new(*args)
  ip.eval_proc(&b) if b
  ip
end
new(remote_ip, displayof=nil, timeout=5) click to toggle source
# File lib/remote-tk.rb, line 66
def initialize(remote_ip, displayof=nil, timeout=5)
  @interp = MultiTkIp.__getip
  if @interp.safe?
    fail SecurityError, "safe-IP cannot create RemoteTkIp"
  end


  @interp.allow_ruby_exit = false
  @appname = @interp._invoke('tk', 'appname')
  @remote = remote_ip.to_s.dup.freeze
  if displayof.kind_of?(TkWindow)
    @displayof = displayof.path.dup.freeze
  else
    @displayof = nil
  end
  if self.deleted?
    fail RuntimeError, "no Tk application named \"#{@remote}\""
  end

  @tk_windows = {}
  @tk_table_list = []
  @slave_ip_tbl = {}
  @slave_ip_top = {}

  @force_default_encoding ||= [false]
  @encoding ||= [nil]
  def @encoding.to_s; self.join(nil); end

  @system = Object.new

  @threadgroup  = ThreadGroup.new

  @safe_level = [0]

  @wait_on_mainloop = [true, 0]

  @cmd_queue = Queue.new

  @@DEFAULT_MASTER.assign_receiver_and_watchdog(self)

  @@IP_TABLE[@threadgroup] = self
  @@TK_TABLE_LIST.size.times{
    @tk_table_list << {}
  }

  @ret_val = TkVariable.new
  if timeout > 0 && ! _available_check(timeout)
    fail RuntimeError, "cannot create connection"
  end
  @ip_id = _create_connection

  class << self
    undef :instance_eval
  end

  self.freeze  # defend against modification
end
set_eventloop_tick(*args) click to toggle source
# File lib/remote-tk.rb, line 492
def set_eventloop_tick(*args)
  fail RuntimeError, 'not support "set_eventloop_tick" on the remote interpreter'
end
set_eventloop_weight(*args) click to toggle source
# File lib/remote-tk.rb, line 504
def set_eventloop_weight(*args)
  fail RuntimeError, 'not support "set_eventloop_weight" on the remote interpreter'
end
set_no_event_wait(*args) click to toggle source
# File lib/remote-tk.rb, line 498
def set_no_event_wait(*args)
  fail RuntimeError, 'not support "set_no_event_wait" on the remote interpreter'
end

Public Instance Methods

__eval(str) click to toggle source
# File lib/remote-tk.rb, line 321
def __eval(str)
  _appsend(false, false, str)
end
__invoke(*args) click to toggle source
# File lib/remote-tk.rb, line 338
def __invoke(*args)
  _appsend(false, false, *args)
end
_conv_listelement(str) click to toggle source
# File lib/remote-tk.rb, line 432
def _conv_listelement(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._conv_listelement(str)
end
_create_console() click to toggle source
# File lib/remote-tk.rb, line 437
def _create_console
  fail RuntimeError, 'not support "_create_console" on the remote interpreter'
end
_eval(str) click to toggle source
# File lib/remote-tk.rb, line 324
def _eval(str)
  _appsend(nil, false, str)
end
_eval_with_enc(str) click to toggle source
# File lib/remote-tk.rb, line 330
def _eval_with_enc(str)
  _appsend(true, false, str)
end
_eval_without_enc(str) click to toggle source
# File lib/remote-tk.rb, line 327
def _eval_without_enc(str)
  _appsend(false, false, str)
end
_fromUTF8(str, encoding=nil) click to toggle source
# File lib/remote-tk.rb, line 356
def _fromUTF8(str, encoding=nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._fromUTF8(str, encoding)
end
_get_global_var(var_name) click to toggle source
# File lib/remote-tk.rb, line 401
def _get_global_var(var_name)
  _appsend(false, 'set', TkComm::_get_eval_string(var_name))
end
_get_global_var2(var_name, index_name) click to toggle source
# File lib/remote-tk.rb, line 404
def _get_global_var2(var_name, index_name)
  _appsend(false, 'set', "#{TkComm::_get_eval_string(var_name)}(#{TkComm::_get_eval_string(index_name)})")
end
_get_variable(var_name, flag) click to toggle source
# File lib/remote-tk.rb, line 374
def _get_variable(var_name, flag)
  # ignore flag
  _appsend(false, 'set', TkComm::_get_eval_string(var_name))
end
_get_variable2(var_name, index_name, flag) click to toggle source
# File lib/remote-tk.rb, line 378
def _get_variable2(var_name, index_name, flag)
  # ignore flag
  _appsend(false, 'set', "#{TkComm::_get_eval_string(var_name)}(#{TkComm::_get_eval_string(index_name)})")
end
_invoke(*args) click to toggle source
# File lib/remote-tk.rb, line 334
def _invoke(*args)
  _appsend(nil, false, *args)
end
_invoke_with_enc(*args) click to toggle source
# File lib/remote-tk.rb, line 347
def _invoke_with_enc(*args)
  _appsend(true, false, *args)
end
_invoke_without_enc(*args) click to toggle source
# File lib/remote-tk.rb, line 344
def _invoke_without_enc(*args)
  _appsend(false, false, *args)
end
_ip_id_() click to toggle source
# File lib/remote-tk.rb, line 137
def _ip_id_
  @ip_id
end
_merge_tklist(*args) click to toggle source
# File lib/remote-tk.rb, line 427
def _merge_tklist(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._merge_tklist(*args)
end
_return_value() click to toggle source
# File lib/remote-tk.rb, line 369
def _return_value
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._return_value
end
_set_global_var(var_name, value) click to toggle source
# File lib/remote-tk.rb, line 408
def _set_global_var(var_name, value)
  _appsend(false, 'set', TkComm::_get_eval_string(var_name), TkComm::_get_eval_string(value))
end
_set_global_var2(var_name, index_name, value) click to toggle source
# File lib/remote-tk.rb, line 411
def _set_global_var2(var_name, index_name, value)
  _appsend(false, 'set', "#{TkComm::_get_eval_string(var_name)}(#{TkComm::_get_eval_string(index_name)})", TkComm::_get_eval_string(value))
end
_set_variable(var_name, value, flag) click to toggle source
# File lib/remote-tk.rb, line 383
def _set_variable(var_name, value, flag)
  # ignore flag
  _appsend(false, 'set', TkComm::_get_eval_string(var_name), TkComm::_get_eval_string(value))
end
_set_variable2(var_name, index_name, value, flag) click to toggle source
# File lib/remote-tk.rb, line 387
def _set_variable2(var_name, index_name, value, flag)
  # ignore flag
  _appsend(false, 'set', "#{TkComm::_get_eval_string(var_name)}(#{TkComm::_get_eval_string(index_name)})", TkComm::_get_eval_string(value))
end
_split_tklist(str) click to toggle source
# File lib/remote-tk.rb, line 422
def _split_tklist(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._split_tklist(str)
end
_thread_tkwait(mode, target) click to toggle source
# File lib/remote-tk.rb, line 365
def _thread_tkwait(mode, target)
  _appsend(false, 'thread_tkwait', mode, target)
end
_thread_vwait(var_name) click to toggle source
# File lib/remote-tk.rb, line 361
def _thread_vwait(var_name)
  _appsend(false, 'thread_vwait', var_name)
end
_toUTF8(str, encoding=nil) click to toggle source
# File lib/remote-tk.rb, line 351
def _toUTF8(str, encoding=nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._toUTF8(str, encoding)
end
_unset_global_var(var_name) click to toggle source
# File lib/remote-tk.rb, line 415
def _unset_global_var(var_name)
  _appsend(false, 'unset', TkComm::_get_eval_string(var_name))
end
_unset_global_var2(var_name, index_name) click to toggle source
# File lib/remote-tk.rb, line 418
def _unset_global_var2(var_name, index_name)
  _appsend(false, 'unset', "#{var_name}(#{index_name})")
end
_unset_variable(var_name, flag) click to toggle source
# File lib/remote-tk.rb, line 392
def _unset_variable(var_name, flag)
  # ignore flag
  _appsend(false, 'unset', TkComm::_get_eval_string(var_name))
end
_unset_variable2(var_name, index_name, flag) click to toggle source
# File lib/remote-tk.rb, line 396
def _unset_variable2(var_name, index_name, flag)
  # ignore flag
  _appsend(false, 'unset', "#{var_name}(#{index_name})")
end
allow_ruby_exit=(mode) click to toggle source
# File lib/remote-tk.rb, line 273
def allow_ruby_exit= (mode)
  fail RuntimeError, 'cannot change mode of the remote interpreter'
end
allow_ruby_exit?() click to toggle source
# File lib/remote-tk.rb, line 269
def allow_ruby_exit?
  false
end
appsend(async, *args) click to toggle source
# File lib/remote-tk.rb, line 220
def appsend(async, *args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  if async != true && async != false && async != nil
    args.unshift(async)
    async = false
  end
  if @displayof
    Tk.appsend_displayof(@remote, @displayof, async, *args)
  else
    Tk.appsend(@remote, async, *args)
  end
end
create_slave(name, safe=false) click to toggle source
# File lib/remote-tk.rb, line 248
def create_slave(name, safe=false)
  if safe
    safe_opt = ''
  else
    safe_opt = '-safe'
  end
  _appsend(false, false, "interp create #{safe_opt} -- #{name}")
end
delete() click to toggle source
# File lib/remote-tk.rb, line 277
def delete
  _appsend(false, true, 'exit')
end
deleted?() click to toggle source
# File lib/remote-tk.rb, line 281
def deleted?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  if @displayof
    lst = @interp._invoke_without_enc('winfo', 'interps',
                                      '-displayof', @displayof)
  else
    lst = @interp._invoke_without_enc('winfo', 'interps')
  end
  # unless @interp._split_tklist(lst).index(@remote)
  unless @interp._split_tklist(lst).index(_toUTF8(@remote))
    true
  else
    false
  end
end
do_one_event(flag = nil) click to toggle source
# File lib/remote-tk.rb, line 447
def do_one_event(flag = nil)
  fail RuntimeError, 'not support "do_one_event" on the remote interpreter'
end
get_eventloop_tick() click to toggle source
# File lib/remote-tk.rb, line 459
def get_eventloop_tick
  fail RuntimeError, 'not support "get_eventloop_tick" on the remote interpreter'
end
get_eventloop_weight() click to toggle source
# File lib/remote-tk.rb, line 471
def get_eventloop_weight
  fail RuntimeError, 'not support "get_eventloop_weight" on the remote interpreter'
end
get_no_event_wait() click to toggle source
# File lib/remote-tk.rb, line 465
def get_no_event_wait
  fail RuntimeError, 'not support "get_no_event_wait" on the remote interpreter'
end
has_mainwindow?() click to toggle source
# File lib/remote-tk.rb, line 298
def has_mainwindow?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  begin
    inf = @interp._invoke_without_enc('info', 'command', '.')
  rescue Exception
    return nil
  end
  if !inf.kind_of?(String) || inf != '.'
    false
  else
    true
  end
end
invalid_namespace?() click to toggle source
# File lib/remote-tk.rb, line 313
def invalid_namespace?
  false
end
is_rubytk?() click to toggle source
# File lib/remote-tk.rb, line 214
def is_rubytk?
  return false if _appsend(false, false, 'info', 'command', 'ruby') == ""
  [ _appsend(false, false, 'ruby', 'RUBY_VERSION'),
    _appsend(false, false, 'set', 'tk_patchLevel') ]
end
mainloop() click to toggle source
# File lib/remote-tk.rb, line 441
def mainloop
  fail RuntimeError, 'not support "mainloop" on the remote interpreter'
end
mainloop_abort_on_exception() click to toggle source
# File lib/remote-tk.rb, line 450
def mainloop_abort_on_exception
  fail RuntimeError, 'not support "mainloop_abort_on_exception" on the remote interpreter'
end
mainloop_abort_on_exception=(mode) click to toggle source
# File lib/remote-tk.rb, line 453
def mainloop_abort_on_exception=(mode)
  fail RuntimeError, 'not support "mainloop_abort_on_exception=" on the remote interpreter'
end
mainloop_watchdog() click to toggle source
# File lib/remote-tk.rb, line 444
def mainloop_watchdog
  fail RuntimeError, 'not support "mainloop_watchdog" on the remote interpreter'
end
make_safe() click to toggle source
# File lib/remote-tk.rb, line 257
def make_safe
  fail RuntimeError, 'cannot change safe mode of the remote interpreter'
end
manipulable?() click to toggle source
# File lib/remote-tk.rb, line 124
def manipulable?
  return true if (Thread.current.group == ThreadGroup::Default)
  MultiTkIp.__getip == @interp && ! @interp.safe?
end
rb_appsend(async, *args) click to toggle source
# File lib/remote-tk.rb, line 234
def rb_appsend(async, *args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  if async != true && async != false && async != nil
    args.unshift(async)
    async = false
  end
  if @displayof
    Tk.rb_appsend_displayof(@remote, @displayof, async, *args)
  else
    Tk.rb_appsend(@remote, async, *args)
  end
end
ready?(timeout=5) click to toggle source
# File lib/remote-tk.rb, line 207
def ready?(timeout=5)
  if timeout < 0
    fail ArgumentError, "timeout must be positive number"
  end
  _available_check(timeout)
end
restart() click to toggle source
# File lib/remote-tk.rb, line 317
def restart
  fail RuntimeError, 'cannot restart the remote interpreter'
end
safe?() click to toggle source
# File lib/remote-tk.rb, line 261
def safe?
  _appsend(false, false, 'interp issafe')
end
safe_base?() click to toggle source
# File lib/remote-tk.rb, line 265
def safe_base?
  false
end
set_eventloop_tick(*args) click to toggle source
# File lib/remote-tk.rb, line 456
def set_eventloop_tick(*args)
  fail RuntimeError, 'not support "set_eventloop_tick" on the remote interpreter'
end
set_eventloop_weight(*args) click to toggle source
# File lib/remote-tk.rb, line 468
def set_eventloop_weight(*args)
  fail RuntimeError, 'not support "set_eventloop_weight" on the remote interpreter'
end
set_no_event_wait(*args) click to toggle source
# File lib/remote-tk.rb, line 462
def set_no_event_wait(*args)
  fail RuntimeError, 'not support "set_no_event_wait" on the remote interpreter'
end

Protected Instance Methods

_is_master_of?(tcltkip_obj) click to toggle source
# File lib/remote-tk.rb, line 132
def _is_master_of?(tcltkip_obj)
  tcltkip_obj == @interp
end

Private Instance Methods

_appsend(enc_mode, async, *cmds) click to toggle source
# File lib/remote-tk.rb, line 183
def _appsend(enc_mode, async, *cmds)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  p ['_appsend', [@remote, @displayof], enc_mode, async, cmds] if $DEBUG

  cmds = @interp._merge_tklist(*TkUtil::_conv_args([], enc_mode, *cmds))
  if @displayof
    if async
      @interp.__invoke('send', '-async', '-displayof', @displayof,
                       '--', @remote, *cmds)
    else
      @interp.__invoke('send', '-displayof', @displayof,
                       '--', @remote, *cmds)
    end
  else
    if async
      @interp.__invoke('send', '-async', '--', @remote, *cmds)
    else
      @interp.__invoke('send', '--', @remote, *cmds)
    end
  end
end
_available_check(timeout = 5) click to toggle source
# File lib/remote-tk.rb, line 141
def _available_check(timeout = 5)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  return nil if timeout < 1
  @ret_val.value = ''
  @interp._invoke('send', '-async', @remote,
                  'send', '-async', Tk.appname,
                  "set #{@ret_val.id} ready")
  Tk.update
  if @ret_val != 'ready'
    (1..(timeout*5)).each{
      sleep 0.2
      Tk.update
      break if @ret_val == 'ready'
    }
  end
  @ret_val.value == 'ready'
end
_create_connection() click to toggle source
# File lib/remote-tk.rb, line 161
  def _create_connection
    raise SecurityError, "no permission to manipulate" unless self.manipulable?

    ip_id = '_' + @interp._invoke('send', @remote, <<-'EOS') + '_'
      if {[catch {set _rubytk_control_ip_id_} ret] != 0} {
        set _rubytk_control_ip_id_ 0
      } else {
        set _rubytk_control_ip_id_ [expr $ret + 1]
      }
      return $_rubytk_control_ip_id_
    EOS

    @interp._invoke('send', @remote, <<-EOS)
      proc rb_out#{ip_id} args {
        send #{@appname} rb_out \$args
      }
    EOS

    ip_id
  end