Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • tk/lib/tk/texttag.rb

Class/Module Index [+]

Quicksearch

TktTag

Public Class Methods

id2obj(text, id) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 24
def TkTextTag.id2obj(text, id)
  tpath = text.path
  TTagID_TBL.mutex.synchronize{
    if TTagID_TBL[tpath]
      TTagID_TBL[tpath][id]? TTagID_TBL[tpath][id]: id
    else
      id
    end
  }
end
            
new(parent, *args) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 35
def initialize(parent, *args)
  #unless parent.kind_of?(TkText)
  #  fail ArgumentError, "expect TkText for 1st argument"
  #end
  @parent = @t = parent
  @tpath = parent.path
  Tk_TextTag_ID.mutex.synchronize{
    # @path = @id = Tk_TextTag_ID.join('')
    @path = @id = Tk_TextTag_ID.join(TkCore::INTERP._ip_id_).freeze
    Tk_TextTag_ID[1].succ!
  }
  TTagID_TBL.mutex.synchronize{
    TTagID_TBL[@id] = self
    TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath]
    TTagID_TBL[@tpath][@id] = self
  }
  #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
  if args != []
    keys = args.pop
    if keys.kind_of?(Hash)
      add(*args) if args != []
      configure(keys)
    else
      args.push keys
      add(*args)
    end
  end
  @t._addtag id, self
end
            

Public Instance Methods

[](key) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 123
def [](key)
  cget key
end
            
[]=(key,val) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 127
def []=(key,val)
  configure key, val
  val
end
            
add(*indices) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 86
def add(*indices)
  tk_call_without_enc(@t.path, 'tag', 'add', @id,
                      *(indices.collect{|idx| _get_eval_enc_str(idx)}))
  self
end
            
bind(seq, *args) click to toggle source

def bind(seq, cmd=Proc.new, *args)

_bind([@t.path, 'tag', 'bind', @id], seq, cmd, *args)
self

end

 
               # File tk/lib/tk/texttag.rb, line 197
def bind(seq, *args)
  # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
  if TkComm._callback_entry?(args[0]) || !block_given?
    cmd = args.shift
  else
    cmd = Proc.new
  end
  _bind([@t.path, 'tag', 'bind', @id], seq, cmd, *args)
  self
end
            
bind_append(seq, *args) click to toggle source

def #bind_append(seq, cmd=Proc.new, *args)

_bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, *args)
self

end

 
               # File tk/lib/tk/texttag.rb, line 212
def bind_append(seq, *args)
  # if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
  if TkComm._callback_entry?(args[0]) || !block_given?
    cmd = args.shift
  else
    cmd = Proc.new
  end
  _bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, *args)
  self
end
            
bind_remove(seq) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 223
def bind_remove(seq)
  _bind_remove([@t.path, 'tag', 'bind', @id], seq)
  self
end
            
bindinfo(context=nil) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 228
def bindinfo(context=nil)
  _bindinfo([@t.path, 'tag', 'bind', @id], context)
end
            
cget(key) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 135
def cget(key)
  @t.tag_cget @id, key
end
            
cget_strict(key) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 138
def cget_strict(key)
  @t.tag_cget_strict @id, key
end
            
cget_tkstring(key) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 132
def cget_tkstring(key)
  @t.tag_cget_tkstring @id, key
end
            
configinfo(key=nil) click to toggle source

def configure(key, val=None)

if key.kind_of?(Hash)
  tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key)
else
  tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val
end

end def configure(key, value)

if value == FALSE
  value = "0"
elsif value.kind_of?(Proc)
  value = install_cmd(value)
end
tk_call @t.path, 'tag', 'configure', @id, "-#{key}", value

end

 
               # File tk/lib/tk/texttag.rb, line 185
def configinfo(key=nil)
  @t.tag_configinfo @id, key
end
            
configure(key, val=None) click to toggle source

def cget(key)

case key.to_s
when 'text', 'label', 'show', 'data', 'file'
  _fromUTF8(tk_call_without_enc(@t.path, 'tag', 'cget', @id, "-#{key}"))
when 'font', 'kanjifont'
  #fnt = tk_tcl2ruby(tk_call(@t.path, 'tag', 'cget', @id, "-#{key}"))
  fnt = tk_tcl2ruby(_fromUTF8(tk_call_without_enc(@t.path, 'tag', 'cget',
                                                  @id, '-font')))
  unless fnt.kind_of?(TkFont)
    fnt = tagfontobj(@id, fnt)
  end
  if key.to_s == 'kanjifont' && JAPANIZED_TK && TK_VERSION =~ /^4\.*/
    # obsolete; just for compatibility
    fnt.kanji_font
  else
    fnt
  end
else
  tk_tcl2ruby(_fromUTF8(tk_call_without_enc(@t.path, 'tag', 'cget',
                                            @id, "-#{key}")))
end

end

 
               # File tk/lib/tk/texttag.rb, line 166
def configure(key, val=None)
  @t.tag_configure @id, key, val
end
            
current_configinfo(key=nil) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 189
def current_configinfo(key=nil)
  @t.current_tag_configinfo @id, key
end
            
destroy() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 244
def destroy
  tk_call_without_enc(@t.path, 'tag', 'delete', @id)
  TTagID_TBL.mutex.synchronize{
    TTagID_TBL[@tpath].delete(@id) if TTagID_TBL[@tpath]
  }
  self
end
            
exist?() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 69
def exist?
  #if ( tk_split_simplelist(_fromUTF8(tk_call_without_enc(@t.path, 'tag', 'names'))).find{|id| id == @id } )
  if ( tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'names'), false, true).find{|id| id == @id } )
    true
  else
    false
  end
end
            
first() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 78
def first
  Tk::Text::IndexString.new(@id + '.first')
end
            
id() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 65
def id
  Tk::Text::IndexString.new(@id)
end
            
last() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 82
def last
  Tk::Text::IndexString.new(@id + '.last')
end
            
lower(below=None) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 238
def lower(below=None)
  tk_call_without_enc(@t.path, 'tag', 'lower', @id,
                      _get_eval_enc_str(below))
  self
end
            
mutex() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 16
def mutex; @mutex; end
            
nextrange(first, last=None) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 107
def nextrange(first, last=None)
  simplelist(tk_call_without_enc(@t.path, 'tag', 'nextrange', @id,
                                 _get_eval_enc_str(first),
                                 _get_eval_enc_str(last))).collect{|idx|
    Tk::Text::IndexString.new(idx)
  }
end
            
prevrange(first, last=None) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 115
def prevrange(first, last=None)
  simplelist(tk_call_without_enc(@t.path, 'tag', 'prevrange', @id,
                                 _get_eval_enc_str(first),
                                 _get_eval_enc_str(last))).collect{|idx|
    Tk::Text::IndexString.new(idx)
  }
end
            
raise(above=None) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 232
def raise(above=None)
  tk_call_without_enc(@t.path, 'tag', 'raise', @id,
                      _get_eval_enc_str(above))
  self
end
            
ranges() click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 98
def ranges
  l = tk_split_simplelist(tk_call_without_enc(@t.path, 'tag', 'ranges', @id))
  r = []
  while key=l.shift
    r.push [Tk::Text::IndexString.new(key), Tk::Text::IndexString.new(l.shift)]
  end
  r
end
            
remove(*indices) click to toggle source
 
               # File tk/lib/tk/texttag.rb, line 92
def remove(*indices)
  tk_call_without_enc(@t.path, 'tag', 'remove', @id,
                      *(indices.collect{|idx| _get_eval_enc_str(idx)}))
  self
end