Module: TkCore

Overview

start Tk which depends on MultiTkIp

Defined Under Namespace

Classes: Tk_OBJECT_TABLE

Constant Summary collapse

INTERP =
TclTkIp.new(name, opts)
WIDGET_DESTROY_HOOK =
'<WIDGET_DESTROY_HOOK>'
EventFlag =
TclTkLib::EventFlag

Constants included from TkComm

TkComm::GET_CONFIGINFO_AS_ARRAY, TkComm::GET_CONFIGINFOwoRES_AS_ARRAY, TkComm::TkExtlibAutoloadModule, TkComm::Tk_CMDTBL, TkComm::Tk_IDs, TkComm::Tk_WINDOWS, TkComm::USE_TCLs_LIST_FUNCTIONS, TkComm::WidgetClassNames

Constants included from TkUtil

TkUtil::None, TkUtil::RELEASE_DATE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TkComm

_at, _callback_entry?, _callback_entry_class?, _curr_cmd_id, _fromUTF8, _genobj_for_tkwidget, _next_cmd_id, _toUTF8, array2tk_list, bind, bind_all, bind_append, bind_append_all, bind_remove, bind_remove_all, bindinfo, bindinfo_all, bool, image_obj, install_cmd, list, num_or_str, number, procedure, simplelist, string, subst, tk_tcl2ruby, uninstall_cmd, window

Methods included from TkUtil

#_conv_args, _conv_args, #_fromUTF8, #_get_eval_enc_str, _get_eval_enc_str, #_get_eval_string, _get_eval_string, _symbolkey2str, #_symbolkey2str, #_toUTF8, bool, #bool, eval_cmd, #hash_kv, hash_kv, install_cmd, num_or_str, #num_or_str, number, #number, string, #string, uninstall_cmd

Methods included from TkEvent

#install_bind, #install_bind_for_event_class

Class Method Details

.callback(*arg) ⇒ Object



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
# File 'lib/tk.rb', line 1318

def TkCore.callback(*arg)
  begin
    if TkCore::INTERP.tk_cmd_tbl.kind_of?(Hash)
      #TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
      normal_ret = false
      ret = catch(:IRB_EXIT) do  # IRB hack
        retval = TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
        normal_ret = true
        retval
      end
      unless normal_ret
        # catch IRB_EXIT
        exit(ret)
      end
      ret
    end
  rescue SystemExit=>e
    exit(e.status)
  rescue Interrupt=>e
    fail(e)
  rescue Exception => e
    begin
      msg = _toUTF8(e.class.inspect) + ': ' + 
            _toUTF8(e.message) + "\n" + 
            "\n---< backtrace of Ruby side >-----\n" + 
            _toUTF8(e.backtrace.join("\n")) + 
            "\n---< backtrace of Tk side >-------"
      msg.instance_variable_set(:@encoding, 'utf-8')
    rescue Exception
      msg = e.class.inspect + ': ' + e.message + "\n" + 
            "\n---< backtrace of Ruby side >-----\n" + 
            e.backtrace.join("\n") + 
            "\n---< backtrace of Tk side >-------"
    end
    # TkCore::INTERP._set_global_var('errorInfo', msg)
    # fail(e)
    fail(e, msg)
  end
end

Instance Method Details

#_tk_call_to_list_core(depth, arg_enc, val_enc, *args) ⇒ Object



1765
1766
1767
1768
1769
1770
1771
1772
1773
# File 'lib/tk.rb', line 1765

def _tk_call_to_list_core(depth, arg_enc, val_enc, *args)
  args = _conv_args([], arg_enc, *args)
  val = _tk_call_core(false, *args)
  if !depth.kind_of?(Integer) || depth == 0
    tk_split_simplelist(val, false, val_enc)
  else
    tk_split_list(val, depth, false, val_enc)
  end
end

#after(ms, cmd = Proc.new) ⇒ Object



1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
# File 'lib/tk.rb', line 1400

def after(ms, cmd=Proc.new)
  crit_bup = Thread.critical
  Thread.critical = true

  myid = _curr_cmd_id
  cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(myid); ret})

  Thread.critical = crit_bup

  tk_call_without_enc("after",ms,cmdid)  # return id
#    return
#    if false #defined? Thread
#      Thread.start do
#       ms = Float(ms)/1000
#       ms = 10 if ms == 0
#       sleep ms/1000
#       cmd.call
#      end
#    else
#      cmdid = install_cmd(cmd)
#      tk_call("after",ms,cmdid)
#    end
end

#after_cancel(afterId) ⇒ Object



1436
1437
1438
# File 'lib/tk.rb', line 1436

def after_cancel(afterId)
  tk_call_without_enc('after','cancel',afterId)
end

#after_idle(cmd = Proc.new) ⇒ Object



1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
# File 'lib/tk.rb', line 1424

def after_idle(cmd=Proc.new)
  crit_bup = Thread.critical
  Thread.critical = true

  myid = _curr_cmd_id
  cmdid = install_cmd(proc{ret = cmd.call;uninstall_cmd(myid); ret})

  Thread.critical = crit_bup

  tk_call_without_enc('after','idle',cmdid)
end

#appname(name = None) ⇒ Object



1472
1473
1474
# File 'lib/tk.rb', line 1472

def appname(name=None)
  tk_call('tk', 'appname', name)
end

#appsend(interp, async, *args) ⇒ Object



1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
# File 'lib/tk.rb', line 1480

def appsend(interp, async, *args)
  if $SAFE >= 4
    fail SecurityError, "cannot send Tk commands at level 4"
  elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
    fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
  end
  if async != true && async != false && async != nil
    args.unshift(async)
    async = false
  end
  if async
    tk_call('send', '-async', '--', interp, *args)
  else
    tk_call('send', '--', interp, *args)
  end
end

#appsend_denyObject



1476
1477
1478
# File 'lib/tk.rb', line 1476

def appsend_deny
  tk_call('rename', 'send', '')
end

#appsend_displayof(interp, win, async, *args) ⇒ Object



1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
# File 'lib/tk.rb', line 1515

def appsend_displayof(interp, win, async, *args)
  if $SAFE >= 4
    fail SecurityError, "cannot send Tk commands at level 4"
  elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
    fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
  end
  win = '.' if win == nil
  if async != true && async != false && async != nil
    args.unshift(async)
    async = false
  end
  if async
    tk_call('send', '-async', '-displayof', win, '--', interp, *args)
  else
    tk_call('send', '-displayor', win, '--', interp, *args)
  end
end

#callback_breakObject



1306
1307
1308
# File 'lib/tk.rb', line 1306

def callback_break
  fail TkCallbackBreak, "Tk callback returns 'break' status"
end

#callback_continueObject



1310
1311
1312
# File 'lib/tk.rb', line 1310

def callback_continue
  fail TkCallbackContinue, "Tk callback returns 'continue' status"
end

#callback_returnObject



1314
1315
1316
# File 'lib/tk.rb', line 1314

def callback_return
  fail TkCallbackReturn, "Tk callback returns 'return' status"
end

#chooseColor(keys = nil) ⇒ Object



1655
1656
1657
# File 'lib/tk.rb', line 1655

def chooseColor(keys = nil)
  tk_call('tk_chooseColor', *hash_kv(keys))
end

#chooseDirectory(keys = nil) ⇒ Object



1659
1660
1661
# File 'lib/tk.rb', line 1659

def chooseDirectory(keys = nil)
  tk_call('tk_chooseDirectory', *hash_kv(keys))
end

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



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

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

#event_generate(win, context, keys = nil) ⇒ Object



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

def event_generate(win, context, keys=nil)
  #win = win.path if win.kind_of?(TkObject)
  if context.kind_of?(TkEvent::Event)
    context.generate(win, ((keys)? keys: {}))
  elsif keys
    tk_call_without_enc('event', 'generate', win, 
                        "<#{tk_event_sequence(context)}>", 
                        *hash_kv(keys, true))
  else
    tk_call_without_enc('event', 'generate', win, 
                        "<#{tk_event_sequence(context)}>")
  end
  nil
end

#get_eventloop_tickObject



1589
1590
1591
# File 'lib/tk.rb', line 1589

def get_eventloop_tick()
  TclTkLib.get_eventloop_tick
end

#get_eventloop_weightObject



1605
1606
1607
# File 'lib/tk.rb', line 1605

def get_eventloop_weight()
  TclTkLib.get_eventloop_weight
end

#get_no_event_waitObject



1597
1598
1599
# File 'lib/tk.rb', line 1597

def get_no_event_wait()
  TclTkLib.get_no_eventloop_wait
end

#getMultipleOpenFile(keys = nil) ⇒ Object



1644
1645
1646
# File 'lib/tk.rb', line 1644

def getMultipleOpenFile(keys = nil)
  simplelist(tk_call('tk_getOpenFile', '-multiple', '1', *hash_kv(keys)))
end

#getMultipleSaveFile(keys = nil) ⇒ Object



1651
1652
1653
# File 'lib/tk.rb', line 1651

def getMultipleSaveFile(keys = nil)
  simplelist(tk_call('tk_getSaveFile', '-multiple', '1', *hash_kv(keys)))
end

#getOpenFile(keys = nil) ⇒ Object



1641
1642
1643
# File 'lib/tk.rb', line 1641

def getOpenFile(keys = nil)
  tk_call('tk_getOpenFile', *hash_kv(keys))
end

#getSaveFile(keys = nil) ⇒ Object



1648
1649
1650
# File 'lib/tk.rb', line 1648

def getSaveFile(keys = nil)
  tk_call('tk_getSaveFile', *hash_kv(keys))
end

#inactiveObject



1459
1460
1461
# File 'lib/tk.rb', line 1459

def inactive
  Integer(tk_call_without_enc('tk', 'inactive'))
end

#inactive_displayof(win) ⇒ Object



1462
1463
1464
# File 'lib/tk.rb', line 1462

def inactive_displayof(win)
  Integer(tk_call_without_enc('tk', 'inactive', '-displayof', win))
end

#info(*args) ⇒ Object



1552
1553
1554
# File 'lib/tk.rb', line 1552

def info(*args)
  tk_call('info', *args)
end

#ip_eval(cmd_string) ⇒ Object



1679
1680
1681
# File 'lib/tk.rb', line 1679

def ip_eval(cmd_string)
  _ip_eval_core(nil, cmd_string)
end

#ip_eval_with_enc(cmd_string) ⇒ Object



1687
1688
1689
# File 'lib/tk.rb', line 1687

def ip_eval_with_enc(cmd_string)
  _ip_eval_core(true, cmd_string)
end

#ip_eval_without_enc(cmd_string) ⇒ Object



1683
1684
1685
# File 'lib/tk.rb', line 1683

def ip_eval_without_enc(cmd_string)
  _ip_eval_core(false, cmd_string)
end

#ip_invoke(*args) ⇒ Object



1707
1708
1709
# File 'lib/tk.rb', line 1707

def ip_invoke(*args)
  _ip_invoke_core(nil, *args)
end

#ip_invoke_with_enc(*args) ⇒ Object



1715
1716
1717
# File 'lib/tk.rb', line 1715

def ip_invoke_with_enc(*args)
  _ip_invoke_core(true, *args)
end

#ip_invoke_without_enc(*args) ⇒ Object



1711
1712
1713
# File 'lib/tk.rb', line 1711

def ip_invoke_without_enc(*args)
  _ip_invoke_core(false, *args)
end

#is_mainloop?Boolean

Returns:

  • (Boolean)


1572
1573
1574
# File 'lib/tk.rb', line 1572

def is_mainloop?
  TclTkLib.mainloop_thread? == true
end

#load_cmd_on_ip(tk_cmd) ⇒ Object

def TkCore.callback(arg_str)

# arg = tk_split_list(arg_str)
arg = tk_split_simplelist(arg_str)
#_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
#_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift], 
#                        *arg))
# TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
begin
  TkCore::INTERP.tk_cmd_tbl[arg.shift].call(*arg)
rescue Exception => e
  raise(e, e.class.inspect + ': ' + e.message + "\n" + 
           "\n---< backtrace of Ruby side >-----\n" + 
           e.backtrace.join("\n") + 
           "\n---< backtrace of Tk side >-------")
end

#=begin # cb_obj = TkCore::INTERP.tk_cmd_tbl # unless $DEBUG # cb_obj.call(*arg) # else # begin # raise ‘check backtrace’ # rescue # # ignore backtrace before ‘callback’ # pos = -($!.backtrace.size) # end # begin # cb_obj.call(*arg) # rescue # trace = $!.backtrace # raise $!, “n#0: #TkCore.$!$!.message (#TkCore.$!$!.class)n” + # “tfrom #.join(”ntfrom “)” # end # end #=end

end


1396
1397
1398
# File 'lib/tk.rb', line 1396

def load_cmd_on_ip(tk_cmd)
  bool(tk_call('auto_load', tk_cmd))
end

#mainloop(check_root = true) ⇒ Object



1556
1557
1558
# File 'lib/tk.rb', line 1556

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

#mainloop_exist?Boolean

Returns:

  • (Boolean)


1568
1569
1570
# File 'lib/tk.rb', line 1568

def mainloop_exist?
  TclTkLib.mainloop_thread? != nil
end

#mainloop_thread?Boolean

Returns:

  • (Boolean)


1560
1561
1562
1563
1564
1565
1566
# File 'lib/tk.rb', line 1560

def mainloop_thread?
  # true  : current thread is mainloop
  # nil   : there is no mainloop
  # false : mainloop is running on the other thread
  #         ( At then, it is dangerous to call Tk interpreter directly. )
  TclTkLib.mainloop_thread?
end

#mainloop_watchdog(check_root = true) ⇒ Object



1576
1577
1578
1579
# File 'lib/tk.rb', line 1576

def mainloop_watchdog(check_root = true)
  # watchdog restarts mainloop when mainloop is dead
  TclTkLib.mainloop_watchdog(check_root)
end

#messageBox(keys) ⇒ Object



1637
1638
1639
# File 'lib/tk.rb', line 1637

def messageBox(keys)
  tk_call('tk_messageBox', *hash_kv(keys))
end

#rb_appsend(interp, async, *args) ⇒ Object



1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
# File 'lib/tk.rb', line 1497

def rb_appsend(interp, async, *args)
  if $SAFE >= 4
    fail SecurityError, "cannot send Ruby commands at level 4"
  elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
    fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
  end
  if async != true && async != false && async != nil
    args.unshift(async)
    async = false
  end
  #args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')}
  args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"\\]/, '\\\\\&')}
  # args.push(').to_s"')
  # appsend(interp, async, 'ruby "(', *args)
  args.push('}.call)"')
  appsend(interp, async, 'ruby "TkComm._get_eval_string(proc{', *args)
end

#rb_appsend_displayof(interp, win, async, *args) ⇒ Object



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
# File 'lib/tk.rb', line 1533

def rb_appsend_displayof(interp, win, async, *args)
  if $SAFE >= 4
    fail SecurityError, "cannot send Ruby commands at level 4"
  elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
    fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
  end
  win = '.' if win == nil
  if async != true && async != false && async != nil
    args.unshift(async)
    async = false
  end
  #args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"]/, '\\\\\&')}
  args = args.collect!{|c| _get_eval_string(c).gsub(/[\[\]$"\\]/, '\\\\\&')}
  # args.push(').to_s"')
  # appsend_displayof(interp, win, async, 'ruby "(', *args)
  args.push('}.call)"')
  appsend(interp, win, async, 'ruby "TkComm._get_eval_string(proc{', *args)
end

#reset_inactiveObject



1465
1466
1467
# File 'lib/tk.rb', line 1465

def reset_inactive
  tk_call_without_enc('tk', 'inactive', 'reset')
end

#reset_inactive_displayof(win) ⇒ Object



1468
1469
1470
# File 'lib/tk.rb', line 1468

def reset_inactive_displayof(win)
  tk_call_without_enc('tk', 'inactive', '-displayof', win, 'reset')
end

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



1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
# File 'lib/tk.rb', line 1609

def restart(app_name = nil, keys = {})
  TkCore::INTERP.init_ip_internal

  tk_call('set', 'argv0', app_name) if app_name
  if keys.kind_of?(Hash)
    # tk_call('set', 'argc', keys.size * 2)
    tk_call('set', 'argv', hash_kv(keys).join(' '))
  end

  INTERP.restart
  nil
end

#scaling(scale = nil) ⇒ Object



1444
1445
1446
1447
1448
1449
1450
# File 'lib/tk.rb', line 1444

def scaling(scale=nil)
  if scale
    tk_call_without_enc('tk', 'scaling', scale)
  else
    Float(number(tk_call_without_enc('tk', 'scaling')))
  end
end

#scaling_displayof(win, scale = nil) ⇒ Object



1451
1452
1453
1454
1455
1456
1457
# File 'lib/tk.rb', line 1451

def scaling_displayof(win, scale=nil)
  if scale
    tk_call_without_enc('tk', 'scaling', '-displayof', win, scale)
  else
    Float(number(tk_call_without_enc('tk', '-displayof', win, 'scaling')))
  end
end

#set_eventloop_tick(timer_tick) ⇒ Object



1585
1586
1587
# File 'lib/tk.rb', line 1585

def set_eventloop_tick(timer_tick)
  TclTkLib.set_eventloop_tick(timer_tick)
end

#set_eventloop_weight(loop_max, no_event_tick) ⇒ Object



1601
1602
1603
# File 'lib/tk.rb', line 1601

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

#set_no_event_wait(wait) ⇒ Object



1593
1594
1595
# File 'lib/tk.rb', line 1593

def set_no_event_wait(wait)
  TclTkLib.set_no_even_wait(wait)
end

#tk_call(*args) ⇒ Object



1753
1754
1755
# File 'lib/tk.rb', line 1753

def tk_call(*args)
  _tk_call_core(nil, *args)
end

#tk_call_to_list(*args) ⇒ Object

private :_tk_call_to_list_core



1776
1777
1778
# File 'lib/tk.rb', line 1776

def tk_call_to_list(*args)
  _tk_call_to_list_core(-1, nil, true, *args)
end

#tk_call_to_list_with_enc(*args) ⇒ Object



1784
1785
1786
# File 'lib/tk.rb', line 1784

def tk_call_to_list_with_enc(*args)
  _tk_call_to_list_core(-1, true, true, *args)
end

#tk_call_to_list_without_enc(*args) ⇒ Object



1780
1781
1782
# File 'lib/tk.rb', line 1780

def tk_call_to_list_without_enc(*args)
  _tk_call_to_list_core(-1, false, false, *args)
end

#tk_call_to_simplelist(*args) ⇒ Object



1788
1789
1790
# File 'lib/tk.rb', line 1788

def tk_call_to_simplelist(*args)
  _tk_call_to_list_core(0, nil, true, *args)
end

#tk_call_to_simplelist_with_enc(*args) ⇒ Object



1796
1797
1798
# File 'lib/tk.rb', line 1796

def tk_call_to_simplelist_with_enc(*args)
  _tk_call_to_list_core(0, true, true, *args)
end

#tk_call_to_simplelist_without_enc(*args) ⇒ Object



1792
1793
1794
# File 'lib/tk.rb', line 1792

def tk_call_to_simplelist_without_enc(*args)
  _tk_call_to_list_core(0, false, false, *args)
end

#tk_call_with_enc(*args) ⇒ Object



1761
1762
1763
# File 'lib/tk.rb', line 1761

def tk_call_with_enc(*args)
  _tk_call_core(true, *args)
end

#tk_call_without_enc(*args) ⇒ Object



1757
1758
1759
# File 'lib/tk.rb', line 1757

def tk_call_without_enc(*args)
  _tk_call_core(false, *args)
end

#windowingsystemObject



1440
1441
1442
# File 'lib/tk.rb', line 1440

def windowingsystem
  tk_call_without_enc('tk', 'windowingsystem')
end