Class: MultiTkIp

Inherits:
Object show all
Defined in:
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/multi-tk.rb,
ext/lib/remote-tk.rb,
ext/lib/remote-tk.rb

Overview

check Ruby 1.9 !!!!!!!

Direct Known Subclasses

RemoteTkIp

Constant Summary collapse

BASE_DIR =
File.dirname(__FILE__)
WITH_RUBY_VM =
Object.const_defined?(:VM) && ::VM.class == Class
WITH_ENCODING =
defined?(::Encoding.default_external)
RUN_EVENTLOOP_ON_MAIN_THREAD =

Ruby 1.9 !!!!!!!!!!!!!!!!!!!!!!!!!!

false
INTERP_THREAD =
@@DEFAULT_MASTER.instance_variable_get('@interp_thread')
INTERP_THREAD_STATUS =
INTERP_MUTEX =
INTERP_ROOT_CHECK =
@@IP_TABLE =
{}.taint
@@INIT_IP_ENV =

table of Procs

[].taint
@@ADD_TK_PROCS =

table of [name, args, body]

[].taint
@@TK_TABLE_LIST =
[].taint
@@TK_CMD_TBL =
Object.new.taint
@@CB_ENTRY_CLASS =
Class.new(TkCallbackEntry){
  def initialize(ip, cmd)
    @ip = ip
    @cmd = cmd
    self.freeze
  end
  attr_reader :ip, :cmd
  def inspect
    cmd.inspect
  end
  def call(*args)
    unless @ip.deleted?
      current = Thread.current
      backup_ip = current[:callback_ip]
      current[:callback_ip] = @ip
      begin
        ret = @ip.cb_eval(@cmd, *args)
        fail ret if ret.kind_of?(Exception)
        ret
      rescue TkCallbackBreak, TkCallbackContinue => e
        fail e
	rescue SecurityError => e
        # in 'exit', 'exit!', and 'abort' : security error --> delete IP
        if e.backtrace[0] =~ /^(.+?):(\d+):in `(exit|exit!|abort)'/
   @ip.delete
        elsif @ip.safe?
   if @ip.respond_to?(:cb_error)
            @ip.cb_error(e)
          else
            nil # ignore
          end
        else
          fail e
        end
      rescue Exception => e
        fail e if e.message =~ /^TkCallback/
         if @ip.safe?
   if @ip.respond_to?(:cb_error)
            @ip.cb_error(e)
          else
            nil # ignore
          end
        else
          fail e
        end
      ensure
        current[:callback_ip] = backup_ip
      end
    end
  end
}.freeze
@@DEFAULT_MASTER =
self.allocate
@@SAFE_OPT_LIST =
[
  'accessPath'.freeze, 
  'statics'.freeze, 
  'nested'.freeze, 
  'deleteHook'.freeze
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master, safeip = true, keys = {}) ⇒ MultiTkIp

Returns a new instance of MultiTkIp.



1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
# File 'ext/lib/multi-tk.rb', line 1253

def initialize(master, safeip=true, keys={})
  if $SAFE >= 4
    fail SecurityError, "cannot create a new interpreter at level #{$SAFE}"
  end

  if safeip == nil && $SAFE >= 2
    fail SecurityError, "cannot create a master-ip at level #{$SAFE}"
  end

  if master.deleted? && safeip == nil
    fail RuntimeError, "cannot create a slave of a deleted interpreter"
  end

  if !master.deleted? && !master.master? && master.safe?
    fail SecurityError, "safe-slave-ip cannot create a new interpreter"
  end

  if safeip == nil && !master.master?
    fail SecurityError, "slave-ip cannot create a master-ip"
  end

  unless keys.kind_of? Hash
    fail ArgumentError, "expecting a Hash object for the 2nd argument"
  end

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

  @tk_windows.taint unless @tk_windows.tainted?
  @tk_table_list.taint unless @tk_table_list.tainted?
  @slave_ip_tbl.taint unless @slave_ip_tbl.tainted?
  @slave_ip_top.taint unless @slave_ip_top.tainted?
  @cb_error_proc.taint unless @cb_error_proc.tainted?
  @evloop_thread.taint unless @evloop_thread.tainted?

  @callback_status = []

  name, safe, safe_opts, tk_opts = _parse_slaveopts(keys)

  safe = 4 if safe && !safe.kind_of?(Fixnum)

  @safe_base = false

  if safeip == nil
    # create master-ip
    unless WITH_RUBY_VM
      @interp = TclTkIp.new(name, _keys2opts(tk_opts))
      @interp.instance_eval{
        @force_default_encoding ||= [false].taint
        @encoding ||= [nil].taint
        def @encoding.to_s; self.join(nil); end
      }

    else ### Ruby 1.9 !!!!!!!!!!!
      @interp_thread = Thread.new{
        Thread.current[:interp] = interp = TclTkIp.new(name, _keys2opts(tk_opts))
        interp.instance_eval{
          @force_default_encoding ||= [false].taint
          @encoding ||= [nil].taint
          def @encoding.to_s; self.join(nil); end
        }

        #sleep
        TclTkLib.mainloop(true)
      }
      until @interp_thread[:interp]
        Thread.pass
      end
      # INTERP_THREAD.run
      @interp = @interp_thread[:interp]
    end

    @ip_name = nil
    if safe
      safe = $SAFE if safe < $SAFE
      @safe_level = [safe]
    else
      @safe_level = [$SAFE]
    end
  else
    # create slave-ip
    if safeip || master.safe?
      @safe_base = true
      @interp, @ip_name = master.__create_safe_slave_obj(safe_opts, 
                                                         name, tk_opts)
      # @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
      @interp_thread = nil unless WITH_RUBY_VM  ### Ruby 1.9 !!!!!!!!!!!
      if safe
        safe = master.safe_level if safe < master.safe_level
        @safe_level = [safe]
      else
        @safe_level = [4]
      end
    else
      @interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
      # @interp_thread = nil if RUBY_VERSION < '1.9.0' ### !!!!!!!!!!!
      @interp_thread = nil unless WITH_RUBY_VM  ### Ruby 1.9 !!!!!!!!!!!
      if safe
        safe = master.safe_level if safe < master.safe_level
        @safe_level = [safe]
      else
        @safe_level = [master.safe_level]
      end
    end
    @set_alias_proc = proc{|name| 
      master._invoke('interp', 'alias', @ip_name, name, '', name)
    }.freeze
  end

  @system = Object.new

  @wait_on_mainloop = [true, 0].taint
  # @wait_on_mainloop = [false, 0].taint

  @threadgroup  = ThreadGroup.new

  @pseudo_toplevel = [false, nil]

  @cmd_queue = Queue.new

=begin
  @cmd_receiver, @receiver_watchdog = _create_receiver_and_watchdog(@safe_level[0])

  @threadgroup.add @cmd_receiver
  @threadgroup.add @receiver_watchdog

  @threadgroup.enclose
=end
  @@DEFAULT_MASTER.assign_receiver_and_watchdog(self)

  @@IP_TABLE[@threadgroup] = self
  @@TK_TABLE_LIST.size.times{ 
    (tbl = {}).tainted? || tbl.taint
    @tk_table_list << tbl
  }
  _init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)

  class << self
    undef :instance_eval
  end

  # dummy call for initialization
  self.eval_proc{ Tk.tk_call('set', 'tcl_patchLevel') }

  self.freeze  # defend against modification
end

Class Method Details

.__getipObject



1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
# File 'ext/lib/multi-tk.rb', line 1446

def self.__getip
  current = Thread.current
  if TclTkLib.mainloop_thread? != false && current[:callback_ip]
    return current[:callback_ip]
  end
  if current.group == ThreadGroup::Default
    @@DEFAULT_MASTER
  else
    ip = @@IP_TABLE[current.group]
    unless ip
      fail SecurityError, 
        "cannot call Tk methods on #{Thread.current.inspect}"
    end
    ip
  end
end

._conv_listelement(arg) ⇒ Object



2421
2422
2423
# File 'ext/lib/multi-tk.rb', line 2421

def _conv_listelement(arg)
  __getip._conv_listelement(arg)
end

._create_consoleObject



2425
2426
2427
# File 'ext/lib/multi-tk.rb', line 2425

def _create_console
  __getip._create_console
end

._DEFAULT_MASTERObject



19
20
21
22
23
24
25
26
27
# File 'ext/lib/remote-tk.rb', line 19

def self._DEFAULT_MASTER
  # work only once
  if @flag
    @flag = nil
    @@DEFAULT_MASTER
  else
    nil
  end
end

._eval(str) ⇒ Object



2329
2330
2331
# File 'ext/lib/multi-tk.rb', line 2329

def _eval(str)
  __getip._eval(str)
end

._eval_with_enc(str) ⇒ Object



2345
2346
2347
# File 'ext/lib/multi-tk.rb', line 2345

def _eval_with_enc(str)
  __getip._eval_with_enc(str)
end

._eval_without_enc(str) ⇒ Object



2337
2338
2339
# File 'ext/lib/multi-tk.rb', line 2337

def _eval_without_enc(str)
  __getip._eval_without_enc(str)
end

._fromUTF8(str, encoding = nil) ⇒ Object



2357
2358
2359
# File 'ext/lib/multi-tk.rb', line 2357

def _fromUTF8(str, encoding=nil)
  __getip._fromUTF8(str, encoding)
end

._get_global_var(var) ⇒ Object



2392
2393
2394
# File 'ext/lib/multi-tk.rb', line 2392

def _get_global_var(var)
  __getip._get_global_var(var)
end

._get_global_var2(var, idx) ⇒ Object



2395
2396
2397
# File 'ext/lib/multi-tk.rb', line 2395

def _get_global_var2(var, idx)
  __getip._get_global_var2(var, idx)
end

._get_variable(var, flag) ⇒ Object



2373
2374
2375
# File 'ext/lib/multi-tk.rb', line 2373

def _get_variable(var, flag)
  __getip._get_variable(var, flag)
end

._get_variable2(var, idx, flag) ⇒ Object



2376
2377
2378
# File 'ext/lib/multi-tk.rb', line 2376

def _get_variable2(var, idx, flag)
  __getip._get_variable2(var, idx, flag)
end

._invoke(*args) ⇒ Object



2333
2334
2335
# File 'ext/lib/multi-tk.rb', line 2333

def _invoke(*args)
  __getip._invoke(*args)
end

._invoke_with_enc(*args) ⇒ Object



2349
2350
2351
# File 'ext/lib/multi-tk.rb', line 2349

def _invoke_with_enc(*args)
  __getip._invoke_with_enc(*args)
end

._invoke_without_enc(*args) ⇒ Object



2341
2342
2343
# File 'ext/lib/multi-tk.rb', line 2341

def _invoke_without_enc(*args)
  __getip._invoke_without_enc(*args)
end

._ip_id_Object



1438
1439
1440
# File 'ext/lib/multi-tk.rb', line 1438

def self._ip_id_
  __getip._ip_id_
end

._IP_TABLEObject



15
# File 'ext/lib/remote-tk.rb', line 15

def self._IP_TABLE; @@IP_TABLE; end

._make_menu_embeddable(menu_path) ⇒ Object



2411
2412
2413
# File 'ext/lib/multi-tk.rb', line 2411

def _make_menu_embeddable(menu_path)
  __getip._make_menu_embeddable(menu_path)
end

._merge_tklist(*args) ⇒ Object



2418
2419
2420
# File 'ext/lib/multi-tk.rb', line 2418

def _merge_tklist(*args)
  __getip._merge_tklist(*args)
end

._return_valueObject



2369
2370
2371
# File 'ext/lib/multi-tk.rb', line 2369

def _return_value
  __getip._return_value
end

._set_global_var(var, value) ⇒ Object



2398
2399
2400
# File 'ext/lib/multi-tk.rb', line 2398

def _set_global_var(var, value)
  __getip._set_global_var(var, value)
end

._set_global_var2(var, idx, value) ⇒ Object



2401
2402
2403
# File 'ext/lib/multi-tk.rb', line 2401

def _set_global_var2(var, idx, value)
  __getip._set_global_var2(var, idx, value)
end

._set_variable(var, value, flag) ⇒ Object



2379
2380
2381
# File 'ext/lib/multi-tk.rb', line 2379

def _set_variable(var, value, flag)
  __getip._set_variable(var, value, flag)
end

._set_variable2(var, idx, value, flag) ⇒ Object



2382
2383
2384
# File 'ext/lib/multi-tk.rb', line 2382

def _set_variable2(var, idx, value, flag)
  __getip._set_variable2(var, idx, value, flag)
end

._split_tklist(str) ⇒ Object



2415
2416
2417
# File 'ext/lib/multi-tk.rb', line 2415

def _split_tklist(str)
  __getip._split_tklist(str)
end

._thread_tkwait(mode, target) ⇒ Object



2365
2366
2367
# File 'ext/lib/multi-tk.rb', line 2365

def _thread_tkwait(mode, target)
  __getip._thread_tkwait(mode, target)
end

._thread_vwait(var) ⇒ Object



2361
2362
2363
# File 'ext/lib/multi-tk.rb', line 2361

def _thread_vwait(var)
  __getip._thread_vwait(var)
end

._TK_TABLE_LISTObject



16
# File 'ext/lib/remote-tk.rb', line 16

def self._TK_TABLE_LIST; @@TK_TABLE_LIST; end

._toUTF8(str, encoding = nil) ⇒ Object



2353
2354
2355
# File 'ext/lib/multi-tk.rb', line 2353

def _toUTF8(str, encoding=nil)
  __getip._toUTF8(str, encoding)
end

._unset_global_var(var) ⇒ Object



2404
2405
2406
# File 'ext/lib/multi-tk.rb', line 2404

def _unset_global_var(var)
  __getip._unset_global_var(var)
end

._unset_global_var2(var, idx) ⇒ Object



2407
2408
2409
# File 'ext/lib/multi-tk.rb', line 2407

def _unset_global_var2(var, idx)
  __getip._unset_global_var2(var, idx)
end

._unset_variable(var, flag) ⇒ Object



2385
2386
2387
# File 'ext/lib/multi-tk.rb', line 2385

def _unset_variable(var, flag)
  __getip._unset_variable(var, flag)
end

._unset_variable2(var, idx, flag) ⇒ Object



2388
2389
2390
# File 'ext/lib/multi-tk.rb', line 2388

def _unset_variable2(var, idx, flag)
  __getip._unset_variable2(var, idx, flag)
end

.abort(msg = nil) ⇒ Object



2306
2307
2308
# File 'ext/lib/multi-tk.rb', line 2306

def abort(msg = nil)
  __getip.abort(msg)
end

.add_tk_procs(name, args = nil, body = nil) ⇒ Object



1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
# File 'ext/lib/multi-tk.rb', line 1787

def self.add_tk_procs(name, args=nil, body=nil)
  if name.kind_of?(Array) # => an array of [name, args, body]
    name.each{|param| self.add_tk_procs(*param)}
  else
    name = name.to_s
    @@ADD_TK_PROCS << [name, args, body]
    @@IP_TABLE.each{|tg, ip| 
      ip._add_tk_procs(name, args, body)
    }
  end
end

.alias_delete(slave, cmd_name) ⇒ Object



2939
2940
2941
2942
# File 'ext/lib/multi-tk.rb', line 2939

def self.alias_delete(slave, cmd_name)
  __getip.alias_delete(slave, cmd_name)
  self
end

.alias_info(slave, cmd_name) ⇒ Object



2930
2931
2932
# File 'ext/lib/multi-tk.rb', line 2930

def self.alias_info(slave, cmd_name)
  __getip.alias_info(slave, cmd_name)
end

.alias_target(aliascmd, slave = '') ⇒ Object



3170
3171
3172
# File 'ext/lib/multi-tk.rb', line 3170

def self.alias_target(aliascmd, slave = '')
  __getip.alias_target(aliascmd, slave)
end

.aliases(slave = '') ⇒ Object



2959
2960
2961
# File 'ext/lib/multi-tk.rb', line 2959

def self.aliases(slave = '')
  __getip.aliases(slave)
end

.alive?Boolean

Returns:

  • (Boolean)


1599
1600
1601
# File 'ext/lib/multi-tk.rb', line 1599

def self.alive?
  __getip.alive?
end

.allow_ruby_exit=(mode) ⇒ Object



2286
2287
2288
# File 'ext/lib/multi-tk.rb', line 2286

def allow_ruby_exit= (mode)
  __getip.allow_ruby_exit = mode
end

.allow_ruby_exit?Boolean

Returns:

  • (Boolean)


2282
2283
2284
# File 'ext/lib/multi-tk.rb', line 2282

def allow_ruby_exit?
  __getip.allow_ruby_exit?
end

.bg_eval(*args, &blk) ⇒ Object Also known as: background_eval



2207
2208
2209
2210
# File 'ext/lib/multi-tk.rb', line 2207

def bg_eval(*args, &blk)
  # class ==> interp object
  __getip.bg_eval(*args, &blk)
end

.bg_eval_proc(*args, &blk) ⇒ Object Also known as: background_eval_proc, thread_eval_proc, bg_call, background_call



2180
2181
2182
2183
# File 'ext/lib/multi-tk.rb', line 2180

def bg_eval_proc(*args, &blk)
  # class ==> interp object
  __getip.bg_eval_proc(*args, &blk)
end

.bg_eval_string(cmd, *eval_args) ⇒ Object Also known as: background_eval_string, bg_eval_str, background_eval_str



2195
2196
2197
2198
# File 'ext/lib/multi-tk.rb', line 2195

def bg_eval_string(cmd, *eval_args)
  # class ==> interp object
  __getip.bg_eval_string(cmd, *eval_args)
end

.bgerror(slave = '') ⇒ Object



3112
3113
3114
# File 'ext/lib/multi-tk.rb', line 3112

def self.bgerror(cmd = Proc.new, slave = nil, &b)
  __getip.bgerror(cmd, slave, &b)
end

.cb_entry_classObject



1819
1820
1821
# File 'ext/lib/multi-tk.rb', line 1819

def self.cb_entry_class
  @@CB_ENTRY_CLASS
end

.create_tableObject



1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
# File 'ext/lib/multi-tk.rb', line 1730

def self.create_table
  if __getip.slave? 
    begin
      raise SecurityError, "slave-IP has no permission creating a new table"
    rescue SecurityError => e
      #p e.backtrace
      # Is called on a Ruby/Tk library?
      caller_info = e.backtrace[1]
      if caller_info =~ %r{^#{MultiTkIp::BASE_DIR}/(tk|tkextlib)/[^:]+\.rb:}
        # Probably, caller is a Ruby/Tk library  -->  allow creating
      else
        raise e
      end
    end
  end

  id = @@TK_TABLE_LIST.size
  obj = Object.new
  @@TK_TABLE_LIST << obj
  obj.instance_variable_set(:@id, id)
  obj.instance_variable_set(:@mutex, Mutex.new)
  obj.instance_eval{
    def self.mutex
      @mutex
    end
    def self.method_missing(m, *args)
      MultiTkIp.tk_object_table(@id).__send__(m, *args)
    end
  }
  obj.freeze
  @@IP_TABLE.each{|tg, ip| ip._add_new_tables }
  return obj
end

.def_alias(slave, new_cmd, org_cmd, *args) ⇒ Object



2950
2951
2952
2953
# File 'ext/lib/multi-tk.rb', line 2950

def self.def_alias(slave, new_cmd, org_cmd, *args)
  ret = __getip.def_alias(slave, new_cmd, org_cmd, *args)
  (ret == new_cmd)? self: nil
end

.default_encodingObject



3367
3368
3369
# File 'ext/lib/multi-tk.rb', line 3367

def encoding_name
  __getip.encoding_name
end

.default_encoding=(enc) ⇒ Object



3351
3352
3353
# File 'ext/lib/multi-tk.rb', line 3351

def default_encoding=(enc)
  __getip.default_encoding=(enc)
end

.default_master?Boolean

Returns:

  • (Boolean)


2218
2219
2220
# File 'ext/lib/multi-tk.rb', line 2218

def self.default_master?
  __getip == @@DEFAULT_MASTER
end

.deleteObject



2290
2291
2292
# File 'ext/lib/multi-tk.rb', line 2290

def delete
  __getip.delete
end

.delete_cmd(slave, cmd) ⇒ Object



2989
2990
2991
2992
# File 'ext/lib/multi-tk.rb', line 2989

def self.delete_cmd(slave, cmd)
  __getip.delete_cmd(slave, cmd)
  self
end

.delete_slaves(*args) ⇒ Object



2969
2970
2971
2972
# File 'ext/lib/multi-tk.rb', line 2969

def self.delete_slaves(*args)
  __getip.delete_slaves(*args)
  self
end

.deleted?Boolean

Returns:

  • (Boolean)


2294
2295
2296
# File 'ext/lib/multi-tk.rb', line 2294

def deleted?
  __getip.deleted?
end

.do_one_event(flag = TclTkLib::EventFlag::ALL) ⇒ Object



2229
2230
2231
# File 'ext/lib/multi-tk.rb', line 2229

def do_one_event(flag = TclTkLib::EventFlag::ALL)
  __getip.do_one_event(flag)
end

.encodingObject



3366
3367
3368
# File 'ext/lib/multi-tk.rb', line 3366

def encoding_name
  __getip.encoding_name
end

.encoding=(enc) ⇒ Object



3355
3356
3357
# File 'ext/lib/multi-tk.rb', line 3355

def encoding=(enc)
  __getip.encoding=(enc)
end

.encoding_convert_fromObject



3372
3373
3374
# File 'ext/lib/multi-tk.rb', line 3372

def encoding_convertfrom(str, enc=None)
  __getip.encoding_convertfrom(str, enc)
end

.encoding_convert_toObject



3377
3378
3379
# File 'ext/lib/multi-tk.rb', line 3377

def encoding_convertto(str, enc=None)
  __getip.encoding_convertto(str, enc)
end

.encoding_convertfrom(str, enc = None) ⇒ Object



3369
3370
3371
# File 'ext/lib/multi-tk.rb', line 3369

def encoding_convertfrom(str, enc=None)
  __getip.encoding_convertfrom(str, enc)
end

.encoding_convertto(str, enc = None) ⇒ Object



3374
3375
3376
# File 'ext/lib/multi-tk.rb', line 3374

def encoding_convertto(str, enc=None)
  __getip.encoding_convertto(str, enc)
end

.encoding_nameObject



3359
3360
3361
# File 'ext/lib/multi-tk.rb', line 3359

def encoding_name
  __getip.encoding_name
end

.encoding_objObject



3363
3364
3365
# File 'ext/lib/multi-tk.rb', line 3363

def encoding_obj
  __getip.encoding_obj
end

.encoding_tableObject



3339
3340
3341
# File 'ext/lib/multi-tk.rb', line 3339

def encoding_table
  __getip.encoding_table
end

.eval(*args, &blk) ⇒ Object



2203
2204
2205
2206
# File 'ext/lib/multi-tk.rb', line 2203

def eval(*args, &blk)
  # class ==> interp object
  __getip.eval(*args, &blk)
end

.eval_proc(*args, &blk) ⇒ Object Also known as: call

class method



2174
2175
2176
2177
# File 'ext/lib/multi-tk.rb', line 2174

def eval_proc(*args, &blk)
  # class ==> interp object
  __getip.eval_proc(*args, &blk)
end

.eval_string(cmd, *eval_args) ⇒ Object Also known as: eval_str



2189
2190
2191
2192
# File 'ext/lib/multi-tk.rb', line 2189

def eval_string(cmd, *eval_args)
  # class ==> interp object
  __getip.eval_string(cmd, *eval_args)
end

.exist?(slave = '') ⇒ Boolean

Returns:

  • (Boolean)


2979
2980
2981
# File 'ext/lib/multi-tk.rb', line 2979

def self.exist?(slave = '')
  __getip.exist?(slave)
end

.exit(st = true) ⇒ Object



2310
2311
2312
# File 'ext/lib/multi-tk.rb', line 2310

def exit(st = true)
  __getip.exit(st)
end

.exit!(st = false) ⇒ Object



2314
2315
2316
# File 'ext/lib/multi-tk.rb', line 2314

def exit!(st = false)
  __getip.exit!(st)
end

.expose_cmd(slave, cmd, aliasname = nil) ⇒ Object



3003
3004
3005
3006
# File 'ext/lib/multi-tk.rb', line 3003

def self.expose_cmd(slave, cmd, aliasname = nil)
  __getip.expose_cmd(slave, cmd, aliasname)
  self
end

.force_default_encoding=(mode) ⇒ Object



3343
3344
3345
# File 'ext/lib/multi-tk.rb', line 3343

def force_default_encoding=(mode)
  __getip.force_default_encoding=(mode)
end

.force_default_encoding?Boolean

Returns:

  • (Boolean)


3347
3348
3349
# File 'ext/lib/multi-tk.rb', line 3347

def force_default_encoding?
  __getip.force_default_encoding?
end

.get_cb_entry(cmd) ⇒ Object



1822
1823
1824
# File 'ext/lib/multi-tk.rb', line 1822

def self.get_cb_entry(cmd)
  @@CB_ENTRY_CLASS.new(__getip, cmd).freeze
end

.get_eventloop_tickObject



2243
2244
2245
# File 'ext/lib/multi-tk.rb', line 2243

def get_eventloop_tick
  __getip.get_eventloop_tick
end

.get_eventloop_weightObject



2255
2256
2257
# File 'ext/lib/multi-tk.rb', line 2255

def get_eventloop_weight
  __getip.get_eventloop_weight
end

.get_limit(limit_type, slave = '', slot = nil) ⇒ Object



3153
3154
3155
# File 'ext/lib/multi-tk.rb', line 3153

def self.get_limit(limit_type, slave = '', slot = nil)
  __getip.get_limit(limit_type, slave, slot)
end

.get_no_event_waitObject



2249
2250
2251
# File 'ext/lib/multi-tk.rb', line 2249

def get_no_event_wait
  __getip.get_no_event_wait
end

.has_mainwindow?Boolean

Returns:

  • (Boolean)


2298
2299
2300
# File 'ext/lib/multi-tk.rb', line 2298

def has_mainwindow?
  __getip.has_mainwindow?
end

.hidden_cmds(slave = '') ⇒ Object



3026
3027
3028
# File 'ext/lib/multi-tk.rb', line 3026

def self.hidden_cmds(slave = '')
  __getip.hidden_cmds(slave)
end

.hide_cmd(slave, cmd, aliasname = nil) ⇒ Object



3017
3018
3019
3020
# File 'ext/lib/multi-tk.rb', line 3017

def self.hide_cmd(slave, cmd, aliasname = nil)
  __getip.hide_cmd(slave, cmd, aliasname)
  self
end

.inherited(subclass) ⇒ Object



970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
# File 'ext/lib/multi-tk.rb', line 970

def self.inherited(subclass)
  # trust if on ThreadGroup::Default or @@DEFAULT_MASTER's ThreadGroup
  if @@IP_TABLE[Thread.current.group] == @@DEFAULT_MASTER
    begin
      class << subclass
        self.methods.each{|m|
          name = m.to_s
          begin
            unless name == '__id__' || name == '__send__' || name == 'freeze'
              undef_method(m)
            end
          rescue Exception
            # ignore all exceptions
          end
        }
      end
    ensure
      subclass.freeze
      fail SecurityError, 
        "cannot create subclass of MultiTkIp on a untrusted ThreadGroup"
    end
  end
end

.init_ip_env(script = Proc.new) ⇒ Object



1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
# File 'ext/lib/multi-tk.rb', line 1764

def self.init_ip_env(script = Proc.new)
  @@INIT_IP_ENV << script
  if __getip.slave?
    begin
      raise SecurityError, "slave-IP has no permission initializing IP env"
    rescue SecurityError => e
      #p e.backtrace
      # Is called on a Ruby/Tk library?
      caller_info = e.backtrace[1]
      if caller_info =~ %r{^#{MultiTkIp::BASE_DIR}/(tk|tkextlib)/[^:]+\.rb:}
        # Probably, caller is a Ruby/Tk library  -->  allow creating
      else
        raise e
      end
    end
  end

  # @@IP_TABLE.each{|tg, ip| 
  #   ip._init_ip_env(script)
  # }
  @@DEFAULT_MASTER.__init_ip_env__(@@IP_TABLE, script)
end

.init_ip_internalObject



1811
1812
1813
# File 'ext/lib/multi-tk.rb', line 1811

def self.init_ip_internal
  __getip._init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)
end

.invalid_namespace?Boolean

Returns:

  • (Boolean)


2302
2303
2304
# File 'ext/lib/multi-tk.rb', line 2302

def invalid_namespace?
  __getip.invalid_namespace?
end

.invoke_hidden(slave, cmd, *args) ⇒ Object



3046
3047
3048
# File 'ext/lib/multi-tk.rb', line 3046

def self.invoke_hidden(slave, cmd, *args)
  __getip.invoke_hidden(slave, cmd, *args)
end

.invoke_hidden_on_global(slave, cmd, *args) ⇒ Object



3067
3068
3069
# File 'ext/lib/multi-tk.rb', line 3067

def self.invoke_hidden_on_global(slave, cmd, *args)
  __getip.invoke_hidden_on_global(slave, cmd, *args)
end

.invoke_hidden_on_namespace(slave, ns, cmd, *args) ⇒ Object



3085
3086
3087
# File 'ext/lib/multi-tk.rb', line 3085

def self.invoke_hidden_on_namespace(slave, ns, cmd, *args)
  __getip.invoke_hidden_on_namespace(slave, ns, cmd, *args)
end

.ip_nameObject



1612
1613
1614
# File 'ext/lib/multi-tk.rb', line 1612

def self.ip_name
  __getip.ip_name
end

.mainloop(check_root = true) ⇒ Object



2223
2224
2225
# File 'ext/lib/multi-tk.rb', line 2223

def mainloop(check_root = true)
  __getip.mainloop(check_root)
end

.mainloop_abort_on_exceptionObject



2232
2233
2234
2235
# File 'ext/lib/multi-tk.rb', line 2232

def mainloop_abort_on_exception
  # __getip.mainloop_abort_on_exception
  TclTkLib.mainloop_abort_on_exception
end

.mainloop_abort_on_exception=(mode) ⇒ Object



2236
2237
2238
2239
# File 'ext/lib/multi-tk.rb', line 2236

def mainloop_abort_on_exception=(mode)
  # __getip.mainloop_abort_on_exception=(mode)
  TclTkLib.mainloop_abort_on_exception=(mode)
end

.mainloop_watchdog(check_root = true) ⇒ Object



2226
2227
2228
# File 'ext/lib/multi-tk.rb', line 2226

def mainloop_watchdog(check_root = true)
  __getip.mainloop_watchdog(check_root)
end

.make_safeObject



2266
2267
2268
# File 'ext/lib/multi-tk.rb', line 2266

def make_safe
  __getip.make_safe
end

.manipulable?Boolean

Returns:

  • (Boolean)


1643
1644
1645
# File 'ext/lib/multi-tk.rb', line 1643

def self.manipulable?
  true
end

.mark_trusted(slave = '') ⇒ Object



3094
3095
3096
3097
# File 'ext/lib/multi-tk.rb', line 3094

def self.mark_trusted(slave = '')
  __getip.mark_trusted(slave)
  self
end

.master?Boolean

Returns:

  • (Boolean)


1577
1578
1579
# File 'ext/lib/multi-tk.rb', line 1577

def self.master?
  __getip.master?
end

.method_missing(id, *args) ⇒ Object



2262
2263
2264
# File 'ext/lib/multi-tk.rb', line 2262

def method_missing(id, *args)
  __getip.__send__(id, *args)
end

.new_master(safe = nil, keys = {}) ⇒ Object Also known as: new



1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
# File 'ext/lib/multi-tk.rb', line 1470

def new_master(safe=nil, keys={})
  if MultiTkIp::WITH_RUBY_VM
    #### TODO !!!!!!
    fail RuntimeError, 
         'sorry, still not support multiple master-interpreters on Ruby VM'
  end

  if safe.kind_of?(Hash)
    keys = safe
  elsif safe.kind_of?(Integer)
    raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
    if !keys.key?(:safe) && !keys.key?('safe')
      keys[:safe] = safe
    end
  elsif safe == nil
    # do nothing
  else
    raise ArgumentError, "unexpected argument(s)"
  end

  ip = __new(__getip, nil, keys)
  #ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call) if block_given?
   if block_given?
     Thread.new{ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call)}
   end
  ip
end

.new_safe_slave(safe = 4, keys = {}) ⇒ Object Also known as: new_safeTk



1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
# File 'ext/lib/multi-tk.rb', line 1523

def new_safe_slave(safe=4, keys={})
  if safe.kind_of?(Hash)
    keys = safe
  elsif safe.kind_of?(Integer)
    raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
    if !keys.key?(:safe) && !keys.key?('safe')
      keys[:safe] = safe
    end
  else
    raise ArgumentError, "unexpected argument(s)"
  end

  ip = __new(__getip, true, keys)
  # ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call) if block_given?
  if block_given?
    Thread.new{ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call)}
  end
  ip
end

.new_slave(safe = nil, keys = {}) ⇒ Object Also known as: new_trusted_slave



1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
# File 'ext/lib/multi-tk.rb', line 1500

def new_slave(safe=nil, keys={})
  if safe.kind_of?(Hash)
    keys = safe
  elsif safe.kind_of?(Integer)
    raise ArgumentError, "unexpected argument(s)" unless keys.kind_of?(Hash)
    if !keys.key?(:safe) && !keys.key?('safe')
      keys[:safe] = safe
    end
  elsif safe == nil
    # do nothing
  else
    raise ArgumentError, "unexpected argument(s)"
  end

  ip = __new(__getip, false, keys)
  # ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call) if block_given?
  if block_given?
    Thread.new{ip.eval_proc(proc{$SAFE=ip.safe_level; Proc.new}.call)}
  end
  ip
end

.pathObject



1606
1607
1608
# File 'ext/lib/multi-tk.rb', line 1606

def self.path
  __getip.path
end

.recursion_limit(slave = '', limit = None) ⇒ Object



3162
3163
3164
# File 'ext/lib/multi-tk.rb', line 3162

def self.recursion_limit(slave = '', limit = None)
  __getip.recursion_limit(slave)
end

.remove_tk_procs(*names) ⇒ Object



1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
# File 'ext/lib/multi-tk.rb', line 1799

def self.remove_tk_procs(*names)
  names.each{|name|
    name = name.to_s
    @@ADD_TK_PROCS.delete_if{|elem| 
      elem.kind_of?(Array) && elem[0].to_s == name
    }
  }
  @@IP_TABLE.each{|tg, ip| 
    ip._remove_tk_procs(*names)
  }
end

.restart(app_name = nil, keys = {}) ⇒ Object



2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
# File 'ext/lib/multi-tk.rb', line 2318

def restart(app_name = nil, keys = {})
  init_ip_internal

  __getip._invoke('set', 'argv0', app_name) if app_name
  if keys.kind_of?(Hash)
    __getip._invoke('set', 'argv', _keys2opts(keys))
  end

  __getip.restart
end

.safe?Boolean

Returns:

  • (Boolean)


2270
2271
2272
# File 'ext/lib/multi-tk.rb', line 2270

def safe?
  __getip.safe?
end

.safe_base?Boolean

Returns:

  • (Boolean)


2274
2275
2276
2277
2278
2279
2280
# File 'ext/lib/multi-tk.rb', line 2274

def safe_base?
  begin
    __getip.safe_base?
  rescue
    false
  end
end

.safe_levelObject



369
370
371
# File 'ext/lib/multi-tk.rb', line 369

def self.safe_level
  __getip.safe_level
end

.safe_level=(safe) ⇒ Object



363
364
365
# File 'ext/lib/multi-tk.rb', line 363

def self.safe_level=(safe)
  self.set_safe_level(safe)
end

.set_eventloop_tick(tick) ⇒ Object



2240
2241
2242
# File 'ext/lib/multi-tk.rb', line 2240

def set_eventloop_tick(tick)
  __getip.set_eventloop_tick(tick)
end

.set_eventloop_weight(loop_max, no_event_tick) ⇒ Object



2252
2253
2254
# File 'ext/lib/multi-tk.rb', line 2252

def set_eventloop_weight(loop_max, no_event_tick)
  __getip.set_eventloop_weight(loop_max, no_event_tick)
end

.set_limit(limit_type, slave = '', opts = {}) ⇒ Object



3128
3129
3130
# File 'ext/lib/multi-tk.rb', line 3128

def self.set_limit(limit_type, slave = '', opts = {})
  __getip.set_limit(limit_type, slave, opts)
end

.set_no_event_wait(tick) ⇒ Object



2246
2247
2248
# File 'ext/lib/multi-tk.rb', line 2246

def set_no_event_wait(tick)
  __getip.set_no_event_wait(tick)
end

.set_safe_level(safe) ⇒ Object



360
361
362
# File 'ext/lib/multi-tk.rb', line 360

def self.set_safe_level(safe)
  __getip.set_safe_level(safe)
end

.share_stderr(dist, src = '') ⇒ Object



3199
3200
3201
3202
# File 'ext/lib/multi-tk.rb', line 3199

def self.share_stderr(dist, src = '')
  __getip.share_stderr(dist, src)
  self
end

.share_stdin(dist, src = '') ⇒ Object



3179
3180
3181
3182
# File 'ext/lib/multi-tk.rb', line 3179

def self.share_stdin(dist, src = '')
  __getip.share_stdin(dist, src)
  self
end

.share_stdio(dist, src = '') ⇒ Object



3241
3242
3243
3244
# File 'ext/lib/multi-tk.rb', line 3241

def self.share_stdio(dist, src = '')
  __getip.share_stdio(dist, src)
  self
end

.share_stdout(dist, src = '') ⇒ Object



3189
3190
3191
3192
# File 'ext/lib/multi-tk.rb', line 3189

def self.share_stdout(dist, src = '')
  __getip.share_stdout(dist, src)
  self
end

.slave?Boolean

Returns:

  • (Boolean)


1584
1585
1586
# File 'ext/lib/multi-tk.rb', line 1584

def self.slave?
  not self.master?
end

.slaves(all = false) ⇒ Object



1634
1635
1636
# File 'ext/lib/multi-tk.rb', line 1634

def self.slaves(all = false)
  __getip.slaves(all)
end

.tk_cmd_tblObject



1721
1722
1723
# File 'ext/lib/multi-tk.rb', line 1721

def self.tk_cmd_tbl
  @@TK_CMD_TBL
end

.tk_object_table(id) ⇒ Object



1727
1728
1729
# File 'ext/lib/multi-tk.rb', line 1727

def self.tk_object_table(id)
  __getip._tk_table_list[id]
end

.tk_windowsObject



1724
1725
1726
# File 'ext/lib/multi-tk.rb', line 1724

def self.tk_windows
  __getip._tk_windows
end

.to_evalObject



1618
1619
1620
# File 'ext/lib/multi-tk.rb', line 1618

def self.to_eval
  __getip.to_eval
end

.transfer_stderr(dist, src = '') ⇒ Object



3229
3230
3231
3232
# File 'ext/lib/multi-tk.rb', line 3229

def self.transfer_stderr(dist, src = '')
  __getip.transfer_stderr(dist, src)
  self
end

.transfer_stdin(dist, src = '') ⇒ Object



3209
3210
3211
3212
# File 'ext/lib/multi-tk.rb', line 3209

def self.transfer_stdin(dist, src = '')
  __getip.transfer_stdin(dist, src)
  self
end

.transfer_stdio(dist, src = '') ⇒ Object



3253
3254
3255
3256
# File 'ext/lib/multi-tk.rb', line 3253

def self.transfer_stdio(dist, src = '')
  __getip.transfer_stdio(dist, src)
  self
end

.transfer_stdout(dist, src = '') ⇒ Object



3219
3220
3221
3222
# File 'ext/lib/multi-tk.rb', line 3219

def self.transfer_stdout(dist, src = '')
  __getip.transfer_stdout(dist, src)
  self
end

Instance Method Details

#__create_safe_slave_obj(safe_opts, app_name, tk_opts) ⇒ Object

Raises:

  • (SecurityError)


1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
# File 'ext/lib/multi-tk.rb', line 1177

def __create_safe_slave_obj(safe_opts, app_name, tk_opts)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  # safe interpreter
  ip_name = _create_slave_ip_name
  slave_ip = @interp.create_slave(ip_name, true)
  slave_ip.instance_eval{
    @force_default_encoding ||= [false].taint
    @encoding ||= [nil].taint
    def @encoding.to_s; self.join(nil); end
  }
  @slave_ip_tbl[ip_name] = slave_ip
  def slave_ip.safe_base?
    true
  end

  @interp._eval("::safe::interpInit #{ip_name}")

  slave_ip._invoke('set', 'argv0', app_name) if app_name.kind_of?(String)

  if tk_opts
    tk_opts = __check_safetk_optkeys(tk_opts)
    if tk_opts.key?('use')
      @slave_ip_top[ip_name] = ''
    else
      tk_opts, top_path = __create_safetk_frame(slave_ip, ip_name, app_name, 
                                                tk_opts)
      @slave_ip_top[ip_name] = top_path
    end
    @interp._eval("::safe::loadTk #{ip_name} #{_keys2opts(tk_opts)}")
  else
    @slave_ip_top[ip_name] = nil
  end

  if safe_opts.key?('deleteHook') || safe_opts.key?(:deleteHook)
    @interp._eval("::safe::interpConfigure #{ip_name} " + 
                  _keys2opts(safe_opts))
  else
    @interp._eval("::safe::interpConfigure #{ip_name} " + 
                  _keys2opts(safe_opts) + '-deleteHook {' + 
                  TkComm._get_eval_string(proc{|slave|
                                            self._default_delete_hook(slave)
                                          }) + '}')
  end

  [slave_ip, ip_name]
end

#__create_trusted_slave_obj(name, keys) ⇒ Object

Raises:

  • (SecurityError)


1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
# File 'ext/lib/multi-tk.rb', line 1225

def __create_trusted_slave_obj(name, keys)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  ip_name = _create_slave_ip_name
  slave_ip = @interp.create_slave(ip_name, false)
  slave_ip.instance_eval{
    @force_default_encoding ||= [false].taint
    @encoding ||= [nil].taint
    def @encoding.to_s; self.join(nil); end
  }
  slave_ip._invoke('set', 'argv0', name) if name.kind_of?(String)
  slave_ip._invoke('set', 'argv', _keys2opts(keys))
  @interp._invoke('load', '', 'Tk', ip_name)
  @slave_ip_tbl[ip_name] = slave_ip
  [slave_ip, ip_name]
end

#__eval(str) ⇒ Object

Raises:

  • (SecurityError)


2746
2747
2748
2749
# File 'ext/lib/multi-tk.rb', line 2746

def __eval(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.__eval(str)
end

#__invoke(*args) ⇒ Object

Raises:

  • (SecurityError)


2751
2752
2753
2754
# File 'ext/lib/multi-tk.rb', line 2751

def __invoke(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.__invoke(*args)
end

#__pseudo_toplevelObject

instance method



1899
1900
1901
1902
1903
# File 'ext/lib/multi-tk.rb', line 1899

def __pseudo_toplevel
  ip = MultiTkIp.__getip
  (ip == @@DEFAULT_MASTER || ip == self) &&
    self.__pseudo_toplevel_evaluable? && @pseudo_toplevel[1]
end

#__pseudo_toplevel=(m) ⇒ Object



1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
# File 'ext/lib/multi-tk.rb', line 1905

def __pseudo_toplevel=(m)
  unless (Thread.current.group == ThreadGroup::Default && 
            MultiTkIp.__getip == @@DEFAULT_MASTER)
    fail SecurityError, "no permission to manipulate"
  end

  # if m.kind_of?(Module) && m.respond_to?(:pseudo_toplevel_evaluable?)
  if m.respond_to?(:pseudo_toplevel_evaluable?)
    @pseudo_toplevel[0] = true
    @pseudo_toplevel[1] = m
  else
    fail ArgumentError, 'fail to set pseudo-toplevel'
  end
  self
end

#__pseudo_toplevel_evaluable=(mode) ⇒ Object



1929
1930
1931
1932
1933
1934
1935
1936
# File 'ext/lib/multi-tk.rb', line 1929

def __pseudo_toplevel_evaluable=(mode)
  unless (Thread.current.group == ThreadGroup::Default && 
            MultiTkIp.__getip == @@DEFAULT_MASTER)
    fail SecurityError, "no permission to manipulate"
  end

  @pseudo_toplevel[0] = (mode)? true: false
end

#__pseudo_toplevel_evaluable?Boolean

Returns:

  • (Boolean)


1921
1922
1923
1924
1925
1926
1927
# File 'ext/lib/multi-tk.rb', line 1921

def __pseudo_toplevel_evaluable?
  begin
    @pseudo_toplevel[0] && @pseudo_toplevel[1].pseudo_toplevel_evaluable?
  rescue Exception
    false
  end
end

#_add_new_tablesObject



1670
1671
1672
1673
1674
1675
# File 'ext/lib/multi-tk.rb', line 1670

def _add_new_tables
  (@@TK_TABLE_LIST.size - @tk_table_list.size).times{ 
    (tbl = {}).tainted? || tbl.taint
    @tk_table_list << tbl
  }
end

#_add_tk_procs(name, args, body) ⇒ Object



1681
1682
1683
1684
1685
1686
1687
# File 'ext/lib/multi-tk.rb', line 1681

def _add_tk_procs(name, args, body)
  return if slave?
  @interp._invoke('proc', name, args, body) if args && body
  @interp._invoke('interp', 'slaves').split.each{|slave|
    @interp._invoke('interp', 'alias', slave, name, '', name)
  }
end

#_conv_listelement(arg) ⇒ Object

Raises:

  • (SecurityError)


2874
2875
2876
2877
# File 'ext/lib/multi-tk.rb', line 2874

def _conv_listelement(arg)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._conv_listelement(arg)
end

#_create_slave_object(keys = {}) ⇒ Object

Raises:

  • (SecurityError)


1244
1245
1246
1247
1248
1249
# File 'ext/lib/multi-tk.rb', line 1244

def _create_slave_object(keys={})
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  ip = MultiTkIp.new_slave(self, keys={})
  @slave_ip_tbl[ip.name] = ip
end

#_default_delete_hook(slave) ⇒ Object

Raises:

  • (SecurityError)


1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
# File 'ext/lib/multi-tk.rb', line 1406

def _default_delete_hook(slave)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @slave_ip_tbl.delete(slave)
  top = @slave_ip_top.delete(slave)
  if top.kind_of?(String)
    # call default hook of safetk.tcl (ignore exceptions)
    if top == ''
      begin
        @interp._eval("::safe::disallowTk #{slave}")
      rescue
        warn("Waring: fail to call '::safe::disallowTk'") if $DEBUG
      end
    else # toplevel path
      begin
        @interp._eval("::safe::tkDelete {} #{top} #{slave}")
      rescue
        warn("Waring: fail to call '::safe::tkDelete'") if $DEBUG
        begin
          @interp._eval("destroy #{top}")
        rescue
          warn("Waring: fail to destroy toplevel") if $DEBUG
        end
      end
    end
  end
end

#_destroy_slaves_of_slaveIP(ip) ⇒ Object



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'ext/lib/multi-tk.rb', line 384

def _destroy_slaves_of_slaveIP(ip)
  unless ip.deleted?
    # ip._split_tklist(ip._invoke('interp', 'slaves')).each{|name|
    ip._split_tklist(ip._invoke_without_enc('interp', 'slaves')).each{|name|
      name = _fromUTF8(name)
      begin
        # ip._eval_without_enc("#{name} eval {foreach i [after info] {after cancel $i}}")
        after_ids = ip._eval_without_enc("#{name} eval {after info}")
        ip._eval_without_enc("#{name} eval {foreach i {#{after_ids}} {after cancel $i}}")
      rescue Exception
      end
      begin
        # ip._invoke('interp', 'eval', name, 'destroy', '.')
        ip._invoke(name, 'eval', 'destroy', '.')
      rescue Exception
      end

      # safe_base?
      if ip._eval_without_enc("catch {::safe::interpConfigure #{name}}") == '0'
        begin
          ip._eval_without_enc("::safe::interpDelete #{name}")
        rescue Exception
        end
      end
=begin
      if ip._invoke('interp', 'exists', name) == '1'
        begin
          ip._invoke(name, 'eval', 'exit')
        rescue Exception
        end
      end
=end
      unless ip.deleted?
        if ip._invoke('interp', 'exists', name) == '1'
          begin
            ip._invoke('interp', 'delete', name)
          rescue Exception
          end
        end
      end
    }
  end
end

#_eval(str) ⇒ Object

Raises:

  • (SecurityError)


2756
2757
2758
2759
# File 'ext/lib/multi-tk.rb', line 2756

def _eval(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._eval(str)
end

#_eval_with_enc(str) ⇒ Object

Raises:

  • (SecurityError)


2776
2777
2778
2779
# File 'ext/lib/multi-tk.rb', line 2776

def _eval_with_enc(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._eval_with_enc(str)
end

#_eval_without_enc(str) ⇒ Object

Raises:

  • (SecurityError)


2766
2767
2768
2769
# File 'ext/lib/multi-tk.rb', line 2766

def _eval_without_enc(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._eval_without_enc(str)
end

#_fromUTF8(str, encoding = nil) ⇒ Object

Raises:

  • (SecurityError)


2791
2792
2793
2794
# File 'ext/lib/multi-tk.rb', line 2791

def _fromUTF8(str, encoding=nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._fromUTF8(str, encoding)
end

#_get_global_var(var) ⇒ Object

Raises:

  • (SecurityError)


2836
2837
2838
2839
# File 'ext/lib/multi-tk.rb', line 2836

def _get_global_var(var)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._get_global_var(var)
end

#_get_global_var2(var, idx) ⇒ Object

Raises:

  • (SecurityError)


2840
2841
2842
2843
# File 'ext/lib/multi-tk.rb', line 2840

def _get_global_var2(var, idx)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._get_global_var2(var, idx)
end

#_get_variable(var, flag) ⇒ Object

Raises:

  • (SecurityError)


2811
2812
2813
2814
# File 'ext/lib/multi-tk.rb', line 2811

def _get_variable(var, flag)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._get_variable(var, flag)
end

#_get_variable2(var, idx, flag) ⇒ Object

Raises:

  • (SecurityError)


2815
2816
2817
2818
# File 'ext/lib/multi-tk.rb', line 2815

def _get_variable2(var, idx, flag)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._get_variable2(var, idx, flag)
end

#_init_ip_env(script) ⇒ Object



1677
1678
1679
# File 'ext/lib/multi-tk.rb', line 1677

def _init_ip_env(script)
  self.eval_proc{script.call(self)}
end

#_init_ip_internal(init_ip_env, add_tk_procs) ⇒ Object



1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
# File 'ext/lib/multi-tk.rb', line 1705

def _init_ip_internal(init_ip_env, add_tk_procs)
  #init_ip_env.each{|script| self.eval_proc{script.call(self)}}
  init_ip_env.each{|script| self._init_ip_env(script)}
  add_tk_procs.each{|name, args, body| 
    if master?
      @interp._invoke('proc', name, args, body) if args && body
    else
      @set_alias_proc.call(name)
    end
  }
end

#_invoke(*args) ⇒ Object

Raises:

  • (SecurityError)


2761
2762
2763
2764
# File 'ext/lib/multi-tk.rb', line 2761

def _invoke(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke(*args)
end

#_invoke_with_enc(*args) ⇒ Object

Raises:

  • (SecurityError)


2781
2782
2783
2784
# File 'ext/lib/multi-tk.rb', line 2781

def _invoke_with_enc(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke_with_enc(*args)
end

#_invoke_without_enc(*args) ⇒ Object

Raises:

  • (SecurityError)


2771
2772
2773
2774
# File 'ext/lib/multi-tk.rb', line 2771

def _invoke_without_enc(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke_without_enc(*args)
end

#_ip_id_Object



1441
1442
1443
1444
# File 'ext/lib/multi-tk.rb', line 1441

def _ip_id_
  # for RemoteTkIp
  ''
end

#_make_menu_embeddable(menu_path) ⇒ Object

Raises:

  • (SecurityError)


2861
2862
2863
2864
# File 'ext/lib/multi-tk.rb', line 2861

def _make_menu_embeddable(menu_path)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._make_menu_embeddable(menu_path)
end

#_merge_tklist(*args) ⇒ Object

Raises:

  • (SecurityError)


2870
2871
2872
2873
# File 'ext/lib/multi-tk.rb', line 2870

def _merge_tklist(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._merge_tklist(*args)
end

#_receiver_mainloop(check_root) ⇒ Object



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'ext/lib/multi-tk.rb', line 634

def _receiver_mainloop(check_root)
  if @evloop_thread[0] && @evloop_thread[0].alive?
    @evloop_thread[0]
  else
    @evloop_thread[0] = Thread.new{
	while !@interp.deleted?
 #if check_root
 #  inf = @interp._invoke_without_enc('info', 'command', '.')
 #  break if !inf.kind_of?(String) || inf != '.'
 #end
        break if check_root && !@interp.has_mainwindow?
 sleep 0.5
	end
    }
    @evloop_thread[0]
  end
end

#_remove_tk_procs(*names) ⇒ Object



1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
# File 'ext/lib/multi-tk.rb', line 1689

def _remove_tk_procs(*names)
  return if slave?
  names.each{|name|
    name = name.to_s

    return if @interp.deleted?
    @interp._invoke('rename', name, '')

    return if @interp.deleted?
    @interp._invoke('interp', 'slaves').split.each{|slave|
      return if @interp.deleted?
      @interp._invoke('interp', 'alias', slave, name, '') rescue nil
    }
  }
end

#_return_valueObject

Raises:

  • (SecurityError)


2806
2807
2808
2809
# File 'ext/lib/multi-tk.rb', line 2806

def _return_value
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._return_value
end

#_set_global_var(var, value) ⇒ Object

Raises:

  • (SecurityError)


2844
2845
2846
2847
# File 'ext/lib/multi-tk.rb', line 2844

def _set_global_var(var, value)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._set_global_var(var, value)
end

#_set_global_var2(var, idx, value) ⇒ Object

Raises:

  • (SecurityError)


2848
2849
2850
2851
# File 'ext/lib/multi-tk.rb', line 2848

def _set_global_var2(var, idx, value)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._set_global_var2(var, idx, value)
end

#_set_variable(var, value, flag) ⇒ Object

Raises:

  • (SecurityError)


2819
2820
2821
2822
# File 'ext/lib/multi-tk.rb', line 2819

def _set_variable(var, value, flag)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._set_variable(var, value, flag)
end

#_set_variable2(var, idx, value, flag) ⇒ Object

Raises:

  • (SecurityError)


2823
2824
2825
2826
# File 'ext/lib/multi-tk.rb', line 2823

def _set_variable2(var, idx, value, flag)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._set_variable2(var, idx, value, flag)
end

#_split_tklist(str) ⇒ Object

Raises:

  • (SecurityError)


2866
2867
2868
2869
# File 'ext/lib/multi-tk.rb', line 2866

def _split_tklist(str)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._split_tklist(str)
end

#_thread_tkwait(mode, target) ⇒ Object

Raises:

  • (SecurityError)


2801
2802
2803
2804
# File 'ext/lib/multi-tk.rb', line 2801

def _thread_tkwait(mode, target)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._thread_tkwait(mode, target)
end

#_thread_vwait(var) ⇒ Object

Raises:

  • (SecurityError)


2796
2797
2798
2799
# File 'ext/lib/multi-tk.rb', line 2796

def _thread_vwait(var)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._thread_vwait(var)
end

#_tk_cmd_tblObject



1656
1657
1658
1659
1660
# File 'ext/lib/multi-tk.rb', line 1656

def _tk_cmd_tbl
  tbl = {}
  MultiTkIp.tk_cmd_tbl.each{|id, ent| tbl[id] = ent if ent.ip == self }
  tbl
end

#_tk_table_listObject



1666
1667
1668
# File 'ext/lib/multi-tk.rb', line 1666

def _tk_table_list
  @tk_table_list
end

#_tk_windowsObject



1662
1663
1664
# File 'ext/lib/multi-tk.rb', line 1662

def _tk_windows
  @tk_windows
end

#_toUTF8(str, encoding = nil) ⇒ Object

Raises:

  • (SecurityError)


2786
2787
2788
2789
# File 'ext/lib/multi-tk.rb', line 2786

def _toUTF8(str, encoding=nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._toUTF8(str, encoding)
end

#_unset_global_var(var) ⇒ Object

Raises:

  • (SecurityError)


2852
2853
2854
2855
# File 'ext/lib/multi-tk.rb', line 2852

def _unset_global_var(var)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._unset_global_var(var)
end

#_unset_global_var2(var, idx) ⇒ Object

Raises:

  • (SecurityError)


2856
2857
2858
2859
# File 'ext/lib/multi-tk.rb', line 2856

def _unset_global_var2(var, idx)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._unset_global_var2(var, idx)
end

#_unset_variable(var, flag) ⇒ Object

Raises:

  • (SecurityError)


2827
2828
2829
2830
# File 'ext/lib/multi-tk.rb', line 2827

def _unset_variable(var, flag)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._unset_variable(var, flag)
end

#_unset_variable2(var, idx, flag) ⇒ Object

Raises:

  • (SecurityError)


2831
2832
2833
2834
# File 'ext/lib/multi-tk.rb', line 2831

def _unset_variable2(var, idx, flag)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._unset_variable2(var, idx, flag)
end

#abort(msg = nil) ⇒ Object

Raises:

  • (SecurityError)


2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
# File 'ext/lib/multi-tk.rb', line 2698

def abort(msg = nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if master? && !safe? && allow_ruby_exit?
    if msg
      Kernel.abort(msg)
    else
      Kernel.abort
    end
  else
    # ignore msg
    delete
    1
  end
end

#alias_delete(slave, cmd_name) ⇒ Object

Raises:

  • (SecurityError)


2934
2935
2936
2937
2938
# File 'ext/lib/multi-tk.rb', line 2934

def alias_delete(slave, cmd_name)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'alias', _slavearg(slave), cmd_name, '')
  self
end

#alias_info(slave, cmd_name) ⇒ Object

Raises:

  • (SecurityError)


2926
2927
2928
2929
# File 'ext/lib/multi-tk.rb', line 2926

def alias_info(slave, cmd_name)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  _lst2ary(@interp._invoke('interp', 'alias', _slavearg(slave), cmd_name))
end

#alias_target(aliascmd, slave = '') ⇒ Object

Raises:

  • (SecurityError)


3166
3167
3168
3169
# File 'ext/lib/multi-tk.rb', line 3166

def alias_target(aliascmd, slave = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'target', _slavearg(slave), aliascmd)
end

#aliases(slave = '') ⇒ Object

Raises:

  • (SecurityError)


2955
2956
2957
2958
# File 'ext/lib/multi-tk.rb', line 2955

def aliases(slave = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  _lst2ary(@interp._invoke('interp', 'aliases', _slavearg(slave)))
end

#alive?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
# File 'ext/lib/multi-tk.rb', line 1588

def alive?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  begin
    return false unless @cmd_receiver.alive?
    return false if @interp.deleted?
    return false if @interp._invoke('interp', 'exists', '') == '0'
  rescue Exception
    return false
  end
  true
end

#allow_ruby_exit=(mode) ⇒ Object

Raises:

  • (SecurityError)


2615
2616
2617
2618
# File 'ext/lib/multi-tk.rb', line 2615

def allow_ruby_exit= (mode)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.allow_ruby_exit = mode
end

#allow_ruby_exit?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2610
2611
2612
2613
# File 'ext/lib/multi-tk.rb', line 2610

def allow_ruby_exit?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.allow_ruby_exit?
end

#background_callObject



2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
# File 'ext/lib/multi-tk.rb', line 2109

def bg_eval_proc(*args)
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  Thread.new{
    eval_proc(cmd, *args)
=begin
    eval_proc_core(false, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   safe_level, *args)
=end
  }
end

#background_evalObject



2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
# File 'ext/lib/multi-tk.rb', line 2169

def bg_eval(*args, &blk)
  if block_given?
    bg_eval_proc(*args, &blk)
  elsif args[0]
    if args[0].respond_to?(:call)
      bg_eval_proc(*args)
    else
      bg_eval_string(*args)
    end
  else
    fail ArgumentError, "no argument to eval"
  end
end

#background_eval_procObject



2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
# File 'ext/lib/multi-tk.rb', line 2106

def bg_eval_proc(*args)
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  Thread.new{
    eval_proc(cmd, *args)
=begin
    eval_proc_core(false, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   safe_level, *args)
=end
  }
end

#background_eval_strObject



2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
# File 'ext/lib/multi-tk.rb', line 2140

def bg_eval_string(cmd, *eval_args)
  # cmd string ==> proc
  unless cmd.kind_of?(String)
    raise RuntimeError, "A String object is expected for the 'cmd' argument"
  end
  Thread.new{
    eval_proc_core(true, 
                   proc{|safe| 
                     Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
                                 *eval_args)
                   })
  }
end

#background_eval_stringObject



2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
# File 'ext/lib/multi-tk.rb', line 2138

def bg_eval_string(cmd, *eval_args)
  # cmd string ==> proc
  unless cmd.kind_of?(String)
    raise RuntimeError, "A String object is expected for the 'cmd' argument"
  end
  Thread.new{
    eval_proc_core(true, 
                   proc{|safe| 
                     Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
                                 *eval_args)
                   })
  }
end

#bg_callObject



2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
# File 'ext/lib/multi-tk.rb', line 2108

def bg_eval_proc(*args)
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  Thread.new{
    eval_proc(cmd, *args)
=begin
    eval_proc_core(false, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   safe_level, *args)
=end
  }
end

#bg_eval(*args, &blk) ⇒ Object



2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
# File 'ext/lib/multi-tk.rb', line 2156

def bg_eval(*args, &blk)
  if block_given?
    bg_eval_proc(*args, &blk)
  elsif args[0]
    if args[0].respond_to?(:call)
      bg_eval_proc(*args)
    else
      bg_eval_string(*args)
    end
  else
    fail ArgumentError, "no argument to eval"
  end
end

#bg_eval_proc(*args) ⇒ Object



2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
# File 'ext/lib/multi-tk.rb', line 2086

def bg_eval_proc(*args)
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  Thread.new{
    eval_proc(cmd, *args)
=begin
    eval_proc_core(false, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   safe_level, *args)
=end
  }
end

#bg_eval_strObject



2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
# File 'ext/lib/multi-tk.rb', line 2139

def bg_eval_string(cmd, *eval_args)
  # cmd string ==> proc
  unless cmd.kind_of?(String)
    raise RuntimeError, "A String object is expected for the 'cmd' argument"
  end
  Thread.new{
    eval_proc_core(true, 
                   proc{|safe| 
                     Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
                                 *eval_args)
                   })
  }
end

#bg_eval_string(cmd, *eval_args) ⇒ Object



2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
# File 'ext/lib/multi-tk.rb', line 2125

def bg_eval_string(cmd, *eval_args)
  # cmd string ==> proc
  unless cmd.kind_of?(String)
    raise RuntimeError, "A String object is expected for the 'cmd' argument"
  end
  Thread.new{
    eval_proc_core(true, 
                   proc{|safe| 
                     Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
                                 *eval_args)
                   })
  }
end

#callObject



2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
# File 'ext/lib/multi-tk.rb', line 2084

def eval_proc(*args)
  # The scope of the eval-block of 'eval_proc' method is different from 
  # the external. If you want to pass local values to the eval-block, 
  # use arguments of eval_proc method. They are passed to block-arguments.
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  if TclTkLib.mainloop_thread? == true
    # call from eventloop
    current = Thread.current
    backup_ip = current[:callback_ip]
    current[:callback_ip] = self
    begin
      eval_proc_core(false, 
              proc{|safe, *params|
         $SAFE=safe if $SAFE < safe
                       cmd.call(*params)
                     }, *args)
    ensure
      current[:callback_ip] = backup_ip
    end
  else
    eval_proc_core(true, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   *args)
  end
end

#cb_error(e) ⇒ Object



342
343
344
345
346
# File 'ext/lib/multi-tk.rb', line 342

def cb_error(e)
  if @cb_error_proc[0].respond_to?(:call)
    @cb_error_proc[0].call(e)
  end
end

#cb_eval(cmd, *args) ⇒ Object

def cb_eval(cmd, *args)

  #self.eval_callback{ TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *args)) }
  #ret = self.eval_callback{ TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *args)) }
  ret = self.eval_callback(*args){|safe, *params|
    $SAFE=safe if $SAFE < safe
    TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *params))
  }
  if ret.kind_of?(Exception)
    raise ret
  end
  ret
end


1840
1841
1842
1843
1844
1845
1846
# File 'ext/lib/multi-tk.rb', line 1840

def cb_eval(cmd, *args)
  self.eval_callback(*args){|safe, *params|
    $SAFE=safe if $SAFE < safe
    # TkUtil.eval_cmd(cmd, *params)
    TkComm._get_eval_string(TkUtil.eval_cmd(cmd, *params))
  }
end

#def_alias(slave, new_cmd, org_cmd, *args) ⇒ Object

Raises:

  • (SecurityError)


2944
2945
2946
2947
2948
2949
# File 'ext/lib/multi-tk.rb', line 2944

def def_alias(slave, new_cmd, org_cmd, *args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  ret = @interp._invoke('interp', 'alias', _slavearg(slave), new_cmd, 
                        '', org_cmd, *args)
  (ret == new_cmd)? self: nil
end

#default_encoding=(enc) ⇒ Object

Raises:

  • (SecurityError)


3393
3394
3395
3396
# File 'ext/lib/multi-tk.rb', line 3393

def default_encoding=(enc)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.default_encoding = enc
end

#deleteObject

Raises:

  • (SecurityError)


2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
# File 'ext/lib/multi-tk.rb', line 2620

def delete
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @slave_ip_tbl.each{|name, subip|
    _destroy_slaves_of_slaveIP(subip)
=begin
    begin
      subip._invoke('destroy', '.') unless subip.deleted?
    rescue Exception
    end
=end
    begin
      # subip._eval_without_enc("foreach i [after info] {after cancel $i}")
	unless subip.deleted?
 after_ids = subip._eval_without_enc("after info")
 subip._eval_without_enc("foreach i {#{after_ids}} {after cancel $i}")
	end
    rescue Exception
    end

    # safe_base?
    if @interp._eval_without_enc("catch {::safe::interpConfigure #{name}}") == '0'
      begin
        @interp._eval_without_enc("::safe::interpDelete #{name}")
      rescue Exception
      else
        next if subip.deleted?
      end
    end
    if subip.respond_to?(:safe_base?) && subip.safe_base? && 
        !subip.deleted?
      # do 'exit' to call the delete_hook procedure
      begin
        subip._eval_without_enc('exit') 
      rescue Exception
      end
    else
      begin
        subip.delete unless subip.deleted?
      rescue Exception
      end
    end
  }

  begin
    # @interp._eval_without_enc("foreach i [after info] {after cancel $i}")
    after_ids = @interp._eval_without_enc("after info")
    @interp._eval_without_enc("foreach i {#{after_ids}} {after cancel $i}")
  rescue Exception
  end

  begin
    @interp._invoke('destroy', '.') unless @interp.deleted?
  rescue Exception
  end

  if @safe_base && !@interp.deleted?
    # do 'exit' to call the delete_hook procedure
    @interp._eval_without_enc('exit')
  end
  @interp.delete
  self
end

#delete_cmd(slave, cmd) ⇒ Object

Raises:

  • (SecurityError)


2983
2984
2985
2986
2987
2988
# File 'ext/lib/multi-tk.rb', line 2983

def delete_cmd(slave, cmd)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  slave_invoke = @interp._invoke('list', 'rename', cmd, '')
  @interp._invoke('interp', 'eval', _slavearg(slave), slave_invoke)
  self
end

#delete_slaves(*args) ⇒ Object

Raises:

  • (SecurityError)


2963
2964
2965
2966
2967
2968
# File 'ext/lib/multi-tk.rb', line 2963

def delete_slaves(*args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  slaves = args.collect{|s| _slavearg(s)}
  @interp._invoke('interp', 'delete', *slaves) if slaves.size > 0
  self
end

#deleted?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2683
2684
2685
2686
# File 'ext/lib/multi-tk.rb', line 2683

def deleted?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.deleted?
end

#encoding=(enc) ⇒ Object

Raises:

  • (SecurityError)


3398
3399
3400
3401
# File 'ext/lib/multi-tk.rb', line 3398

def encoding=(enc)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.encoding = enc
end

#encoding_convertfrom(str, enc = None) ⇒ Object Also known as: encoding_convert_from

Raises:

  • (SecurityError)


3413
3414
3415
3416
# File 'ext/lib/multi-tk.rb', line 3413

def encoding_convertfrom(str, enc=None)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.encoding_convertfrom(str, enc)
end

#encoding_convertto(str, enc = None) ⇒ Object Also known as: encoding_convert_to

Raises:

  • (SecurityError)


3419
3420
3421
3422
# File 'ext/lib/multi-tk.rb', line 3419

def encoding_convertto(str, enc=None)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.encoding_convertto(str, enc)
end

#encoding_nameObject Also known as: encoding, default_encoding

Raises:

  • (SecurityError)


3402
3403
3404
3405
# File 'ext/lib/multi-tk.rb', line 3402

def encoding_name
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.encoding_name
end

#encoding_objObject

Raises:

  • (SecurityError)


3406
3407
3408
3409
# File 'ext/lib/multi-tk.rb', line 3406

def encoding_obj
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.encoding_obj
end

#encoding_tableObject



3380
3381
3382
# File 'ext/lib/multi-tk.rb', line 3380

def encoding_table
  @interp.encoding_table
end

#eval(*args, &blk) ⇒ Object



2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
# File 'ext/lib/multi-tk.rb', line 2142

def eval(*args, &blk)
  if block_given?
    eval_proc(*args, &blk)
  elsif args[0]
    if args[0].respond_to?(:call)
      eval_proc(*args)
    else
      eval_string(*args)
    end
  else
    fail ArgumentError, "no argument to eval"
  end
end

#eval_callback(*args) ⇒ Object



2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
# File 'ext/lib/multi-tk.rb', line 2034

def eval_callback(*args)
  if block_given?
    cmd = Proc.new
  else
    cmd = args.shift
  end
  current = Thread.current
  backup_ip = current[:callback_ip]
  current[:callback_ip] = self
  begin
    eval_proc_core(false, cmd, *args)
  ensure
    current[:callback_ip] = backup_ip
  end
end

#eval_proc(*args) ⇒ Object



2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
# File 'ext/lib/multi-tk.rb', line 2050

def eval_proc(*args)
  # The scope of the eval-block of 'eval_proc' method is different from 
  # the external. If you want to pass local values to the eval-block, 
  # use arguments of eval_proc method. They are passed to block-arguments.
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  if TclTkLib.mainloop_thread? == true
    # call from eventloop
    current = Thread.current
    backup_ip = current[:callback_ip]
    current[:callback_ip] = self
    begin
      eval_proc_core(false, 
              proc{|safe, *params|
         $SAFE=safe if $SAFE < safe
                       cmd.call(*params)
                     }, *args)
    ensure
      current[:callback_ip] = backup_ip
    end
  else
    eval_proc_core(true, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   *args)
  end
end

#eval_strObject



2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
# File 'ext/lib/multi-tk.rb', line 2123

def eval_string(cmd, *eval_args)
  # cmd string ==> proc
  unless cmd.kind_of?(String)
    raise RuntimeError, "A String object is expected for the 'cmd' argument"
  end

  eval_proc_core(true, 
                 proc{|safe| 
                   Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
                               *eval_args)
                 })
end

#eval_string(cmd, *eval_args) ⇒ Object



2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
# File 'ext/lib/multi-tk.rb', line 2111

def eval_string(cmd, *eval_args)
  # cmd string ==> proc
  unless cmd.kind_of?(String)
    raise RuntimeError, "A String object is expected for the 'cmd' argument"
  end

  eval_proc_core(true, 
                 proc{|safe| 
                   Kernel.eval("$SAFE=#{safe} if $SAFE < #{safe};" << cmd,
                               *eval_args)
                 })
end

#exist?(slave = '') ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2974
2975
2976
2977
2978
# File 'ext/lib/multi-tk.rb', line 2974

def exist?(slave = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  ret = @interp._invoke('interp', 'exists', _slavearg(slave))
  (ret == '1')? true: false
end

#exit(st = true) ⇒ Object

Raises:

  • (SecurityError)


2713
2714
2715
2716
2717
2718
2719
2720
2721
# File 'ext/lib/multi-tk.rb', line 2713

def exit(st = true)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if master? && !safe? && allow_ruby_exit?
    Kernel.exit(st)
  else
    delete
    st
  end
end

#exit!(st = false) ⇒ Object

Raises:

  • (SecurityError)


2723
2724
2725
2726
2727
2728
2729
2730
2731
# File 'ext/lib/multi-tk.rb', line 2723

def exit!(st = false)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if master? && !safe? && allow_ruby_exit?
    Kernel.exit!(st)
  else
    delete
    st
  end
end

#expose_cmd(slave, cmd, aliasname = nil) ⇒ Object

Raises:

  • (SecurityError)


2994
2995
2996
2997
2998
2999
3000
3001
3002
# File 'ext/lib/multi-tk.rb', line 2994

def expose_cmd(slave, cmd, aliasname = nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if aliasname
    @interp._invoke('interp', 'expose', _slavearg(slave), cmd, aliasname)
  else
    @interp._invoke('interp', 'expose', _slavearg(slave), cmd)
  end
  self
end

#force_default_encoding=(mode) ⇒ Object

Raises:

  • (SecurityError)


3384
3385
3386
3387
# File 'ext/lib/multi-tk.rb', line 3384

def force_default_encoding=(mode)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.force_default_encoding = mode
end

#force_default_encoding?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


3388
3389
3390
3391
# File 'ext/lib/multi-tk.rb', line 3388

def force_default_encoding?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.force_default_encoding?
end

#get_bgerror_handler(slave = '') ⇒ Object

Raises:

  • (SecurityError)


3116
3117
3118
3119
# File 'ext/lib/multi-tk.rb', line 3116

def get_bgerror_handler(slave = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  procedure(@interp._invoke('interp', 'bgerror', _slavearg(slave)))
end

#get_limit(limit_type, slave = '', slot = nil) ⇒ Object

Raises:

  • (SecurityError)


3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
# File 'ext/lib/multi-tk.rb', line 3132

def get_limit(limit_type, slave = '', slot = nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  if slot
    num_or_str(@interp._invoke('interp', 'limit', _slavearg(slave), 
                               limit_type, slot))
  else
    l = @interp._split_tklist(@interp._invoke_without_enc('interp', 'limit', 
                                                          _slavearg(slave), 
                                                          limit_type))
    l.map!{|s| _fromUTF8(s)}
    r = {}
    until l.empty?
      key = l.shift[1..-1]
      val = l.shift
      val = num_or_str(val) if val
      r[key] = val
    end
    r
  end
end

#has_mainwindow?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2688
2689
2690
2691
# File 'ext/lib/multi-tk.rb', line 2688

def has_mainwindow?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.has_mainwindow?
end

#hidden_cmds(slave = '') ⇒ Object

Raises:

  • (SecurityError)


3022
3023
3024
3025
# File 'ext/lib/multi-tk.rb', line 3022

def hidden_cmds(slave = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  _lst2ary(@interp._invoke('interp', 'hidden', _slavearg(slave)))
end

#hide_cmd(slave, cmd, aliasname = nil) ⇒ Object

Raises:

  • (SecurityError)


3008
3009
3010
3011
3012
3013
3014
3015
3016
# File 'ext/lib/multi-tk.rb', line 3008

def hide_cmd(slave, cmd, aliasname = nil)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if aliasname
    @interp._invoke('interp', 'hide', _slavearg(slave), cmd, aliasname)
  else
    @interp._invoke('interp', 'hide', _slavearg(slave), cmd)
  end
  self
end

#inspectObject



1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
# File 'ext/lib/multi-tk.rb', line 1548

def inspect
  s = self.to_s.chop!
  if self.manipulable?
    if master?
      if @interp.deleted?
        s << ':deleted-master'
      else
        s << ':master'
      end
    else
      if @interp.deleted?
        s << ':deleted-slave'
      elsif @interp.safe?
        s << ':safe-slave'
      else
        s << ':trusted-slave'
      end
    end
  end
  s << '>'
end

#invalid_namespace?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2693
2694
2695
2696
# File 'ext/lib/multi-tk.rb', line 2693

def invalid_namespace?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.invalid_namespace?
end

#invoke_hidden(slave, cmd, *args) ⇒ Object

Raises:

  • (SecurityError)


3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
# File 'ext/lib/multi-tk.rb', line 3030

def invoke_hidden(slave, cmd, *args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if args[-1].kind_of?(Hash)
    keys = _symbolkey2str(args.pop)
  else
    keys = []
  end
  keys << _slavearg(slave)
  if Tk::TCL_MAJOR_VERSION > 8 ||
      (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5) 
    keys << '--'
  end
  keys << cmd
  keys.concat(args)
  @interp._invoke('interp', 'invokehidden', *keys)
end

#invoke_hidden_on_global(slave, cmd, *args) ⇒ Object

Raises:

  • (SecurityError)


3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
# File 'ext/lib/multi-tk.rb', line 3050

def invoke_hidden_on_global(slave, cmd, *args)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if args[-1].kind_of?(Hash)
    keys = _symbolkey2str(args.pop)
  else
    keys = []
  end
  keys << _slavearg(slave)
  keys << '-global'
  if Tk::TCL_MAJOR_VERSION > 8 ||
      (Tk::TCL_MAJOR_VERSION == 8 && Tk::TCL_MINOR_VERSION >= 5) 
    keys << '--'
  end
  keys << cmd
  keys.concat(args)
  @interp._invoke('interp', 'invokehidden', *keys)
end

#invoke_hidden_on_namespace(slave, ns, cmd, *args) ⇒ Object

Raises:

  • (SecurityError)


3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
# File 'ext/lib/multi-tk.rb', line 3071

def invoke_hidden_on_namespace(slave, ns, cmd, *args)
  # for Tcl8.5 or later
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  if args[-1].kind_of?(Hash)
    keys = _symbolkey2str(args.pop)
  else
    keys = []
  end
  keys << _slavearg(slave)
  keys << '-namespace' << TkComm._get_eval_string(ns)
  keys << '--' << cmd
  keys.concat(args)
  @interp._invoke('interp', 'invokehidden', *keys)
end

#ip_nameObject



1609
1610
1611
# File 'ext/lib/multi-tk.rb', line 1609

def ip_name
  @ip_name || ''
end

#mainloop(check_root = true, restart_on_dead = true) ⇒ Object

Raises:

  • (SecurityError)


2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
# File 'ext/lib/multi-tk.rb', line 2481

def mainloop(check_root = true, restart_on_dead = true)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  if WITH_RUBY_VM  ### Ruby 1.9 !!!!!!!!!!!
    return @interp_thread.value if @interp_thread
  end

  #return self if self.slave?
  #return self if self != @@DEFAULT_MASTER
  if self != @@DEFAULT_MASTER
    if @wait_on_mainloop[0]
      begin
        @wait_on_mainloop[1] += 1
        if $SAFE >= 4
   _receiver_mainloop(check_root).join
        else
          @cmd_queue.enq([@system, 'call_mainloop', 
                          Thread.current, check_root])
          Thread.stop
        end
      rescue MultiTkIp_OK => ret
        # return value
        if ret.value.kind_of?(Thread)
          return ret.value.value
        else
          return ret.value
        end
      rescue SystemExit => e
        # exit IP
        warn("Warning: " + $! + " on " + self.inspect) if $DEBUG
        begin
          self._eval_without_enc('exit')
        rescue Exception
        end
        self.delete
      rescue StandardError => e
        if $DEBUG
          warn("Warning: " + e.class.inspect + 
               ((e.message.length > 0)? ' "' + e.message + '"': '') +  
               " on " + self.inspect) 
        end
        return e
      rescue Exception => e
 return e
      ensure
        @wait_on_mainloop[1] -= 1
      end
    end
    return
  end

  unless restart_on_dead
    @wait_on_mainloop[1] += 1
=begin
    begin
      @interp.mainloop(check_root)
    rescue StandardError => e
      if $DEBUG
        warn("Warning: " + e.class.inspect + 
             ((e.message.length > 0)? ' "' + e.message + '"': '') +  
             " on " + self.inspect) 
      end
    end
=end
    begin
	@interp.mainloop(check_root)
    ensure
	@wait_on_mainloop[1] -= 1
    end
  else
    loop do
      break unless self.alive?
      if check_root
        begin
          break if TclTkLib.num_of_mainwindows == 0
        rescue StandardError
          break
        end
      end
      break if @interp.deleted?
      begin
 @wait_on_mainloop[1] += 1
        @interp.mainloop(check_root)
      rescue StandardError => e
        if TclTkLib.mainloop_abort_on_exception != nil
          #STDERR.print("Warning: Tk mainloop receives ", $!.class.inspect, 
          #             " exception (ignore) : ", $!.message, "\n");
          if $DEBUG
            warn("Warning: Tk mainloop receives " << e.class.inspect <<
                 " exception (ignore) : " << e.message);
          end
        end
        #raise e
      rescue Exception => e
=begin
        if TclTkLib.mainloop_abort_on_exception != nil
          #STDERR.print("Warning: Tk mainloop receives ", $!.class.inspect, 
          #             " exception (ignore) : ", $!.message, "\n");
          if $DEBUG
            warn("Warning: Tk mainloop receives " << e.class.inspect <<
                 " exception (ignore) : " << e.message);
          end
        end
=end
        raise e
      ensure
        @wait_on_mainloop[1] -= 1
        Thread.pass  # avoid eventloop conflict
      end
    end
  end
  self
end

#make_safeObject

Raises:

  • (SecurityError)


2595
2596
2597
2598
# File 'ext/lib/multi-tk.rb', line 2595

def make_safe
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.make_safe
end

#manipulable?Boolean

Returns:

  • (Boolean)


1638
1639
1640
1641
1642
# File 'ext/lib/multi-tk.rb', line 1638

def manipulable?
  return true if (Thread.current.group == ThreadGroup::Default)
  ip = MultiTkIp.__getip
  (ip == self) || ip._is_master_of?(@interp)
end

#mark_trusted(slave = '') ⇒ Object

Raises:

  • (SecurityError)


3089
3090
3091
3092
3093
# File 'ext/lib/multi-tk.rb', line 3089

def mark_trusted(slave = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'marktrusted', _slavearg(slave))
  self
end

#master?Boolean

Returns:

  • (Boolean)


1570
1571
1572
1573
1574
1575
1576
# File 'ext/lib/multi-tk.rb', line 1570

def master?
  if @ip_name
    false
  else
    true
  end
end

#pathObject



1603
1604
1605
# File 'ext/lib/multi-tk.rb', line 1603

def path
  @ip_name || ''
end

#recursion_limit(slave = '', limit = None) ⇒ Object

Raises:

  • (SecurityError)


3157
3158
3159
3160
3161
# File 'ext/lib/multi-tk.rb', line 3157

def recursion_limit(slave = '', limit = None)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  number(@interp._invoke('interp', 'recursionlimit', 
                         _slavearg(slave), limit))
end

#restart(app_name = nil, keys = {}) ⇒ Object

Raises:

  • (SecurityError)


2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
# File 'ext/lib/multi-tk.rb', line 2733

def restart(app_name = nil, keys = {})
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  _init_ip_internal(@@INIT_IP_ENV, @@ADD_TK_PROCS)

  @interp._invoke('set', 'argv0', app_name) if app_name
  if keys.kind_of?(Hash)
    @interp._invoke('set', 'argv', _keys2opts(keys))
  end

  @interp.restart
end

#running_mainloop?Boolean

Returns:

  • (Boolean)


380
381
382
# File 'ext/lib/multi-tk.rb', line 380

def running_mainloop?
  @wait_on_mainloop[1] > 0
end

#safe?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2600
2601
2602
2603
# File 'ext/lib/multi-tk.rb', line 2600

def safe?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp.safe?
end

#safe_base?Boolean

Returns:

  • (Boolean)

Raises:

  • (SecurityError)


2605
2606
2607
2608
# File 'ext/lib/multi-tk.rb', line 2605

def safe_base?
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @safe_base
end

#safe_levelObject



366
367
368
# File 'ext/lib/multi-tk.rb', line 366

def safe_level
  @safe_level[0]
end

#safe_level=(safe) ⇒ Object



357
358
359
# File 'ext/lib/multi-tk.rb', line 357

def safe_level=(safe)
  set_safe_level(safe)
end

#safeip_add_to_access_path(dir) ⇒ Object



3320
3321
3322
3323
# File 'ext/lib/multi-tk.rb', line 3320

def safeip_add_to_access_path(dir)
  ip = MultiTkIp.__getip
  ip._eval("::safe::interpAddToAccessPath #{@ip_name} #{dir}")
end

#safeip_configinfo(slot = nil) ⇒ Object



3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
# File 'ext/lib/multi-tk.rb', line 3275

def safeip_configinfo(slot = nil)
  ip = MultiTkIp.__getip
  ret = {}
  if slot
    conf = _lst2ary(ip._eval("::safe::interpConfigure " + 
                             @ip_name + " -#{slot}"))
    if conf[0] == '-deleteHook'
=begin
      if conf[1] =~ /^rb_out\S* (c(_\d+_)?\d+)/
        ret[conf[0][1..-1]] = MultiTkIp._tk_cmd_tbl[$1]
=end
      if conf[1] =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
        ret[conf[0][1..-1]] = MultiTkIp._tk_cmd_tbl[$4]
      else
        ret[conf[0][1..-1]] = conf[1]
      end
    else
      ret[conf[0][1..-1]] = conf[1]
    end
  else
    Hash[*_lst2ary(ip._eval("::safe::interpConfigure " + 
                            @ip_name))].each{|k, v|
      if k == '-deleteHook'
=begin
        if v =~ /^rb_out\S* (c(_\d+_)?\d+)/
          ret[k[1..-1]] = MultiTkIp._tk_cmd_tbl[$1]
=end
        if v =~ /rb_out\S*(?:\s+(::\S*|[{](::.*)[}]|["](::.*)["]))? (c(_\d+_)?(\d+))/
          ret[k[1..-1]] = MultiTkIp._tk_cmd_tbl[$4]
        else
          ret[k[1..-1]] = v
        end
      else
        ret[k[1..-1]] = v
      end
    }
  end
  ret
end

#safeip_configure(slot, value = None) ⇒ Object



3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
# File 'ext/lib/multi-tk.rb', line 3262

def safeip_configure(slot, value=None)
  # use for '-noStatics' option ==> {statics=>false}
  #     for '-nestedLoadOk' option ==> {nested=>true}
  if slot.kind_of?(Hash)
    ip = MultiTkIp.__getip
    ip._eval('::safe::interpConfigure ' + @ip_name + ' ' + _keys2opts(slot))
  else
    ip._eval('::safe::interpConfigure ' + @ip_name + ' ' + 
             "-#{slot} #{_get_eval_string(value)}")
  end
  self
end

#safeip_deleteObject



3315
3316
3317
3318
# File 'ext/lib/multi-tk.rb', line 3315

def safeip_delete
  ip = MultiTkIp.__getip
  ip._eval("::safe::interpDelete " + @ip_name)
end

#safeip_find_in_access_path(dir) ⇒ Object



3325
3326
3327
3328
# File 'ext/lib/multi-tk.rb', line 3325

def safeip_find_in_access_path(dir)
  ip = MultiTkIp.__getip
  ip._eval("::safe::interpFindInAccessPath #{@ip_name} #{dir}")
end

#safeip_set_log_cmd(cmd = Proc.new) ⇒ Object



3330
3331
3332
3333
# File 'ext/lib/multi-tk.rb', line 3330

def safeip_set_log_cmd(cmd = Proc.new)
  ip = MultiTkIp.__getip
  ip._eval("::safe::setLogCmd #{@ip_name} #{_get_eval_string(cmd)}")
end

#set_bgerror_handler(cmd = Proc.new, slave = nil, &b) ⇒ Object

Raises:

  • (SecurityError)


3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
# File 'ext/lib/multi-tk.rb', line 3099

def set_bgerror_handler(cmd = Proc.new, slave = nil, &b)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?

  unless TkComm._callback_entry?(cmd)
    if !slave && b
      slave = cmd
      cmd = Proc.new(&b)
    end
  end
  slave = '' unless slave

  @interp._invoke('interp', 'bgerror', _slavearg(slave), cmd)
end

#set_cb_error(cmd = Proc.new) ⇒ Object



338
339
340
# File 'ext/lib/multi-tk.rb', line 338

def set_cb_error(cmd = Proc.new)
  @cb_error_proc[0] = cmd
end

#set_limit(limit_type, slave = '', opts = {}) ⇒ Object

Raises:

  • (SecurityError)


3124
3125
3126
3127
# File 'ext/lib/multi-tk.rb', line 3124

def set_limit(limit_type, slave = '', opts = {})
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'limit', _slavearg(slave), limit_type, opts)
end

#set_safe_level(safe) ⇒ Object



350
351
352
353
354
355
356
# File 'ext/lib/multi-tk.rb', line 350

def set_safe_level(safe)
  if safe > @safe_level[0]
    @safe_level[0] = safe
    @cmd_queue.enq([@system, 'set_safe_level', safe])
  end
  @safe_level[0]
end

#share_stderr(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3194
3195
3196
3197
3198
# File 'ext/lib/multi-tk.rb', line 3194

def share_stderr(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'share', src, 'stderr', dist)
  self
end

#share_stdin(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3174
3175
3176
3177
3178
# File 'ext/lib/multi-tk.rb', line 3174

def share_stdin(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'share', src, 'stdin', dist)
  self
end

#share_stdio(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3234
3235
3236
3237
3238
3239
3240
# File 'ext/lib/multi-tk.rb', line 3234

def share_stdio(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'share', src, 'stdin',  dist)
  @interp._invoke('interp', 'share', src, 'stdout', dist)
  @interp._invoke('interp', 'share', src, 'stderr', dist)
  self
end

#share_stdout(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3184
3185
3186
3187
3188
# File 'ext/lib/multi-tk.rb', line 3184

def share_stdout(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'share', src, 'stdout', dist)
  self
end

#slave?Boolean

Returns:

  • (Boolean)


1581
1582
1583
# File 'ext/lib/multi-tk.rb', line 1581

def slave?
  not master?
end

#slaves(all = false) ⇒ Object

Raises:

  • (SecurityError)


1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
# File 'ext/lib/multi-tk.rb', line 1622

def slaves(all = false)
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp','slaves').split.map!{|name| 
    if @slave_ip_tbl.key?(name)
      @slave_ip_tbl[name]
    elsif all
      name
    else
      nil
    end
  }.compact!
end

#thread_eval_procObject



2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
# File 'ext/lib/multi-tk.rb', line 2107

def bg_eval_proc(*args)
  if block_given?
    cmd = Proc.new
  else
    unless (cmd = args.shift)
      fail ArgumentError, "A Proc or Method object is expected for 1st argument"
    end
  end
  Thread.new{
    eval_proc(cmd, *args)
=begin
    eval_proc_core(false, 
                   proc{|safe, *params| 
                     $SAFE=safe if $SAFE < safe
                     Thread.new(*params, &cmd).value
                   },
                   safe_level, *args)
=end
  }
end

#to_evalObject



1615
1616
1617
# File 'ext/lib/multi-tk.rb', line 1615

def to_eval
  @ip_name || ''
end

#transfer_stderr(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3224
3225
3226
3227
3228
# File 'ext/lib/multi-tk.rb', line 3224

def transfer_stderr(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'transfer', src, 'stderr', dist)
  self
end

#transfer_stdin(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3204
3205
3206
3207
3208
# File 'ext/lib/multi-tk.rb', line 3204

def transfer_stdin(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'transfer', src, 'stdin', dist)
  self
end

#transfer_stdio(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3246
3247
3248
3249
3250
3251
3252
# File 'ext/lib/multi-tk.rb', line 3246

def transfer_stdio(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'transfer', src, 'stdin',  dist)
  @interp._invoke('interp', 'transfer', src, 'stdout', dist)
  @interp._invoke('interp', 'transfer', src, 'stderr', dist)
  self
end

#transfer_stdout(dist, src = '') ⇒ Object

Raises:

  • (SecurityError)


3214
3215
3216
3217
3218
# File 'ext/lib/multi-tk.rb', line 3214

def transfer_stdout(dist, src = '')
  raise SecurityError, "no permission to manipulate" unless self.manipulable?
  @interp._invoke('interp', 'transfer', src, 'stdout', dist)
  self
end

#wait_on_mainloop=(bool) ⇒ Object



376
377
378
# File 'ext/lib/multi-tk.rb', line 376

def wait_on_mainloop=(bool)
  @wait_on_mainloop[0] = bool
end

#wait_on_mainloop?Boolean

Returns:

  • (Boolean)


373
374
375
# File 'ext/lib/multi-tk.rb', line 373

def wait_on_mainloop?
  @wait_on_mainloop[0]
end