module Tk

string with Tcl's encoding

dummy methods

freeze core modules

TclTkLib.freeze TclTkIp.freeze TkUtil.freeze TkKernel.freeze TkComm.freeze TkComm::Event.freeze TkCore.freeze Tk.freeze

autoload

geometry manager

classes on Tk module

sub-module of Tk

toplevel classes/modules (switchable)

methods to control default widget set

string with Tcl's encoding

ttk_selector

toplevel classes/modules

autoload

tkextlib/tcllib/tablelist_core.rb

                            by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

* Part of tcllib extension
* This file is required by 'tkextlib/tcllib/tablelist.rb' or
  'tkextlib/tcllib/tablelist_tile.rb'.

define dummy methods

version 0.4 or former

version 0.5 – version 0.6

version 0.8 or later

Ttk package merged Tcl/Tk core (Tcl/Tk 8.5+)

autoload

release date of tkextlib

autoload

create module/class

create module/class

create module/class

Constants

AUTO_PATH
Checkbutton
CloneMenu
Fontchooser
JAPANIZED_TK
LIBRARY_PATH
Labelframe
OptionMenuButton
PACKAGE_PATH
Panedwindow
RELEASE_DATE
Radiobutton
TCL_LIBRARY_PATH
TCL_MAJOR_VERSION
TCL_MINOR_VERSION
TCL_PACKAGE_PATH

begin

AUTO_OLDPATH = tk_split_simplelist(INTERP._invoke('set', 'auto_oldpath'))
AUTO_OLDPATH.each{|s| s.freeze}
AUTO_OLDPATH.freeze

end

TCL_PATCHLEVEL
TCL_PRECISION
TCL_VERSION
TK_MAJOR_VERSION
TK_MINOR_VERSION
TK_PATCHLEVEL
TK_VERSION
Tkextlib_RELEASE_DATE
TreeCtrl_Widget
X_Scrollable
Y_Scrollable

Public Class Methods

BinaryString(str) click to toggle source
# File lib/tk/autoload.rb, line 115
def Tk.BinaryString(str); Tk::BinaryString.new(str); end
EncodedString(str, enc = nil) click to toggle source
# File lib/tk/autoload.rb, line 112
def Tk.EncodedString(str, enc = nil); Tk::EncodedString.new(str, enc); end
UTF8_String(str) click to toggle source
# File lib/tk/autoload.rb, line 118
def Tk.UTF8_String(str); Tk::UTF8_String.new(str); end
__create_widget_set__(new_set, src_set={}) click to toggle source
# File lib/tk/autoload.rb, line 723
def __create_widget_set__(new_set, src_set={})
  new_set = new_set.to_sym
  if @TOPLEVEL_ALIAS_TABLE[new_set]
    fail RuntimeError, "A widget-set #{new_set.inspect} is already exist."
  end
  if src_set.kind_of?(Symbol)
    # new_set is an alias name of existed widget set.
    @TOPLEVEL_ALIAS_TABLE[new_set] = @TOPLEVEL_ALIAS_TABLE[src_set]
  else
    @TOPLEVEL_ALIAS_TABLE[new_set] = {}
    src_set.each{|sym, obj| set_topalias(new_set, obj, sym.to_sym) }
  end
end
__disable_toplevel_control__(*symbols) click to toggle source
# File lib/tk/autoload.rb, line 719
def __disable_toplevel_control__(*symbols)
  symbols.each{|sym| @TOPLEVEL_ALIAS_OWNER[sym.to_sym] = false}
end
__import_toplevel_aliases__(target, *symbols) click to toggle source
# File lib/tk/autoload.rb, line 670
def __import_toplevel_aliases__(target, *symbols)
  current = @current_default_widget_set
  symbols.each{|sym|
    sym = sym.to_sym
    if (obj = @TOPLEVEL_ALIAS_TABLE[target][sym]).nil?
      # remove
      @TOPLEVEL_ALIAS_TABLE[current].delete(sym)
      @TOPLEVEL_ALIAS_OWNER.delete(sym)
      Tk::TOPLEVEL_ALIASES.module_eval{remove_const sym} if topalias_defined?(sym)
      Object.class_eval{remove_const sym} if topobj_defined?(sym)

    elsif obj == false
      # remove, but OWNER[sym] <- false and not treat Object::sym
      @TOPLEVEL_ALIAS_TABLE[current].delete(sym)
      @TOPLEVEL_ALIAS_OWNER[sym] = false
      Tk::TOPLEVEL_ALIASES.module_eval{remove_const sym} if topalias_defined?(sym)

    elsif @TOPLEVEL_ALIAS_OWNER[sym] == false
      # Object::sym is out of control. --> not change
      # Keep OWNER[sym].
      @TOPLEVEL_ALIAS_TABLE[current][sym] = obj
      replace_topalias(sym, obj)

    else
      # new definition under control
      @TOPLEVEL_ALIAS_OWNER[sym] = current
      @TOPLEVEL_ALIAS_TABLE[current][sym] = obj
      replace_topalias(sym, obj)
      replace_topobj(sym, obj)
    end
  }
end
__regist_toplevel_aliases__(target, obj, *symbols) click to toggle source
# File lib/tk/autoload.rb, line 437
def __regist_toplevel_aliases__(target, obj, *symbols)
  # initial regist
  @TOPLEVEL_ALIAS_TABLE[target = target.to_sym] ||= {}
  symbols.each{|sym|
    @TOPLEVEL_ALIAS_TABLE[target][sym = sym.to_sym] = obj
    if !topalias_defined?(sym) || target == @current_default_widget_set
      @TOPLEVEL_ALIAS_OWNER[sym] = target
      replace_topalias(sym, obj)
      replace_topobj(sym, obj) unless obj.kind_of?(String) # NOT autoload
    end
  }
end
__remove_toplevel_aliases__(*symbols) click to toggle source
# File lib/tk/autoload.rb, line 703
def __remove_toplevel_aliases__(*symbols)
  # remove toplevel aliases of current widget set
  current = @current_default_widget_set
  symbols.each{|sym|
    sym = sym.to_sym
    @TOPLEVEL_ALIAS_TABLE[current].delete(sym)
    @TOPLEVEL_ALIAS_OWNER.delete(sym)
    Tk::TOPLEVEL_ALIASES.module_eval{remove_const sym} if topalias_defined?(sym)
    Object.class_eval{remove_const sym} if topobj_defined?(sym)
  }
end
__reset_toplevel_owner__(*symbols) click to toggle source
# File lib/tk/autoload.rb, line 715
def __reset_toplevel_owner__(*symbols)
  symbols.each{|sym| @TOPLEVEL_ALIAS_OWNER.delete(sym.to_sym)}
end
__set_loaded_toplevel_aliases__(autopath, target, obj, *symbols) click to toggle source
# File lib/tk/autoload.rb, line 587
def __set_loaded_toplevel_aliases__(autopath, target, obj, *symbols)
  # autopath is an autoload file
  # Currently, this method doesn't support that autoload loads
  # different toplevels between <basename>.rb and <basename>.so extension.
  shortpath = (autopath =~ /^(.*)(.rb|.so)$/)? $1: autopath
  target = target.to_sym
  symbols.map!{|sym| sym.to_sym}

  symbols.each{|sym| regist_sym_for_loaded_file(shortpath, obj, sym) }
  symbols.each{|sym| set_topalias(target, obj, sym)}
end
__set_toplevel_aliases__(target, obj, *symbols) click to toggle source
# File lib/tk/autoload.rb, line 580
def __set_toplevel_aliases__(target, obj, *symbols)
  # obj is a kind of String : define autoload path
  #                  Class  : use the class object
  target = target.to_sym
  symbols.each{|sym| set_topalias(target, obj, sym.to_sym)}
end
__toplevel_alias_setup_proc__(*target_list, &cmd) click to toggle source
# File lib/tk/autoload.rb, line 370
def __toplevel_alias_setup_proc__(*target_list, &cmd)
  target_list.each{|target| @TOPLEVEL_ALIAS_SETUP_PROC[target.to_sym] = cmd}
end
add_kinsoku(chars, mode='both') click to toggle source
# File lib/tk.rb, line 2529
def Tk.add_kinsoku(chars, mode='both')
  begin
    if /^8\.*/ === TK_VERSION  && JAPANIZED_TK
      tk_split_simplelist(tk_call('kinsoku', 'add', mode,
                                  *(chars.split(''))))
    else
      []
    end
  rescue
    []
  end
end
bell(nice = false) click to toggle source
# File lib/tk.rb, line 2357
def Tk.bell(nice = false)
  if nice
    tk_call_without_enc('bell', '-nice')
  else
    tk_call_without_enc('bell')
  end
  nil
end
bell_on_display(win, nice = false) click to toggle source
# File lib/tk.rb, line 2366
def Tk.bell_on_display(win, nice = false)
  if nice
    tk_call_without_enc('bell', '-displayof', win, '-nice')
  else
    tk_call_without_enc('bell', '-displayof', win)
  end
  nil
end
const_missing(sym) click to toggle source
# File lib/tk.rb, line 2183
def Tk.const_missing(sym)
  case(sym)
  when :TCL_LIBRARY
    INTERP._invoke_without_enc('global', 'tcl_library')
    INTERP._invoke("set", "tcl_library").freeze

  when :TK_LIBRARY
    INTERP._invoke_without_enc('global', 'tk_library')
    INTERP._invoke("set", "tk_library").freeze

  when :LIBRARY
    INTERP._invoke("info", "library").freeze

  #when :PKG_PATH, :PACKAGE_PATH, :TCL_PACKAGE_PATH
  #  INTERP._invoke_without_enc('global', 'tcl_pkgPath')
  #  tk_split_simplelist(INTERP._invoke('set', 'tcl_pkgPath'))

  #when :LIB_PATH, :LIBRARY_PATH, :TCL_LIBRARY_PATH
  #  INTERP._invoke_without_enc('global', 'tcl_libPath')
  #  tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath'))

  when :PLATFORM, :TCL_PLATFORM
    INTERP._invoke_without_enc('global', 'tcl_platform')
    Hash[*tk_split_simplelist(INTERP._invoke_without_enc('array', 'get',
                                                         'tcl_platform'))]

  when :ENV
    INTERP._invoke_without_enc('global', 'env')
    Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'env'))]

  #when :AUTO_PATH   #<===
  #  tk_split_simplelist(INTERP._invoke('set', 'auto_path'))

  #when :AUTO_OLDPATH
  #  tk_split_simplelist(INTERP._invoke('set', 'auto_oldpath'))

  when :AUTO_INDEX
    INTERP._invoke_without_enc('global', 'auto_index')
    Hash[*tk_split_simplelist(INTERP._invoke('array', 'get', 'auto_index'))]

  when :PRIV, :PRIVATE, :TK_PRIV
    priv = {}
    if INTERP._invoke_without_enc('info', 'vars', 'tk::Priv') != ""
      var_nam = 'tk::Priv'
    else
      var_nam = 'tkPriv'
    end
    INTERP._invoke_without_enc('global', var_nam)
    Hash[*tk_split_simplelist(INTERP._invoke('array', 'get',
                                             var_nam))].each{|k,v|
      k.freeze
      case v
      when /^-?\d+$/
        priv[k] = v.to_i
      when /^-?\d+\.?\d*(e[-+]?\d+)?$/
        priv[k] = v.to_f
      else
        priv[k] = v.freeze
      end
    }
    priv

  else
    raise NameError, 'uninitialized constant Tk::' + sym.id2name
  end
end
current_grabs(win = nil) click to toggle source
# File lib/tk.rb, line 2481
def Tk.current_grabs(win = nil)
  if win
    window(tk_call_without_enc('grab', 'current', win))
  else
    tk_split_list(tk_call_without_enc('grab', 'current'))
  end
end
cursor_display(parent=None) click to toggle source
# File lib/tkextlib/tcllib/cursor.rb, line 47
def self.cursor_display(parent=None)
  # Pops up a dialog with a listbox containing all the cursor names.
  # Selecting a cursor name will display it in that dialog.
  # This is simply for viewing any available cursors on the platform .
  #tk_call_without_enc('::cursor::display', parent)
  Tk::Tcllib::Cursor.cursor_display(parent)
end
default_widget_set() click to toggle source
# File lib/tk/autoload.rb, line 343
def default_widget_set
  @current_default_widget_set
end
default_widget_set=(target) click to toggle source
# File lib/tk/autoload.rb, line 347
def default_widget_set=(target)
  target = target.to_sym
  return target if target == @current_default_widget_set

  if (cmd = @TOPLEVEL_ALIAS_SETUP_PROC[target])
    cmd.call(target)
  end

  _replace_toplevel_aliases(target)
end
delete_kinsoku(chars, mode='both') click to toggle source
# File lib/tk.rb, line 2541
def Tk.delete_kinsoku(chars, mode='both')
  begin
    if /^8\.*/ === TK_VERSION  && JAPANIZED_TK
      tk_split_simplelist(tk_call('kinsoku', 'delete', mode,
                          *(chars.split(''))))
    end
  rescue
  end
end
destroy(*wins) click to toggle source
# File lib/tk.rb, line 2375
def Tk.destroy(*wins)
  #tk_call_without_enc('destroy', *wins)
  tk_call_without_enc('destroy', *(wins.collect{|win|
                                     if win.kind_of?(TkWindow)
                                       win.epath
                                     else
                                       win
                                     end
                                   }))
end
errorCode() click to toggle source
# File lib/tk.rb, line 2255
def Tk.errorCode
  INTERP._invoke_without_enc('global', 'errorCode')
  code = tk_split_simplelist(INTERP._invoke_without_enc('set', 'errorCode'))
  case code[0]
  when 'CHILDKILLED', 'CHILDSTATUS', 'CHILDSUSP'
    begin
      pid = Integer(code[1])
      code[1] = pid
    rescue
    end
  end
  code
end
errorInfo() click to toggle source
# File lib/tk.rb, line 2250
def Tk.errorInfo
  INTERP._invoke_without_enc('global', 'errorInfo')
  INTERP._invoke_without_enc('set', 'errorInfo')
end
exit() click to toggle source
# File lib/tk.rb, line 2386
def Tk.exit
  TkCore::INTERP.has_mainwindow? && tk_call_without_enc('destroy', '.')
end
focus(display=nil) click to toggle source
# File lib/tk.rb, line 2489
def Tk.focus(display=nil)
  if display == nil
    window(tk_call_without_enc('focus'))
  else
    window(tk_call_without_enc('focus', '-displayof', display))
  end
end
focus_lastfor(win) click to toggle source
# File lib/tk.rb, line 2505
def Tk.focus_lastfor(win)
  window(tk_call_without_enc('focus', '-lastfor', win))
end
focus_next(win) click to toggle source
# File lib/tk.rb, line 2509
def Tk.focus_next(win)
  TkManageFocus.next(win)
end
focus_prev(win) click to toggle source
# File lib/tk.rb, line 2513
def Tk.focus_prev(win)
  TkManageFocus.prev(win)
end
focus_to(win, force=false) click to toggle source
# File lib/tk.rb, line 2497
def Tk.focus_to(win, force=false)
  if force
    tk_call_without_enc('focus', '-force', win)
  else
    tk_call_without_enc('focus', win)
  end
end
fromUTF8(str, encoding = nil) click to toggle source
# File lib/tk.rb, line 2555
def Tk.fromUTF8(str, encoding = nil)
  _fromUTF8(str, encoding)
end
grid(*args) click to toggle source
# File lib/tk.rb, line 2421
def Tk.grid(*args)
  TkGrid.configure(*args)
end
grid_forget(*args) click to toggle source
# File lib/tk.rb, line 2424
def Tk.grid_forget(*args)
  TkGrid.forget(*args)
end
has_mainwindow?() click to toggle source
# File lib/tk.rb, line 2269
def Tk.has_mainwindow?
  INTERP.has_mainwindow?
end
load_tcllibrary(file, pkg_name=None, interp=None) click to toggle source
# File lib/tk.rb, line 2286
def Tk.load_tcllibrary(file, pkg_name=None, interp=None)
  tk_call('load', file, pkg_name, interp)
end
load_tclscript(file, enc=nil) click to toggle source
# File lib/tk.rb, line 2277
def Tk.load_tclscript(file, enc=nil)
  if enc
    # TCL_VERSION >= 8.5
    tk_call('source', '-encoding', enc, file)
  else
    tk_call('source', file)
  end
end
load_tclscript_rsrc(resource_name, file=None) click to toggle source
# File lib/tk/macpkg.rb, line 13
def Tk.load_tclscript_rsrc(resource_name, file=None)
  # Mac only
  tk_call('source', '-rsrc', resource_name, file)
end
load_tclscript_rsrcid(resource_id, file=None) click to toggle source
# File lib/tk/macpkg.rb, line 18
def Tk.load_tclscript_rsrcid(resource_id, file=None)
  # Mac only
  tk_call('source', '-rsrcid', resource_id, file)
end
lower_window(win, below=None) click to toggle source
# File lib/tk.rb, line 2472
def Tk.lower_window(win, below=None)
  tk_call('lower', _epath(win), _epath(below))
  nil
end
pack(*args) click to toggle source
# File lib/tk.rb, line 2411
def Tk.pack(*args)
  TkPack.configure(*args)
end
pack_forget(*args) click to toggle source
# File lib/tk.rb, line 2414
def Tk.pack_forget(*args)
  TkPack.forget(*args)
end
pkgconfig_get(mod, key) click to toggle source
# File lib/tk.rb, line 2320
def Tk.pkgconfig_get(mod, key)
  # Tk8.5 feature
  if mod.kind_of?(Module)
    if mod.respond_to?(:package_name)
      pkgname = mod.package_name
    else
      fail NotImplementedError, 'may not be a module for a Tcl extension'
    end
  else
    pkgname = mod.to_s
  end

  pkgname = '::' << pkgname unless pkgname =~ /^::/

  tk_call(pkgname + '::pkgconfig', 'get', key)
end
pkgconfig_list(mod) click to toggle source
# File lib/tk.rb, line 2301
def Tk.pkgconfig_list(mod)
  # Tk8.5 feature
  if mod.kind_of?(Module)
    if mod.respond_to?(:package_name)
      pkgname = mod.package_name
    elsif mod.const_defined?(:PACKAGE_NAME)
      pkgname = mod::PACKAGE_NAME
    else
      fail NotImplementedError, 'may not be a module for a Tcl extension'
    end
  else
    pkgname = mod.to_s
  end

  pkgname = '::' << pkgname unless pkgname =~ /^::/

  tk_split_list(tk_call(pkgname + '::pkgconfig', 'list'))
end
place(*args) click to toggle source
# File lib/tk.rb, line 2431
def Tk.place(*args)
  TkPlace.configure(*args)
end
place_forget(*args) click to toggle source
# File lib/tk.rb, line 2434
def Tk.place_forget(*args)
  TkPlace.forget(*args)
end
raise_window(win, above=None) click to toggle source
# File lib/tk.rb, line 2476
def Tk.raise_window(win, above=None)
  tk_call('raise', _epath(win), _epath(above))
  nil
end
show_kinsoku(mode='both') click to toggle source
# File lib/tk.rb, line 2521
def Tk.show_kinsoku(mode='both')
  begin
    if /^8\.*/ === TK_VERSION  && JAPANIZED_TK
      tk_split_simplelist(tk_call('kinsoku', 'show', mode))
    end
  rescue
  end
end
sleep(ms = nil, id = nil) click to toggle source
# File lib/tk.rb, line 2392
def Tk.sleep(ms = nil, id = nil)
  if id
    var = (id.kind_of?(TkVariable))? id: TkVarAccess.new(id.to_s)
  else
    var = TkVariable.new
  end

  var.value = tk_call_without_enc('after', ms, proc{ var.value = 0 }) if ms
  var.thread_wait
  ms
end
strictMotif(mode=None) click to toggle source
# File lib/tk.rb, line 2517
def Tk.strictMotif(mode=None)
  bool(tk_call_without_enc('set', 'tk_strictMotif', mode))
end
subst_tk_backslash(str) click to toggle source
# File lib/tk.rb, line 2567
def Tk.subst_tk_backslash(str)
  Tk::EncodedString.subst_tk_backslash(str)
end
subst_utf_backslash(str) click to toggle source
# File lib/tk.rb, line 2564
def Tk.subst_utf_backslash(str)
  Tk::EncodedString.subst_utf_backslash(str)
end
tcl_pkgconfig_get(key) click to toggle source
# File lib/tk.rb, line 2342
def Tk.tcl_pkgconfig_get(key)
  # Tk8.5 feature
  Tk.pkgconfig_get('::tcl', key)
end
tcl_pkgconfig_list() click to toggle source
# File lib/tk.rb, line 2337
def Tk.tcl_pkgconfig_list
  # Tk8.5 feature
  Tk.pkgconfig_list('::tcl')
end
thread_update(idle=nil) click to toggle source
NOTE

If no eventloop-thread is running, “thread_update” method is same to “update” method. Else, “thread_update” method waits to complete idletask operation on the eventloop-thread.

# File lib/tk.rb, line 2461
def Tk.thread_update(idle=nil)
  if idle
    tk_call_without_enc('thread_update', 'idletasks')
  else
    tk_call_without_enc('thread_update')
  end
end
thread_update_idletasks() click to toggle source
# File lib/tk.rb, line 2468
def Tk.thread_update_idletasks
  thread_update(true)
end
tk_pkgconfig_get(key) click to toggle source
# File lib/tk.rb, line 2352
def Tk.tk_pkgconfig_get(key)
  # Tk8.5 feature
  Tk.pkgconfig_get('::tk', key)
end
tk_pkgconfig_list() click to toggle source
# File lib/tk.rb, line 2347
def Tk.tk_pkgconfig_list
  # Tk8.5 feature
  Tk.pkgconfig_list('::tk')
end
toUTF8(str, encoding = nil) click to toggle source
# File lib/tk.rb, line 2551
def Tk.toUTF8(str, encoding = nil)
  _toUTF8(str, encoding)
end
to_backslash_sequence(str) click to toggle source
# File lib/tk.rb, line 2576
def Tk.to_backslash_sequence(str)
  Tk::EncodedString.to_backslash_sequence(str)
end
toplevel_aliases_on_widget_set(widget_set) click to toggle source
# File lib/tk/autoload.rb, line 362
def toplevel_aliases_on_widget_set(widget_set)
  if (tbl = @TOPLEVEL_ALIAS_TABLE[widget_set.to_sym])
    tbl.collect{|k, v| (v.nil?)? nil: k}.compact
  else
    fail ArgumentError, "unknown widget_set #{widget_set.to_sym.inspect}"
  end
end
ungrid(*args) click to toggle source
# File lib/tk.rb, line 2427
def Tk.ungrid(*args)
  TkGrid.forget(*args)
end
unload_tcllibrary(*args) click to toggle source
# File lib/tk.rb, line 2290
def Tk.unload_tcllibrary(*args)
  if args[-1].kind_of?(Hash)
    keys = _symbolkey2str(args.pop)
    nocomp = (keys['nocomplain'])? '-nocomplain': None
    keeplib = (keys['keeplibrary'])? '-keeplibrary': None
    tk_call('unload', nocomp, keeplib, '--', *args)
  else
    tk_call('unload', *args)
  end
end
unpack(*args) click to toggle source
# File lib/tk.rb, line 2417
def Tk.unpack(*args)
  TkPack.forget(*args)
end
unplace(*args) click to toggle source
# File lib/tk.rb, line 2437
def Tk.unplace(*args)
  TkPlace.forget(*args)
end
update(idle=nil) click to toggle source
# File lib/tk.rb, line 2441
def Tk.update(idle=nil)
  if idle
    tk_call_without_enc('update', 'idletasks')
  else
    tk_call_without_enc('update')
  end
end
update_idletasks() click to toggle source
# File lib/tk.rb, line 2448
def Tk.update_idletasks
  update(true)
end
utf_to_backslash(str) click to toggle source
# File lib/tk.rb, line 2573
def Tk.utf_to_backslash(str)
  Tk::EncodedString.utf_to_backslash_sequence(str)
end
utf_to_backslash_sequence(str) click to toggle source
# File lib/tk.rb, line 2570
def Tk.utf_to_backslash_sequence(str)
  Tk::EncodedString.utf_to_backslash_sequence(str)
end
wakeup(id) click to toggle source
# File lib/tk.rb, line 2404
def Tk.wakeup(id)
  ((id.kind_of?(TkVariable))? id: TkVarAccess.new(id.to_s)).value = 0
  nil
end
widget_set_symbols() click to toggle source
# File lib/tk/autoload.rb, line 358
def widget_set_symbols
  @TOPLEVEL_ALIAS_TABLE.keys
end

Private Class Methods

_replace_toplevel_aliases(target) click to toggle source
# File lib/tk/autoload.rb, line 644
def _replace_toplevel_aliases(target)
  # backup
  @TOPLEVEL_ALIAS_TABLE[target].each_key{|sym|
    backup_current_topdef(sym)
  }

  # replace
  @TOPLEVEL_ALIAS_TABLE[target].each_key{|sym|
    next if (obj = @TOPLEVEL_ALIAS_TABLE[target][sym]).nil?
    if @TOPLEVEL_ALIAS_OWNER[sym] == false
      # Object::sym is out of control. --> not change
      # Keep OWNER[sym].
      replace_topalias(sym, obj)
    else
      # New definition
      @TOPLEVEL_ALIAS_OWNER[sym] = target
      replace_topalias(sym, obj)
      replace_topobj(sym, obj)
    end
  }

  # change default_widget_set
  @current_default_widget_set = target
end
backup_current_topdef(sym) click to toggle source
# File lib/tk/autoload.rb, line 599
def backup_current_topdef(sym)
  return if (current = @current_default_widget_set).nil?

  case @TOPLEVEL_ALIAS_OWNER[sym]
  when false
    # Object::sym is out of control.
    if (cur_alias = topalias_defined?(sym)) && ! cur_alias.kind_of?(String)
      @TOPLEVEL_ALIAS_TABLE[current][sym] = cur_alias
    end

  when current
    if cur_obj = topobj_defined?(sym)
      if ! cur_obj.kind_of?(String) && (cur_alias = topalias_defined?(sym))
        if cur_alias.kind_of?(String)
          # Maybe, user replaced Object::sym.
          # Make Object::sym out of control.
          @TOPLEVEL_ALIAS_OWNER[sym] = false
        elsif cur_obj == cur_alias
          # Possibly, defined normally. Backup it
          @TOPLEVEL_ALIAS_TABLE[current][sym] = cur_alias
        else
          # Maybe, user replaced Object::sym.
          # Make Object::sym out of control.
          @TOPLEVEL_ALIAS_OWNER[sym] = false
        end
      end
    else
      # Maybe, user replaced Object::sym.
      # Make Object::sym out of control.
      @TOPLEVEL_ALIAS_OWNER[sym] = false
    end

  when nil
    # Object::sym is out of control.
    if (cur_alias = topalias_defined?(sym)) && ! cur_alias.kind_of?(String)
      # Possibly, defined normally. Backup it.
      @TOPLEVEL_ALIAS_TABLE[current][sym] = cur_alias
    end
  else
    # No authority to control Object::sym and ALIASES::sym.
    # Do nothing.
  end
end
define_topalias(sym, obj) click to toggle source
# File lib/tk/autoload.rb, line 401
def define_topalias(sym, obj)
  if obj.kind_of? String
    # obj is an autoload path
    Tk::TOPLEVEL_ALIASES.autoload(sym, obj)
    unless Tk::TOPLEVEL_ALIASES.autoload?(sym)
      # file is autoloaded?
      if @AUTOLOAD_FILE_SYM_TABLE.has_key?(obj) &&
          (loaded_obj = @AUTOLOAD_FILE_SYM_TABLE[obj][sym])
        Tk::TOPLEVEL_ALIASES.const_set(sym, loaded_obj)
      else
        fail ArgumentError, "cannot define autoload file (already loaded?)"
      end
    end
  else
    # object
    Tk::TOPLEVEL_ALIASES.const_set(sym, obj)
  end
end
define_topobj(sym, obj) click to toggle source
# File lib/tk/autoload.rb, line 383
def define_topobj(sym, obj)
  if obj.kind_of? String
    # obj is an autoload path
    Object.autoload(sym, obj)
    unless Object.autoload?(sym)
      # file is autoloaded?
      if @AUTOLOAD_FILE_SYM_TABLE.has_key?(obj) &&
          (loaded_obj = @AUTOLOAD_FILE_SYM_TABLE[obj][sym])
        Object.const_set(sym, loaded_obj)
      else
        fail ArgumentError, "cannot define autoload file (already loaded?)"
      end
    end
  else
    # object
    Object.const_set(sym, obj)
  end
end
regist_sym_for_loaded_file(auto, obj, sym) click to toggle source
# File lib/tk/autoload.rb, line 450
def regist_sym_for_loaded_file(auto, obj, sym)
  @AUTOLOAD_FILE_SYM_TABLE[auto][sym] = obj

  reg = /^#{Regexp.quote(auto)}(\.rb|\.so|)$/
  @TOPLEVEL_ALIAS_TABLE.each_key{|set|
    if @TOPLEVEL_ALIAS_TABLE[set][sym] =~ reg
      @TOPLEVEL_ALIAS_TABLE[set][sym] = obj
      if @TOPLEVEL_ALIAS_OWNER[sym].nil? || @TOPLEVEL_ALIAS_OWNER[sym] == set
        replace_topalias(sym, obj)
        replace_topobj(sym, obj) if set == @current_default_widget_set
      end
    end
  }
  if (f = Object.autoload?(sym)) && f =~ reg
    replace_topobj(sym, obj)
  end
  if (f = Tk::TOPLEVEL_ALIASES.autoload?(sym)) && f =~ reg
    replace_topalias(sym, obj)
  end
end
replace_topalias(sym, obj) click to toggle source
# File lib/tk/autoload.rb, line 426
def replace_topalias(sym, obj) #=> old_obj (alias_filename or object) or nil
  if old_obj = topalias_defined?(sym)
    Tk::TOPLEVEL_ALIASES.module_eval{remove_const sym} rescue nil #ignore err
  end
  define_topalias(sym, obj)
  old_obj
end
replace_topobj(sym, obj) click to toggle source
# File lib/tk/autoload.rb, line 419
def replace_topobj(sym, obj) #=> old_obj (alias_filename or object) or nil
  if old_obj = topobj_defined?(sym)
    Object.class_eval{remove_const sym} rescue nil # ignore err
  end
  define_topobj(sym, obj)
  old_obj
end
set_topalias(target, obj, sym) click to toggle source
# File lib/tk/autoload.rb, line 472
def set_topalias(target, obj, sym)
  # obj is a kind of String : define autoload path
  #                  Class  : use the class object
  if target == @current_default_widget_set
    case @TOPLEVEL_ALIAS_OWNER[sym]
    when false
      # Object::sym is out of control. --> not change
      # Make ALIAS::sym under control, because target widget set is current.
      # Keep OWNER[sym]
      @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
      replace_topalias(sym, obj)

    when target
      if current_obj = topobj_defined?(sym)
        if current_obj == obj
          # Make current_obj under control.
          # Keep Object::sym.
          # Keep OWNER[sym].
          @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
          replace_topalias(sym, obj)

        else # current_obj != obj
          if current_obj == topalias_defined?(sym)
            # Change controlled object
            # Keep OWNER[sym].
            @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
            replace_topalias(sym, obj)
            replace_topobj(sym, obj)

          else # current_obj != topalias_defined?(sym)
            # Maybe current_obj is defined by user. --> OWNER[sym] = false
            # Keep Object::sym.
            @TOPLEVEL_ALIAS_OWNER[sym] = false
            @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
            replace_topalias(sym, obj)
          end
        end

      else # NOT topobj_defined?(sym)
        # New definition for sym at target.
        # Keep OWNER[sym].
        @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
        replace_topalias(sym, obj)
        define_topobj(sym, obj)
      end

    when nil
      # New definition for sym at target.
      @TOPLEVEL_ALIAS_OWNER[sym] = target
      @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
      replace_topalias(sym, obj)

    else # others
      # Maybe planning to make sym under control.
      @TOPLEVEL_ALIAS_OWNER[sym] = target
      @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
      replace_topalias(sym, obj)
      replace_topobj(sym, obj)
    end

  else # target != @current_default_widget_set
    case @TOPLEVEL_ALIAS_OWNER[sym]
    when false
      # Object::sym is out of control. --> not change
      if topalias_defined?(sym)
        # ALIAS[sym] may be defined by other widget set.
        # Keep Object::sym (even if it is not defined)
        # Keep ALIAS[sym].
        # Keep OWNER[sym].
        @TOPLEVEL_ALIAS_TABLE[target][sym] = obj

      else # NOT topalias_defined?(sym)
        # Nobody controls ALIAS[sym].
        # At least, current widget set doesn't control ALIAS[sym].
        # Keep Object::sym (even if it is not defined)
        # Keep OWNER[sym].
        @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
        define_topalias(sym, obj)
      end

    when target
      # Maybe change controlled object, because Object::sym is under control.
      # Keep OWNER[sym].
      @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
      replace_topalias(sym, obj)
      replace_topobj(sym, obj)

    when nil
      # New definition for sym
      @TOPLEVEL_ALIAS_OWNER[sym] = target
      @TOPLEVEL_ALIAS_TABLE[target][sym] = obj
      replace_topalias(sym, obj)
      replace_topobj(sym, obj)

    else # others
      # An other widget set controls sym.
      # Keep Object::sym (even if it is not defined)
      # Keep ALIAS[sym].
      # Keep OWNER[sym].
      @TOPLEVEL_ALIAS_TABLE[target][sym] = obj

    end
  end

  sym
end
topalias_defined?(sym) click to toggle source
# File lib/tk/autoload.rb, line 378
def topalias_defined?(sym) #=> alias_filename or object or false
  Tk::TOPLEVEL_ALIASES.autoload?(sym) ||
    (Tk::TOPLEVEL_ALIASES.const_defined?(sym) &&
       Tk::TOPLEVEL_ALIASES.const_get(sym))
end
topobj_defined?(sym) click to toggle source
# File lib/tk/autoload.rb, line 374
def topobj_defined?(sym) #=> alias_filename or object or false
  Object.autoload?(sym) ||
    (Object.const_defined?(sym) && Object.const_get(sym))
end

Public Instance Methods

Grid(*args) click to toggle source
# File lib/tk/autoload.rb, line 9
def Grid(*args); TkGrid.configure(*args); end
Pack(*args) click to toggle source
# File lib/tk/autoload.rb, line 12
def Pack(*args); TkPack.configure(*args); end
Place(*args) click to toggle source
# File lib/tk/autoload.rb, line 15
def Place(*args); TkPlace.configure(*args); end
root() click to toggle source
# File lib/tk.rb, line 2273
def root
  Tk::Root.new
end
update(idle=nil) click to toggle source
# File lib/tk.rb, line 2451
def update(idle=nil)
  # only for backward compatibility (This never be recommended to use)
  Tk.update(idle)
  self
end