⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tktext.rb

📁 ruby的源代码
💻 RB
📖 第 1 页 / 共 2 页
字号:
	if cnt == 0	  break	end      end      idx += 1    end    return str[i+1..idx-1], idx + 2  end  private :_retrieve_braced_text  def _retrieve_backslashed_text(str, i)    j = i    idx = nil    loop {      idx = str.index(/ /, j)      if str[idx-1] == ?\\	j += 1      else	break      end    }    val = str[i..(idx-1)]    val.gsub!(/\\( |\{|\})/, '\1')    return val, idx + 1  end  private :_retrieve_backslashed_text  def dump_all(*index, &block)    dump(['all'], *index, &block)  end  def dump_mark(*index, &block)    dump(['mark'], *index, &block)  end  def dump_tag(*index, &block)    dump(['tag'], *index, &block)  end  def dump_text(*index, &block)    dump(['text'], *index, &block)  end  def dump_window(*index, &block)    dump(['window'], *index, &block)  end  def dump_image(*index, &block)    dump(['image'], *index, &block)  endendclass TkTextTag<TkObject  include TkTreatTagFont  Tk_TextTag_ID = ['tag0000']  def initialize(parent, *args)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @parent = @t = parent    @path = @id = Tk_TextTag_ID[0]    Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ    #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)    if args != [] then      keys = args.pop      if keys.kind_of? Hash then	add(*args) if args != []	configure(keys)      else	args.push keys	add(*args)      end    end    @t._addtag id, self  end  def id    return @id  end  def first    @id + '.first'  end  def last    @id + '.last'  end  def add(*index)    tk_call @t.path, 'tag', 'add', @id, *index  end  def remove(*index)    tk_call @t.path, 'tag', 'remove', @id, *index  end  def ranges    l = tk_split_simplelist(tk_call(@t.path, 'tag', 'ranges', @id))    r = []    while key=l.shift      r.push [key, l.shift]    end    r  end  def nextrange(first, last=None)    tk_split_simplelist(tk_call(@t.path, 'tag', 'nextrange', @id, first, last))  end  def prevrange(first, last=None)    tk_split_simplelist(tk_call(@t.path, 'tag', 'prevrange', @id, first, last))  end  def [](key)    cget key  end  def []=(key,val)    configure key, val  end  def cget(key)    case key    when 'text', 'label', 'show', 'data', 'file'      tk_call @t.path, 'tag', 'cget', @id, "-#{key}"    else      tk_tcl2ruby tk_call @t.path, 'tag', 'cget', @id, "-#{key}"    end  end  def configure(key, val=None)    @t.tag_configure @id, key, val  end#  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  def configinfo(key=nil)    @t.tag_configinfo @id, key  end  def bind(seq, cmd=Proc.new, args=nil)    _bind([@t.path, 'tag', 'bind', @id], seq, cmd, args)  end  def bind_append(seq, cmd=Proc.new, args=nil)    _bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, args)  end  def bindinfo(context=nil)    _bindinfo([@t.path, 'tag', 'bind', @id], context)  end  def raise(above=None)    tk_call @t.path, 'tag', 'raise', @id, above  end  def lower(below=None)    tk_call @t.path, 'tag', 'lower', @id, below  end  def destroy    tk_call @t.path, 'tag', 'delete', @id  endendclass TkTextTagSel<TkTextTag  def initialize(parent, keys=nil)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    @path = @id = 'sel'    #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)    configure(keys) if keys    @t._addtag id, self  endendclass TkTextMark<TkObject  Tk_TextMark_ID = ['mark0000']  def initialize(parent, index)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    @path = @id = Tk_TextMark_ID[0]    Tk_TextMark_ID[0] = Tk_TextMark_ID[0].succ    tk_call @t.path, 'mark', 'set', @id, index    @t._addtag id, self  end  def id    return @id  end  def set(where)    tk_call @t.path, 'mark', 'set', @id, where  end  def unset    tk_call @t.path, 'mark', 'unset', @id  end  alias destroy unset  def gravity    tk_call @t.path, 'mark', 'gravity', @id  end  def gravity=(direction)    tk_call @t.path, 'mark', 'gravity', @id, direction  end  def next(index = nil)    if index      @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index))    else      @t.tagid2obj(tk_call(@t.path, 'mark', 'next', @id))    end  end  def previous(index = nil)    if index      @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index))    else      @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', @id))    end  endendclass TkTextMarkInsert<TkTextMark  def initialize(parent, index=nil)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    @path = @id = 'insert'    tk_call @t.path, 'mark', 'set', @id, index if index    @t._addtag id, self  endendclass TkTextMarkCurrent<TkTextMark  def initialize(parent,index=nil)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    @path = @id = 'current'    tk_call @t.path, 'mark', 'set', @id, index if index    @t._addtag id, self  endendclass TkTextMarkAnchor<TkTextMark  def initialize(parent,index=nil)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    @path = @id = 'anchor'    tk_call @t.path, 'mark', 'set', @id, index if index    @t._addtag id, self  endendclass TkTextWindow<TkObject  def initialize(parent, index, keys)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    if index == 'end'      @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))    elsif index.kind_of? TkTextMark      if tk_call(@t.path,'index',index.path) == tk_call(@t.path,'index','end')	@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))      else	@path = TkTextMark.new(@t, tk_call(@t.path, 'index', index.path))      end    else      @path = TkTextMark.new(@t, tk_call(@t.path, 'index', index))    end    @path.gravity = 'left'    @index = @path.path    @id = keys['window']    if keys['create']      @p_create = keys['create']      if @p_create.kind_of? Proc	keys['create'] = install_cmd(proc{@id = @p_create.call; @id.path})      end    end    tk_call @t.path, 'window', 'create', @index, *hash_kv(keys)  end  def [](slot)    cget(slot)  end  def []=(slot, value)    configure(slot, value)  end  def cget(slot)    case slot    when 'text', 'label', 'show', 'data', 'file'      tk_call @t.path, 'window', 'cget', @index, "-#{slot}"    else      tk_tcl2ruby tk_call @t.path, 'window', 'cget', @index, "-#{slot}"    end  end  def configure(slot, value=None)    if slot.kind_of? Hash      @id = slot['window'] if slot['window']      if slot['create']	self.create=value	slot['create']=nil      end      if slot.size > 0	tk_call @t.path, 'window', 'configure', @index, *hash_kv(slot)      end    else      @id = value if slot == 'window'      if slot == 'create'	self.create=value      else	tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value      end    end  end  def window    @id  end  def window=(value)    tk_call @t.path, 'window', 'configure', @index, '-window', value    @id = value  end  def create    @p_create  end  def create=(value)    @p_create = value    if @p_create.kind_of? Proc      value = install_cmd(proc{@id = @p_create.call})    end    tk_call @t.path, 'window', 'configure', @index, '-create', value  end  def configinfo(slot = nil)    if slot      case slot      when 'text', 'label', 'show', 'data', 'file'	conf = tk_split_simplelist(tk_call @t.path, 'window', 'configure', 				   @index, "-#{slot}")      else	conf = tk_split_list(tk_call @t.path, 'window', 'configure', 			     @index, "-#{slot}")      end      conf[0] = conf[0][1..-1]      conf    else      tk_split_simplelist(tk_call @t.path, 'window', 'configure', 			  @index).collect{|conflist|	conf = tk_split_simplelist(conflist)	conf[0] = conf[0][1..-1]	case conf[0]	when 'text', 'label', 'show', 'data', 'file'	else	  if conf[3]	    if conf[3].index('{')	      conf[3] = tk_split_list(conf[3]) 	    else	      conf[3] = tk_tcl2ruby(conf[3]) 	    end	  end	  if conf[4]	    if conf[4].index('{')	      conf[4] = tk_split_list(conf[4]) 	    else	      conf[4] = tk_tcl2ruby(conf[4]) 	    end	  end	end	conf      }    end  endendclass TkTextImage<TkObject  def initialize(parent, index, keys)    if not parent.kind_of?(TkText)      fail format("%s need to be TkText", parent.inspect)    end    @t = parent    if index == 'end'      @path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))    elsif index.kind_of? TkTextMark      if tk_call(@t.path,'index',index.path) == tk_call(@t.path,'index','end')	@path = TkTextMark.new(@t, tk_call(@t.path, 'index', 'end - 1 chars'))      else	@path = TkTextMark.new(@t, tk_call(@t.path, 'index', index.path))      end    else      @path = TkTextMark.new(@t, tk_call(@t.path, 'index', index))    end    @path.gravity = 'left'    @index = @path.path    @id = tk_call(@t.path, 'image', 'create', @index, *hash_kv(keys))  end  def [](slot)    cget(slot)  end  def []=(slot, value)    configure(slot, value)  end  def cget(slot)    case slot    when 'text', 'label', 'show', 'data', 'file'      tk_call @t.path, 'image', 'cget', @index, "-#{slot}"    else      tk_tcl2ruby tk_call @t.path, 'image', 'cget', @index, "-#{slot}"    end  end  def configure(slot, value=None)    if slot.kind_of? Hash      tk_call @t.path, 'image', 'configure', @index, *hash_kv(slot)    else      tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value    end  end#  def configure(slot, value)#    tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value#  end  def image    tk_call @t.path, 'image', 'configure', @index, '-image'  end  def image=(value)    tk_call @t.path, 'image', 'configure', @index, '-image', value  end  def configinfo(slot = nil)    if slot      case slot      when 'text', 'label', 'show', 'data', 'file'	conf = tk_split_simplelist(tk_call @t.path, 'image', 'configure', 				   @index, "-#{slot}")      else	conf = tk_split_list(tk_call @t.path, 'image', 'configure', 			     @index, "-#{slot}")      end      conf[0] = conf[0][1..-1]      conf    else      tk_split_simplelist(tk_call @t.path, 'image', 'configure', 			  @index).collect{|conflist|	conf = tk_split_simplelist(conflist)	conf[0] = conf[0][1..-1]	case conf[0]	when 'text', 'label', 'show', 'data', 'file'	else	  if conf[3]	    if conf[3].index('{')	      conf[3] = tk_split_list(conf[3]) 	    else	      conf[3] = tk_tcl2ruby(conf[3]) 	    end	  end	  if conf[4]	    if conf[4].index('{')	      conf[4] = tk_split_list(conf[4]) 	    else	      conf[4] = tk_tcl2ruby(conf[4]) 	    end	  end	end	conf      }    end  endend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -