Class: TkNamespace

Class | TkNamespace
In: | tk/lib/tk/namespace.rb
Parent: | TkObject

### Methods

children children code code current current current_namespace delete delete ensemble_configinfo ensemble_configure ensemble_create ensemble_exist? eval eval exist? exist? export export export_with_clear export_with_clear force_import force_import forget forget get_path import import inscope inscope new ns_tk_call ns_tk_call_with_enc ns_tk_call_without_enc origin parent parent qualifiers set_path set_path tail tk_call tk_call_with_enc tk_call_without_enc which which_command which_variable

### Classes and Modules

Class TkNamespace::Ensemble
Class TkNamespace::NsCode
Class TkNamespace::ScopeArgs

### Constants

TkCommandNames | = | [ 'namespace'.freeze, ].freeze
Tk_Namespace_ID_TBL | = | TkCore::INTERP.create_table
Tk_Namespace_ID | = | ["ns".freeze, "00000".taint].freeze

### External Aliases

tk_call | -> | __tk_call
tk_call_without_enc | -> | __tk_call_without_enc
tk_call_with_enc | -> | __tk_call_with_enc

### Public Class methods

children(*args)

[Source]

    # File tk/lib/tk/namespace.rb, line 224
      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)

[Source]

    # File tk/lib/tk/namespace.rb, line 240
      def self.code(script = Proc.new)
        TkNamespace.new('').code(script)
      end

current()

[Source]

    # File tk/lib/tk/namespace.rb, line 255
      def self.current
        tk_call('namespace', 'current')
      end

delete(*ns_list)

[Source]

    # File tk/lib/tk/namespace.rb, line 264
      def self.delete(*ns_list)
        tk_call('namespace', 'delete', *ns_list)
      end

ensemble_configinfo(cmd, slot = nil)

[Source]

    # File tk/lib/tk/namespace.rb, line 281
      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)

[Source]

    # File tk/lib/tk/namespace.rb, line 274
      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)

[Source]

    # File tk/lib/tk/namespace.rb, line 271
      def self.ensemble_create(*keys)
        tk_call('namespace', 'ensemble', 'create', *hash_kv(keys))
      end

ensemble_exist?(cmd)

[Source]

    # File tk/lib/tk/namespace.rb, line 290
      def self.ensemble_exist?(cmd)
        bool(tk_call('namespace', 'ensemble', 'exists', cmd))
      end

eval(namespace, cmd = Proc.new, *args)

[Source]

    # File tk/lib/tk/namespace.rb, line 294
      def self.eval(namespace, cmd = Proc.new, *args)
        #tk_call('namespace', 'eval', namespace, cmd, *args)
        TkNamespace.new(namespece).eval(cmd, *args)
      end

exist?(ns)

[Source]

    # File tk/lib/tk/namespace.rb, line 308
      def self.exist?(ns)
        bool(tk_call('namespace', 'exists', ns))
      end

export(*patterns)

[Source]

    # File tk/lib/tk/namespace.rb, line 315
      def self.export(*patterns)
        tk_call('namespace', 'export', *patterns)
      end

export_with_clear(*patterns)

[Source]

    # File tk/lib/tk/namespace.rb, line 318
      def self.export_with_clear(*patterns)
        tk_call('namespace', 'export', '-clear', *patterns)
      end

force_import(*patterns)

[Source]

    # File tk/lib/tk/namespace.rb, line 338
      def self.force_import(*patterns)
        tk_call('namespace', 'import', '-force', *patterns)
      end

forget(*patterns)

[Source]

    # File tk/lib/tk/namespace.rb, line 328
      def self.forget(*patterns)
        tk_call('namespace', 'forget', *patterns)
      end

get_path()

[Source]

    # File tk/lib/tk/namespace.rb, line 371
      def self.get_path
        tk_call('namespace', 'path')
      end

import(*patterns)

[Source]

    # File tk/lib/tk/namespace.rb, line 335
      def self.import(*patterns)
        tk_call('namespace', 'import', *patterns)
      end

inscope(namespace, script, *args)

[Source]

    # File tk/lib/tk/namespace.rb, line 348
      def self.inscope(namespace, script, *args)
        tk_call('namespace', 'inscope', namespace, script, *args)
      end

new(name = nil, parent = nil)

[Source]

    # File tk/lib/tk/namespace.rb, line 182
      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)

[Source]

    # File tk/lib/tk/namespace.rb, line 355
      def self.origin(cmd)
        tk_call('namespace', 'origin', cmd)
      end

parent(namespace=None)

[Source]

    # File tk/lib/tk/namespace.rb, line 359
      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)

[Source]

    # File tk/lib/tk/namespace.rb, line 381
      def self.qualifiers(str)
        tk_call('namespace', 'qualifiers', str)
      end

set_path(*namespace_list)

[Source]

    # File tk/lib/tk/namespace.rb, line 374
      def self.set_path(*namespace_list)
        tk_call('namespace', 'path', array2tk_list(namespace_list))
      end

tail(str)

[Source]

    # File tk/lib/tk/namespace.rb, line 385
      def self.tail(str)
        tk_call('namespace', 'tail', str)
      end

which(name)

[Source]

    # File tk/lib/tk/namespace.rb, line 389
      def self.which(name)
        tk_call('namespace', 'which', name)
      end

which_command(name)

[Source]

    # File tk/lib/tk/namespace.rb, line 392
      def self.which_command(name)
        tk_call('namespace', 'which', '-command', name)
      end

which_variable(name)

[Source]

    # File tk/lib/tk/namespace.rb, line 395
      def self.which_variable(name)
        tk_call('namespace', 'which', '-variable', name)
      end

### Public Instance methods

children(pattern=None)

[Source]

    # File tk/lib/tk/namespace.rb, line 236
      def children(pattern=None)
        TkNamespace.children(@fullname, pattern)
      end

code(script = Proc.new)

[Source]

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

current()

Alias for current_namespace

current_namespace()

[Source]

    # File tk/lib/tk/namespace.rb, line 258
      def current_namespace
        # ns_tk_call('namespace', 'current')
        @fullname
      end

delete()

[Source]

    # File tk/lib/tk/namespace.rb, line 267
      def delete
        TkNamespece.delete(@fullname)
      end

eval(cmd = Proc.new, *args)

[Source]

    # File tk/lib/tk/namespace.rb, line 298
      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]))
        ret
      end

exist?()

[Source]

    # File tk/lib/tk/namespace.rb, line 311
      def exist?
        TkNamespece.delete(@fullname)
      end

export()

[Source]

    # File tk/lib/tk/namespace.rb, line 321
      def export
        TkNamespace.export(@fullname)
      end

export_with_clear()

[Source]

    # File tk/lib/tk/namespace.rb, line 324
      def export_with_clear
        TkNamespace.export_with_clear(@fullname)
      end

force_import()

[Source]

    # File tk/lib/tk/namespace.rb, line 344
      def force_import
        TkNamespace.force_import(@fullname)
      end

forget()

[Source]

    # File tk/lib/tk/namespace.rb, line 331
      def forget
        TkNamespace.forget(@fullname)
      end

import()

[Source]

    # File tk/lib/tk/namespace.rb, line 341
      def import
        TkNamespace.import(@fullname)
      end

inscope(script, *args)

[Source]

    # File tk/lib/tk/namespace.rb, line 351
      def inscope(script, *args)
        TkNamespace(@fullname, script, *args)
      end

ns_tk_call(*args)

Alias for tk_call

ns_tk_call_with_enc(*args)

Alias for tk_call_with_enc

ns_tk_call_without_enc(*args)

Alias for tk_call_without_enc

parent()

[Source]

    # File tk/lib/tk/namespace.rb, line 367
      def parent
        tk_call('namespace', 'parent', @fullname)
      end

set_path()

[Source]

    # File tk/lib/tk/namespace.rb, line 377
      def set_path
        tk_call('namespace', 'path', @fullname)
      end

tk_call(*args)

[Source]

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

tk_call_with_enc(*args)

[Source]

    # File tk/lib/tk/namespace.rb, line 172
      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)

[Source]

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

[Validate]