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

📄 tkcanvas.rb

📁 ruby的源代码
💻 RB
📖 第 1 页 / 共 2 页
字号:
#		tkcanvas.rb - Tk canvas classes#			$Date: 2002/02/28 06:52:49 $#			by Yukihiro Matsumoto <matz@caelum.co.jp>#			$Date: 2002/02/28 06:52:49 $#			by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>require "tk"require 'tkfont'module TkTreatCItemFont  include TkTreatItemFont  ItemCMD = ['itemconfigure', TkComm::None]  def __conf_cmd(idx)    ItemCMD[idx]  end  def __item_pathname(tagOrId)    if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag)      self.path + ';' + tagOrId.id.to_s    else      self.path + ';' + tagOrId.to_s    end  endendclass TkCanvas<TkWindow  include TkTreatCItemFont  include Scrollable  WidgetClassName = 'Canvas'.freeze  WidgetClassNames[WidgetClassName] = self  def self.to_eval    WidgetClassName  end  def create_self(keys)    if keys and keys != None      tk_call 'canvas', @path, *hash_kv(keys)    else      tk_call 'canvas', @path    end  end  def tagid(tag)    if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag)      tag.id    else      tag    end  end  private :tagid  def addtag(tag, mode, *args)    tk_send 'addtag', tagid(tag), mode, *args  end  def addtag_above(tagOrId, target)    addtag(tagOrId, 'above', tagid(target))  end  def addtag_all(tagOrId)    addtag(tagOrId, 'all')  end  def addtag_below(tagOrId, target)    addtag(tagOrId, 'below', tagid(target))  end  def addtag_closest(tagOrId, x, y, halo=None, start=None)    addtag(tagOrId, 'closest', x, y, halo, start)  end  def addtag_enclosed(tagOrId, x1, y1, x2, y2)    addtag(tagOrId, 'enclosed', x1, y1, x2, y2)  end  def addtag_overlapping(tagOrId, x1, y1, x2, y2)    addtag(tagOrId, 'overlapping', x1, y1, x2, y2)  end  def addtag_withtag(tagOrId, tag)    addtag(tagOrId, 'withtag', tagid(tag))  end  def bbox(tagOrId, *tags)    list(tk_send('bbox', tagid(tagOrId), *tags.collect{|t| tagid(t)}))  end  def itembind(tag, context, cmd=Proc.new, args=nil)    _bind([path, "bind", tagid(tag)], context, cmd, args)  end  def itembind_append(tag, context, cmd=Proc.new, args=nil)    _bind_append([path, "bind", tagid(tag)], context, cmd, args)  end  def itembindinfo(tag, context=nil)    _bindinfo([path, "bind", tagid(tag)], context)  end  def canvasx(x, *args)    tk_tcl2ruby(tk_send 'canvasx', x, *args)  end  def canvasy(y, *args)    tk_tcl2ruby(tk_send 'canvasy', y, *args)  end  def coords(tag, *args)    if args == []      tk_split_list(tk_send('coords', tagid(tag)))    else      tk_send('coords', tagid(tag), *args)    end  end  def dchars(tag, first, last=None)    tk_send 'dchars', tagid(tag), first, last  end  def delete(*args)    tk_send 'delete', *args.collect{|t| tagid(t)}  end  alias remove delete  def dtag(tag, tag_to_del=None)    tk_send 'dtag', tagid(tag), tag_to_del  end  def find(mode, *args)    list(tk_send 'find', mode, *args).collect!{|id|       TkcItem.id2obj(self, id)    }  end  def find_above(target)    find('above', tagid(target))  end  def find_all    find('all')  end  def find_below(target)    find('below', tagid(target))  end  def find_closest(x, y, halo=None, start=None)    find('closest', x, y, halo, start)  end  def find_enclosed(x1, y1, x2, y2)    find('enclosed', x1, y1, x2, y2)  end  def find_overlapping(x1, y1, x2, y2)    find('overlapping', x1, y1, x2, y2)  end  def find_withtag(tag)    find('withtag', tag)  end  def itemfocus(tagOrId=nil)    if tagOrId      tk_send 'focus', tagid(tagOrId)    else      ret = tk_send('focus')      if ret == ""	nil      else	TkcItem.id2obj(self, ret)      end    end  end  def gettags(tagOrId)    list(tk_send('gettags', tagid(tagOrId))).collect{|tag|      TkcTag.id2obj(self, tag)    }  end  def icursor(tagOrId, index)    tk_send 'icursor', tagid(tagOrId), index  end  def index(tagOrId, index)    tk_send 'index', tagid(tagOrId), index  end  def insert(tagOrId, index, string)    tk_send 'insert', tagid(tagOrId), index, string  end  def itemcget(tagOrId, option)    case option    when 'dash', 'activedash', 'disableddash'      conf = tk_send('itemcget', tagid(tagOrId), "-#{option}")      if conf =~ /^[0-9]/	list(conf)      else	conf      end    when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile'      tk_send 'itemcget', tagid(tagOrId), "-#{option}"    else      tk_tcl2ruby tk_send 'itemcget', tagid(tagOrId), "-#{option}"    end  end  def itemconfigure(tagOrId, key, value=None)    if key.kind_of? Hash      if ( key['font'] || key['kanjifont'] \	  || key['latinfont'] || key['asciifont'] )	tagfont_configure(tagOrId, key.dup)      else	tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key)      end    else      if ( key == 'font' || key == 'kanjifont' \	  || key == 'latinfont' || key == 'asciifont' )	tagfont_configure(tagid(tagOrId), {key=>value})      else	tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value      end    end  end#  def itemconfigure(tagOrId, key, value=None)#    if key.kind_of? Hash#      tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key)#    else#      tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value#    end#  end#  def itemconfigure(tagOrId, keys)#    tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys)#  end  def itemconfiginfo(tagOrId, key=nil)    if key      case key      when 'dash', 'activedash', 'disableddash'	conf = tk_split_simplelist(tk_send 'itemconfigure', 				   tagid(tagOrId), "-#{key}")	if conf[3] && conf[3] =~ /^[0-9]/	  conf[3] = list(conf[3])	end	if conf[4] && conf[4] =~ /^[0-9]/	  conf[4] = list(conf[4])	end      when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile'	conf = tk_split_simplelist(tk_send 'itemconfigure', 				   tagid(tagOrId), "-#{key}")      else	conf = tk_split_list(tk_send 'itemconfigure', 			     tagid(tagOrId), "-#{key}")      end      conf[0] = conf[0][1..-1]      conf    else      tk_split_simplelist(tk_send 'itemconfigure', 			  tagid(tagOrId)).collect{|conflist|	conf = tk_split_simplelist(conflist)	conf[0] = conf[0][1..-1]	case conf[0]	when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile'	when 'dash', 'activedash', 'disableddash'	  if conf[3] && conf[3] =~ /^[0-9]/	    conf[3] = list(conf[3])	  end	  if conf[4] && conf[4] =~ /^[0-9]/	    conf[4] = list(conf[4])	  end	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  end  def lower(tag, below=None)    tk_send 'lower', tagid(tag), tagid(below)  end  def move(tag, x, y)    tk_send 'move', tagid(tag), x, y  end  def postscript(keys)    tk_send "postscript", *hash_kv(keys)  end  def raise(tag, above=None)    tk_send 'raise', tagid(tag), tagid(above)  end  def scale(tag, x, y, xs, ys)    tk_send 'scale', tagid(tag), x, y, xs, ys  end  def scan_mark(x, y)    tk_send 'scan', 'mark', x, y  end  def scan_dragto(x, y)    tk_send 'scan', 'dragto', x, y  end  def select(mode, *args)    tk_send 'select', mode, *args  end  def select_adjust(tagOrId, index)    select('adjust', tagid(tagOrId), index)  end  def select_clear    select('clear')  end  def select_from(tagOrId, index)    select('from', tagid(tagOrId), index)  end  def select_item    select('item')  end  def select_to(tagOrId, index)    select('to', tagid(tagOrId), index)  end  def itemtype(tag)    TkcItem.type2class(tk_send 'type', tagid(tag))  endendmodule TkcTagAccess  include TkComm  include TkTreatTagFont  def addtag(tag)    @c.addtag(tag, 'with', @id)  end  def bbox    @c.bbox(@id)  end  def bind(seq, cmd=Proc.new, args=nil)    @c.itembind @id, seq, cmd, args  end  def bindinfo(seq=nil)    @c.itembindinfo @id, seq  end  def cget(option)    @c.itemcget @id, option  end  def configure(key, value=None)    @c.itemconfigure @id, key, value  end#  def configure(keys)#    @c.itemconfigure @id, keys#  end  def configinfo(key=nil)    @c.itemconfiginfo @id, key  end  def coords(*args)    @c.coords @id, *args  end  def dchars(first, last=None)    @c.dchars @id, first, last  end  def dtag(tag_to_del=None)    @c.dtag @id, tag_to_del  end  def find    @c.find 'withtag', @id  end  alias list find  def focus    @c.itemfocus @id  end  def gettags    @c.gettags @id  end  def icursor(index)    @c.icursor @id, index  end  def index(index)    @c.index @id, index  end  def insert(beforethis, string)    @c.insert @id, beforethis, string  end  def lower(belowthis=None)    @c.lower @id, belowthis  end  def move(xamount, yamount)    @c.move @id, xamount, yamount  end  def raise(abovethis=None)    @c.raise @id, abovethis  end  def scale(xorigin, yorigin, xscale, yscale)    @c.scale @id, xorigin, yorigin, xscale, yscale  end  def select_adjust(index)    @c.select('adjust', @id, index)  end  def select_from(index)    @c.select('from', @id, index)  end  def select_to(index)    @c.select('to', @id, index)  end  def itemtype

⌨️ 快捷键说明

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