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

📄 tk.rb

📁 ruby的源代码
💻 RB
📖 第 1 页 / 共 5 页
字号:
  end  def []=(id, val)    configure id, val  end  def cget(slot)    case slot    when 'text', 'label', 'show', 'data', 'file'      tk_call path, 'cget', "-#{slot}"    else      tk_tcl2ruby tk_call path, 'cget', "-#{slot}"    end  end  def configure(slot, value=None)    if slot.kind_of? Hash      if (slot['font'] || slot['kanjifont'] ||	  slot['latinfont'] || slot['asciifont'] )	font_configure(slot.dup)      else	tk_call path, 'configure', *hash_kv(slot)      end    else      if (slot == 'font' || slot == 'kanjifont' ||	  slot == 'latinfont' || slot == 'asciifont')	if value == None	  fontobj	else	  font_configure({slot=>value})	end      else	tk_call path, 'configure', "-#{slot}", value      end    end  end  def configure_cmd(slot, value)    configure slot, install_cmd(value)  end  def configinfo(slot = nil)    if slot == 'font' || slot == 'kanjifont'      fontobj    else      if slot	case slot	when 'text', 'label', 'show', 'data', 'file'	  conf = tk_split_simplelist(tk_send('configure', "-#{slot}") )	else	  conf = tk_split_list(tk_send('configure', "-#{slot}") )	end	conf[0] = conf[0][1..-1]	conf      else	ret = tk_split_simplelist(tk_send('configure') ).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	}	fontconf = ret.assoc('font')	if fontconf	  ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}	  fontconf[4] = fontobj	  ret.push(fontconf)	else	  ret	end      end    end  end  def event_generate(context, keys=nil)    if keys      tk_call('event', 'generate', path, 	      "<#{tk_event_sequence(context)}>", *hash_kv(keys))    else      tk_call('event', 'generate', path, "<#{tk_event_sequence(context)}>")    end  end  def tk_trace_variable(v)    unless v.kind_of?(TkVariable)      fail ArgumentError, format("requires TkVariable given %s", v.type)    end    v  end  private :tk_trace_variable  def destroy    tk_call 'trace', 'vdelete', @tk_vn, 'w', @var_id if @var_id  endendclass TkWindow<TkObject  extend TkBindCore  def initialize(parent=nil, keys=nil)    install_win(if parent then parent.path end)    if self.method(:create_self).arity == 0      p 'create_self has no arg' if $DEBUG      create_self      if keys	# tk_call @path, 'configure', *hash_kv(keys)	configure(keys)      end    else      p 'create_self has an arg' if $DEBUG      fontkeys = {}      if keys	keys = keys.dup	['font', 'kanjifont', 'latinfont', 'asciifont'].each{|key|	  fontkeys[key] = keys.delete(key) if keys.key?(key)	}      end      create_self(keys)      font_configure(fontkeys) unless fontkeys.empty?    end  end  def create_self  end  private :create_self  def pack(keys = nil)    tk_call 'pack', epath, *hash_kv(keys)    self  end  def unpack    tk_call 'pack', 'forget', epath    self  end  alias pack_forget unpack  def pack_config(slot, value=None)    if slot.kind_of? Hash      tk_call 'pack', 'configure', epath, *hash_kv(slot)    else      tk_call 'pack', 'configure', epath, "-#{slot}", value    end  end  def pack_info()    ilist = list(tk_call('pack', 'info', epath))    info = {}    while key = ilist.shift      info[key[1..-1]] = ilist.shift    end    return info  end  def pack_propagate(mode = nil)    if mode      tk_call('pack', 'propagate', epath, mode)    else      bool(tk_call('pack', 'propagate', epath))    end  end  def pack_slaves()    list(tk_call('pack', 'slaves', epath))  end  def grid(keys = nil)    tk_call 'grid', epath, *hash_kv(keys)    self  end  def ungrid    tk_call 'grid', 'forget', epath    self  end  alias grid_forget ungrid  def grid_bbox(*args)    list(tk_call('grid', 'bbox', epath, *args))  end  def grid_config(slot, value=None)    if slot.kind_of? Hash      tk_call 'grid', 'configure', epath, *hash_kv(slot)    else      tk_call 'grid', 'configure', epath, "-#{slot}", value    end  end  def grid_columnconfig(index, keys)    tk_call('grid', 'columnconfigure', epath, index, *hash_kv(keys))  end  def grid_rowconfig(index, keys)    tk_call('grid', 'rowconfigure', epath, index, *hash_kv(keys))  end  def grid_columnconfiginfo(index, slot=nil)    if slot      tk_call('grid', 'columnconfigure', epath, index, "-#{slot}")    else      ilist = list(tk_call('grid', 'columnconfigure', epath, index))      info = {}      while key = ilist.shift	info[key[1..-1]] = ilist.shift      end      info    end  end  def grid_rowconfiginfo(index, slot=nil)    if slot      tk_call('grid', 'rowconfigure', epath, index, "-#{slot}")    else      ilist = list(tk_call('grid', 'rowconfigure', epath, index))      info = {}      while key = ilist.shift	info[key[1..-1]] = ilist.shift      end      info    end  end  def grid_info()    list(tk_call('grid', 'info', epath))  end  def grid_location(x, y)    list(tk_call('grid', 'location', epath, x, y))  end  def grid_propagate(mode=nil)    if mode      tk_call('grid', 'propagate', epath, mode)    else      bool(tk_call('grid', 'propagate', epath))    end  end  def grid_remove()    tk_call 'grid', 'remove', epath  end  def grid_size()    tk_call 'grid', 'size', epath  end  def grid_slaves(args)    list(tk_call('grid', 'slaves', epath, *hash_kv(args)))  end  def place(keys = nil)    tk_call 'place', epath, *hash_kv(keys)    self  end  def unplace    tk_call 'place', 'forget', epath    self  end  alias place_forget unplace  def place_config(slot, value=None)    if slot.kind_of? Hash      tk_call 'place', 'configure', epath, *hash_kv(slot)    else      tk_call 'place', 'configure', epath, "-#{slot}", value    end  end  def place_configinfo(slot = nil)    # for >= Tk8.4a2 ?    if slot      conf = tk_split_list(tk_call('place', 'configure', epath, "-#{slot}") )      conf[0] = conf[0][1..-1]      conf    else      tk_split_simplelist(tk_call('place', 				  'configure', epath)).collect{|conflist|	conf = tk_split_simplelist(conflist)	conf[0] = conf[0][1..-1]	conf      }    end  end  def place_info()    ilist = list(tk_call('place', 'info', epath))    info = {}    while key = ilist.shift      info[key[1..-1]] = ilist.shift    end    return info  end  def place_slaves()    list(tk_call('place', 'slaves', epath))  end  def focus(force=false)    if force      tk_call 'focus', '-force', path    else      tk_call 'focus', path    end    self  end  def grab(*args)    if !args or args.length == 0      tk_call 'grab', 'set', path    elsif args.length == 1      case args[0]      when 'global'	return(tk_call 'grab', 'set', '-global', path)      when 'release'	return(tk_call 'grab', 'release', path)      else	val = tk_call('grab', args[0], path)      end      case args[0]      when 'current'	return window(val)      when 'status'	return val      end    else      fail ArgumentError, 'wrong # of args'    end  end  def lower(below=None)    tk_call 'lower', epath, below    self  end  def raise(above=None)    tk_call 'raise', epath, above    self  end  def command(cmd=Proc.new)    configure_cmd 'command', cmd  end  def colormodel model=None    tk_call 'tk', 'colormodel', path, model    self  end  def destroy    tk_call 'destroy', epath    if @cmdtbl      for id in @cmdtbl	uninstall_cmd id      end    end    uninstall_win  end  def wait_visibility    tk_call 'tkwait', 'visibility', path  end  alias wait wait_visibility  def wait_destroy    tk_call 'tkwait', 'window', epath  end  def bindtags(taglist=nil)    if taglist      fail ArgumentError unless taglist.kind_of? Array      tk_call('bindtags', path, taglist)    else      list(tk_call('bindtags', path)).collect{|tag|	if tag.kind_of?(String) 	  if cls = WidgetClassNames[tag]	    cls	  elsif btag = TkBindTag.id2obj(tag)	    btag	  else	    tag	  end	else	  tag	end      }    end  endendclass TkRoot<TkWindow  include Wm  ROOT = []  def TkRoot.new    return ROOT[0] if ROOT[0]    new = super    ROOT[0] = new    Tk_WINDOWS["."] = new  end  WidgetClassName = 'Tk'.freeze  WidgetClassNames[WidgetClassName] = self  def self.to_eval    WidgetClassName  end  def create_self    @path = '.'  end  def path    "."  endendclass TkToplevel<TkWindow  include Wm  WidgetClassName = 'Toplevel'.freeze  WidgetClassNames[WidgetClassName] = self  def self.to_eval    WidgetClassName  end################# old version#  def initialize(parent=nil, screen=nil, classname=nil, keys=nil)#    if screen.kind_of? Hash#      keys = screen.dup#    else#      @screen = screen#    end#    @classname = classname#    if keys.kind_of? Hash#      keys = keys.dup#      @classname = keys.delete('classname') if keys.key?('classname')#      @colormap  = keys.delete('colormap')  if keys.key?('colormap')#      @container = keys.delete('container') if keys.key?('container')#      @screen    = keys.delete('screen')    if keys.key?('screen')#      @use       = keys.delete('use')       if keys.key?('use')#      @visual    = keys.delete('visual')    if keys.key?('visual')#    end#    super(parent, keys)#  end##  def create_self#    s = []#    s << "-class"     << @classname if @classname#    s << "-colormap"  << @colormap  if @colormap#    s << "-container" << @container if @container#    s << "-screen"    << @screen    if @screen #    s << "-use"       << @use       if @use#    s << "-visual"    << @visual    if @visual#    tk_call 'toplevel', @path, *s#  end#################  def initialize(parent=nil, screen=nil, classname=nil, keys=nil)    if screen.kind_of? Hash      keys = screen    else      @screen = screen    end    @classname = classname    if keys.kind_of? Hash      if keys.key?('classname')	keys = keys.dup	keys['class'] = keys.delete('classname')      end      @classname = keys['class']      @colormap  = keys['colormap']      @container = keys['container']      @screen    = keys['screen']      @use       = keys['use']      @visual    = keys['visual']    end    super(parent, keys)  end  def create_self(keys)    if keys and keys != None      tk_call 'toplevel', @path, *hash_kv(keys)    else      tk_call 'toplevel', @path    end  end  def specific_class    @classname  endendclass TkFrame<TkWindow  WidgetClassName = 'Frame'.freeze  WidgetClassNames[WidgetClassName] = self  def self.to_eval    WidgetClassName  end################# old version#  def initialize(parent=nil, keys=nil)#    if keys.kind_of? Hash#      keys = keys.dup#      @classname = keys.delete('classname') if keys.key?('classname')#      @colormap  = keys.delete('colormap')  if keys.key?('colormap')#      @container = keys.delete('container') if keys.key?('container')#      @visual    = keys.delete('visual')    if keys.key?('visual')#    end#    super(parent, keys)#  end##  def create_self#    s = []#    s << "-class"     << @classname if @classname#    s << "-colormap"  << @colormap  if @colormap#    s << "-container" << @container if @container#    s << "-visual"    << @visual    if @visual#    tk_call 'frame', @path, *s#  end#################  def initialize(parent=nil, keys=nil)    if keys.kind_of? Hash      if keys.key?('classname')	keys = keys.dup	keys['class'] = keys.delete('classname')      end      @classname = keys['class']      @colormap  = keys['colormap']      @container = keys['container']      @visual    = keys['visual']    end    super(parent, keys)  end  def create_self(keys)    if keys and keys != None      tk_call 'frame', @path, *hash_kv(keys)    else      tk_call 'frame', @path    end  endendclass TkLabel<TkWindow  WidgetClassName = 'Label'.freeze  WidgetClassNames[WidgetClassName] = self  def self.to_eval    WidgetClassName  end  def create_self(keys)    if keys and keys != None      tk_call 'label', @path, *hash_kv(keys)    else      tk_call 'label', @path    end  end  def textvariable(v)    configure 'textvariable', tk_trace_variable(v)  endendclass TkButton<TkLabel  WidgetClassNames['Button'] = self  def TkButton.to_eval    'Button' 

⌨️ 快捷键说明

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