In Files

  • tk/lib/tk/namespace.rb

Class/Module Index [+]

Quicksearch

TkNamespace

Public Class Methods

children(*args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 258
def self.children(*args)
  # args ::= [<namespace>] [<pattern>]
  # <pattern> must be glob-style pattern
  tk_split_simplelist(tk_call('namespace', 'children', *args)).collect{|ns|
    # ns is fullname
    if Tk_Namespace_ID_TBL.key?(ns)
      Tk_Namespace_ID_TBL[ns]
    else
      ns
    end
  }
end
            
code(script = Proc.new) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 274
def self.code(script = Proc.new)
  TkNamespace.new('').code(script)
end
            
current() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 320
def self.current
  ns = self.current_path
  if Tk_Namespace_ID_TBL.key?(ns)
    Tk_Namespace_ID_TBL[ns]
  else
    ns
  end
end
            
current_path() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 313
def self.current_path
  tk_call('namespace', 'current')
end
            
delete(*ns_list) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 335
def self.delete(*ns_list)
  tk_call('namespace', 'delete', *ns_list)
  ns_list.each{|ns|
    if ns.kind_of?(TkNamespace)
      Tk_Namespace_ID_TBL.delete(ns.path)
    else
      Tk_Namespace_ID_TBL.delete(ns.to_s)
    end
  }
end
            
ensemble_configinfo(cmd, slot = nil) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 359
def self.ensemble_configinfo(cmd, slot = nil)
  if slot
    tk_call('namespace', 'ensemble', 'configure', cmd, '-' + slot.to_s)
  else
    inf = {}
    Hash(*tk_split_simplelist(tk_call('namespace', 'ensemble', 'configure', cmd))).each{|k, v| inf[k[1..-1]] = v}
    inf
  end
end
            
ensemble_configure(cmd, slot, value=None) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 352
def self.ensemble_configure(cmd, slot, value=None)
  if slot.kind_of?(Hash)
    tk_call('namespace', 'ensemble', 'configure', cmd, *hash_kv(slot))
  else
    tk_call('namespace', 'ensemble', 'configure', cmd, '-'+slot.to_s, value)
  end
end
            
ensemble_create(*keys) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 349
def self.ensemble_create(*keys)
  tk_call('namespace', 'ensemble', 'create', *hash_kv(keys))
end
            
ensemble_exist?(cmd) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 368
def self.ensemble_exist?(cmd)
  bool(tk_call('namespace', 'ensemble', 'exists', cmd))
end
            
eval(namespace, cmd = Proc.new, *args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 372
def self.eval(namespace, cmd = Proc.new, *args)
  #tk_call('namespace', 'eval', namespace, cmd, *args)
  TkNamespace.new(namespece).eval(cmd, *args)
end
            
exist?(ns) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 394
def self.exist?(ns)
  bool(tk_call('namespace', 'exists', ns))
end
            
export(*patterns) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 401
def self.export(*patterns)
  tk_call('namespace', 'export', *patterns)
end
            
export_with_clear(*patterns) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 404
def self.export_with_clear(*patterns)
  tk_call('namespace', 'export', '-clear', *patterns)
end
            
force_import(*patterns) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 424
def self.force_import(*patterns)
  tk_call('namespace', 'import', '-force', *patterns)
end
            
forget(*patterns) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 414
def self.forget(*patterns)
  tk_call('namespace', 'forget', *patterns)
end
            
get_path() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 457
def self.get_path
  tk_call('namespace', 'path')
end
            
get_unknown_handler() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 482
def self.get_unknown_handler
  tk_tcl2ruby(tk_call('namespace', 'unknown'))
end
            
id2obj(id) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 24
def TkNamespace.id2obj(id)
  Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
end
            
import(*patterns) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 421
def self.import(*patterns)
  tk_call('namespace', 'import', *patterns)
end
            
inscope(namespace, script, *args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 434
def self.inscope(namespace, script, *args)
  tk_call('namespace', 'inscope', namespace, script, *args)
end
            
new(name = nil, parent = nil) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 216
def initialize(name = nil, parent = nil)
  unless name
    # name = Tk_Namespace_ID.join('')
    name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
    Tk_Namespace_ID[1].succ!
  end
  name = __tk_call('namespace', 'current') if name == ''
  if parent
    if parent =~ /^::/
      if name =~ /^::/
        @fullname = parent + name
      else
        @fullname = parent +'::'+ name
      end
    else
      ancestor = __tk_call('namespace', 'current')
      ancestor = '' if ancestor == '::'
      if name =~ /^::/
        @fullname = ancestor + '::' + parent + name
      else
        @fullname = ancestor + '::'+ parent +'::'+ name
      end
    end
  else # parent == nil
    ancestor = __tk_call('namespace', 'current')
    ancestor = '' if ancestor == '::'
    if name =~ /^::/
      @fullname = name
    else
      @fullname = ancestor + '::' + name
    end
  end
  @path = @fullname
  @parent = __tk_call('namespace', 'qualifiers', @fullname)
  @name = __tk_call('namespace', 'tail', @fullname)

  # create namespace
  __tk_call('namespace', 'eval', @fullname, '')

  Tk_Namespace_ID_TBL[@fullname] = self
end
            
origin(cmd) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 441
def self.origin(cmd)
  tk_call('namespace', 'origin', cmd)
end
            
parent(namespace=None) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 445
def self.parent(namespace=None)
  ns = tk_call('namespace', 'parent', namespace)
  if Tk_Namespace_ID_TBL.key?(ns)
    Tk_Namespace_ID_TBL[ns]
  else
    ns
  end
end
            
qualifiers(str) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 467
def self.qualifiers(str)
  tk_call('namespace', 'qualifiers', str)
end
            
set_path(*namespace_list) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 460
def self.set_path(*namespace_list)
  tk_call('namespace', 'path', array2tk_list(namespace_list))
end
            
set_unknown_handler(cmd = Proc.new) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 485
def self.set_unknown_handler(cmd = Proc.new)
  tk_call('namespace', 'unknown', cmd)
end
            
tail(str) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 471
def self.tail(str)
  tk_call('namespace', 'tail', str)
end
            
upvar(namespace, *var_pairs) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 475
def self.upvar(namespace, *var_pairs)
  tk_call('namespace', 'upvar', namespace, *(var_pairs.flatten))
end
            
which(name) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 489
def self.which(name)
  tk_call('namespace', 'which', name)
end
            
which_command(name) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 492
def self.which_command(name)
  tk_call('namespace', 'which', '-command', name)
end
            
which_variable(name) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 495
def self.which_variable(name)
  tk_call('namespace', 'which', '-variable', name)
end
            

Public Instance Methods

__tk_call(*args) click to toggle source
Alias for: tk_call
__tk_call_with_enc(*args) click to toggle source
Alias for: tk_call_with_enc
__tk_call_without_enc(*args) click to toggle source
Alias for: tk_call_without_enc
children(pattern=None) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 270
def children(pattern=None)
  TkNamespace.children(@fullname, pattern)
end
            
code(script = Proc.new) click to toggle source

begin

def code(script = Proc.new)
  if script.kind_of?(String)
    cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(script)}
  elsif script.kind_of?(Proc)
    cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(&script)}
  else
    fail ArgumentError, "String or Proc is expected"
  end
  TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code', 
                                              _get_eval_string(cmd, false)))
end

end

 
               # File tk/lib/tk/namespace.rb, line 290
def code(script = Proc.new)
  if script.kind_of?(String)
    cmd = proc{|*args|
      ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
      id = ret.object_id
      TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
      id
    }
  elsif script.kind_of?(Proc)
    cmd = proc{|*args|
      ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
      id = ret.object_id
      TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
      id
    }
  else
    fail ArgumentError, "String or Proc is expected"
  end
  TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code', 
                                              _get_eval_string(cmd, false)), 
                          true)
end
            
current() click to toggle source
Alias for: current_namespace
current_namespace() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 328
def current_namespace
  # ns_tk_call('namespace', 'current')
  # @fullname
  self
end
            
Also aliased as: current
current_path() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 316
def current_path
  @fullname
end
            
delete() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 345
def delete
  TkNamespece.delete(@fullname)
end
            
eval(cmd = Proc.new, *args) click to toggle source

begin

def eval(cmd = Proc.new, *args)
  #TkNamespace.eval(@fullname, cmd, *args)
  #ns_tk_call(cmd, *args)
  code_obj = code(cmd)
  ret = code_obj.call(*args)
  # uninstall_cmd(TkCore::INTERP._split_tklist(code_obj.path)[-1])
  uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
  tk_tcl2ruby(ret)
end

end

 
               # File tk/lib/tk/namespace.rb, line 387
def eval(cmd = Proc.new, *args)
  code_obj = code(cmd)
  ret = code_obj.call(*args)
  uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
  ret
end
            
exist?() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 397
def exist?
  TkNamespece.exist?(@fullname)
end
            
export() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 407
def export
  TkNamespace.export(@fullname)
end
            
export_with_clear() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 410
def export_with_clear
  TkNamespace.export_with_clear(@fullname)
end
            
force_import() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 430
def force_import
  TkNamespace.force_import(@fullname)
end
            
forget() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 417
def forget
  TkNamespace.forget(@fullname)
end
            
import() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 427
def import
  TkNamespace.import(@fullname)
end
            
inscope(script, *args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 437
def inscope(script, *args)
  TkNamespace.inscope(@fullname, script, *args)
end
            
install_cmd(cmd) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 181
def install_cmd(cmd)
  lst = tk_split_simplelist(super(cmd), false, false)
  if lst[1] =~ /^::/
    lst[1] = @fullname
  else
    lst.insert(1, @fullname)
  end
  TkCore::INTERP._merge_tklist(*lst)
end
            
ns_tk_call(*args) click to toggle source
Alias for: tk_call
ns_tk_call_with_enc(*args) click to toggle source
Alias for: tk_call_with_enc
ns_tk_call_without_enc(*args) click to toggle source
Alias for: tk_call_without_enc
parent() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 453
def parent
  tk_call('namespace', 'parent', @fullname)
end
            
set_path() click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 463
def set_path
  tk_call('namespace', 'path', @fullname)
end
            
tk_call(*args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 194
def tk_call(*args)
  #super('namespace', 'eval', @fullname, *args)
  args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
  super('namespace', 'eval', @fullname, 
        TkCore::INTERP._merge_tklist(*args))
end
            
Also aliased as: __tk_call, ns_tk_call
tk_call_with_enc(*args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 206
def tk_call_with_enc(*args)
  #super('namespace', 'eval', @fullname, *args)
  args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
  super('namespace', 'eval', @fullname, 
        TkCore::INTERP._merge_tklist(*args))
end
            
tk_call_without_enc(*args) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 200
def tk_call_without_enc(*args)
  #super('namespace', 'eval', @fullname, *args)
  args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
  super('namespace', 'eval', @fullname,  
        TkCore::INTERP._merge_tklist(*args))
end
            
upvar(*var_pairs) click to toggle source
 
               # File tk/lib/tk/namespace.rb, line 478
def upvar(*var_pairs)
  TkNamespace.inscope(@fullname, *(var_pairs.flatten))
end