📄 tk.rb
字号:
end def TkWinfo.screenmmheight(window) number(tk_call('winfo', 'screenmmheight', window.path)) end def winfo_screenmmheight TkWinfo.screenmmheight self end def TkWinfo.screenmmwidth(window) number(tk_call('winfo', 'screenmmwidth', window.path)) end def winfo_screenmmwidth TkWinfo.screenmmwidth self end def TkWinfo.screenvisual(window) tk_call 'winfo', 'screenvisual', window.path end def winfo_screenvisual TkWinfo.screenvisual self end def TkWinfo.screenwidth(window) number(tk_call('winfo', 'screenwidth', window.path)) end def winfo_screenwidth TkWinfo.screenwidth self end def TkWinfo.server(window) tk_call 'winfo', 'server', window.path end def winfo_server TkWinfo.server self end def TkWinfo.toplevel(window) window(tk_call('winfo', 'toplevel', window.path)) end def winfo_toplevel TkWinfo.toplevel self end def TkWinfo.visual(window) tk_call 'winfo', 'visual', window.path end def winfo_visual TkWinfo.visual self end def TkWinfo.visualid(window) tk_call 'winfo', 'visualid', window.path end def winfo_visualid TkWinfo.visualid self end def TkWinfo.visualsavailable(window, includeids=false) if includeids v = tk_call('winfo', 'visualsavailable', window.path, "includeids") else v = tk_call('winfo', 'visualsavailable', window.path) end list(v) end def winfo_visualsavailable(includeids=false) TkWinfo.visualsavailable self, includeids end def TkWinfo.vrootheight(window) number(tk_call('winfo', 'vrootheight', window.path)) end def winfo_vrootheight TkWinfo.vrootheight self end def TkWinfo.vrootwidth(window) number(tk_call('winfo', 'vrootwidth', window.path)) end def winfo_vrootwidth TkWinfo.vrootwidth self end def TkWinfo.vrootx(window) number(tk_call('winfo', 'vrootx', window.path)) end def winfo_vrootx TkWinfo.vrootx self end def TkWinfo.vrooty(window) number(tk_call('winfo', 'vrooty', window.path)) end def winfo_vrooty TkWinfo.vrooty self end def TkWinfo.width(window) number(tk_call('winfo', 'width', window.path)) end def winfo_width TkWinfo.width self end def TkWinfo.x(window) number(tk_call('winfo', 'x', window.path)) end def winfo_x TkWinfo.x self end def TkWinfo.y(window) number(tk_call('winfo', 'y', window.path)) end def winfo_y TkWinfo.y self end def TkWinfo.viewable(window) bool(tk_call 'winfo', 'viewable', window.path) end def winfo_viewable TkWinfo.viewable self end def TkWinfo.pointerx(window) number(tk_call('winfo', 'pointerx', window.path)) end def winfo_pointerx TkWinfo.pointerx self end def TkWinfo.pointery(window) number(tk_call('winfo', 'pointery', window.path)) end def winfo_pointery TkWinfo.pointery self end def TkWinfo.pointerxy(window) list(tk_call('winfo', 'pointerxy', window.path)) end def winfo_pointerxy TkWinfo.pointerxy self endendmodule TkPack include Tk extend Tk def configure(win, *args) if args[-1].kind_of?(Hash) keys = args.pop end wins = [win.epath] for i in args wins.push i.epath end tk_call "pack", 'configure', *(wins+hash_kv(keys)) end def forget(*args) tk_call 'pack', 'forget' *args end def info(slave) ilist = list(tk_call('pack', 'info', slave.epath)) info = {} while key = ilist.shift info[key[1..-1]] = ilist.shift end return info end def propagate(master, bool=None) if bool == None bool(tk_call('pack', 'propagate', master.epath)) else tk_call('pack', 'propagate', master.epath, bool) end end def slaves(master) list(tk_call('pack', 'slaves', master.epath)) end module_function :configure, :forget, :info, :propagate, :slavesendmodule TkGrid include Tk extend Tk def bbox(*args) list(tk_call('grid', 'bbox', *args)) end def configure(widget, *args) if args[-1].kind_of?(Hash) keys = args.pop end wins = [widget.epath] for i in args wins.push i.epath end tk_call "grid", 'configure', *(wins+hash_kv(keys)) end def columnconfigure(master, index, args) tk_call "grid", 'columnconfigure', master, index, *hash_kv(args) end def rowconfigure(master, index, args) tk_call "grid", 'rowconfigure', master, index, *hash_kv(args) end def columnconfiginfo(master, index, slot=nil) if slot tk_call 'grid', 'columnconfigure', master, index, "-#{slot}" else ilist = list(tk_call('grid', 'columnconfigure', master, index)) info = {} while key = ilist.shift info[key[1..-1]] = ilist.shift end info end end def rowconfiginfo(master, index, slot=nil) if slot tk_call 'grid', 'rowconfigure', master, index, "-#{slot}" else ilist = list(tk_call('grid', 'rowconfigure', master, index)) info = {} while key = ilist.shift info[key[1..-1]] = ilist.shift end info end end def add(widget, *args) configure(widget, *args) end def forget(*args) tk_call 'grid', 'forget', *args end def info(slave) list(tk_call('grid', 'info', slave)) end def location(master, x, y) list(tk_call('grid', 'location', master, x, y)) end def propagate(master, bool=None) if bool == None bool(tk_call('grid', 'propagate', master.epath)) else tk_call('grid', 'propagate', master.epath, bool) end end def remove(*args) tk_call 'grid', 'remove', *args end def size(master) tk_call 'grid', 'size', master end def slaves(master, args) list(tk_call('grid', 'slaves', master, *hash_kv(args))) end module_function :bbox, :forget, :propagate, :info module_function :remove, :size, :slaves, :location module_function :configure, :columnconfigure, :rowconfigure module_function :columnconfiginfo, :rowconfiginfoendmodule TkPlace include Tk extend Tk def configure(win, slot, value=None) if slot.kind_of? Hash tk_call 'place', 'configure', win.epath, *hash_kv(slot) else tk_call 'place', 'configure', win.epath, "-#{slot}", value end end def configinfo(win, slot = nil) # for >= Tk8.4a2 ? if slot conf = tk_split_list(tk_call('place', 'configure', win.epath, "-#{slot}") ) conf[0] = conf[0][1..-1] conf else tk_split_simplelist(tk_call('place', 'configure', win.epath)).collect{|conflist| conf = tk_split_simplelist(conflist) conf[0] = conf[0][1..-1] conf } end end def forget(win) tk_call 'place', 'forget', win end def info(win) ilist = list(tk_call('place', 'info', win.epath)) info = {} while key = ilist.shift info[key[1..-1]] = ilist.shift end return info end def slaves(master) list(tk_call('place', 'slaves', master.epath)) end module_function :configure, :configinfo, :forget, :info, :slavesendmodule TkOption include Tk extend Tk def add pat, value, pri=None tk_call 'option', 'add', pat, value, pri end def clear tk_call 'option', 'clear' end def get win, name, klass tk_call 'option', 'get', win ,name, klass end def readfile file, pri=None tk_call 'option', 'readfile', file, pri end module_function :add, :clear, :get, :readfileendmodule TkTreatFont def font_configinfo ret = TkFont.used_on(self.path) if ret == nil ret = TkFont.init_widget_font(self.path, self.path, 'configure') end ret end alias fontobj font_configinfo def font_configure(slot) if (fnt = slot.delete('font')) if fnt.kind_of? TkFont return fnt.call_font_configure(self.path, self.path,'configure',slot) else latinfont_configure(fnt) if fnt end end if (ltn = slot.delete('latinfont')) latinfont_configure(ltn) if ltn end if (ltn = slot.delete('asciifont')) latinfont_configure(ltn) if ltn end if (knj = slot.delete('kanjifont')) kanjifont_configure(knj) if knj end tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {} self end def latinfont_configure(ltn, keys=nil) fobj = fontobj if ltn.kind_of? TkFont conf = {} ltn.latin_configinfo.each{|key,val| conf[key] = val} if keys fobj.latin_configure(conf.update(keys)) else fobj.latin_configure(conf) end else fobj.latin_replace(ltn) end end alias asciifont_configure latinfont_configure def kanjifont_configure(knj, keys=nil) fobj = fontobj if knj.kind_of? TkFont conf = {} knj.kanji_configinfo.each{|key,val| conf[key] = val} if keys fobj.kanji_configure(conf.update(keys)) else fobj.kanji_configure(cond) end else fobj.kanji_replace(knj) end end def font_copy(window, tag=nil) if tag window.tagfontobj(tag).configinfo.each{|key,value| fontobj.configure(key,value) } fontobj.replace(window.tagfontobj(tag).latin_font, window.tagfontobj(tag).kanji_font) else window.fontobj.configinfo.each{|key,value| fontobj.configure(key,value) } fontobj.replace(window.fontobj.latin_font, window.fontobj.kanji_font) end end def latinfont_copy(window, tag=nil) if tag fontobj.latin_replace(window.tagfontobj(tag).latin_font) else fontobj.latin_replace(window.fontobj.latin_font) end end alias asciifont_copy latinfont_copy def kanjifont_copy(window, tag=nil) if tag fontobj.kanji_replace(window.tagfontobj(tag).kanji_font) else fontobj.kanji_replace(window.fontobj.kanji_font) end endendmodule TkTreatItemFont def __conf_cmd(idx) raise NotImplementError, "need to define `__conf_cmd'" end def __item_pathname(tagOrId) raise NotImplementError, "need to define `__item_pathname'" end private :__conf_cmd, :__item_pathname def tagfont_configinfo(tagOrId) pathname = __item_pathname(tagOrId) ret = TkFont.used_on(pathname) if ret == nil ret = TkFont.init_widget_font(pathname, self.path, __conf_cmd(0), __conf_cmd(1), tagOrId) end ret end alias tagfontobj tagfont_configinfo def tagfont_configure(tagOrId, slot) pathname = __item_pathname(tagOrId) if (fnt = slot.delete('font')) if fnt.kind_of? TkFont return fnt.call_font_configure(pathname, self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, slot) else latintagfont_configure(tagOrId, fnt) if fnt end end if (ltn = slot.delete('latinfont')) latintagfont_configure(tagOrId, ltn) if ltn end if (ltn = slot.delete('asciifont')) latintagfont_configure(tagOrId, ltn) if ltn end if (knj = slot.delete('kanjifont')) kanjitagfont_configure(tagOrId, knj) if knj end tk_call(self.path, __conf_cmd(0), __conf_cmd(1), tagOrId, *hash_kv(slot)) if slot != {} self end def latintagfont_configure(tagOrId, ltn, keys=nil) fobj = tagfontobj(tagOrId) if ltn.kind_of? TkFont conf = {} ltn.latin_configinfo.each{|key,val| conf[key] = val if val != []} if conf == {} fobj.latin_replace(ltn) fobj.latin_configure(keys) if keys elsif keys fobj.latin_configure(conf.update(keys)) else fobj.latin_configure(conf) end else fobj.latin_replace(ltn) end end alias asciitagfont_configure latintagfont_configure def kanjitagfont_configure(tagOrId, knj, keys=nil) fobj = tagfontobj(tagOrId) if knj.kind_of? TkFont conf = {} knj.kanji_configinfo.each{|key,val| conf[key] = val if val != []} if conf == {} fobj.kanji_replace(knj) fobj.kanji_configure(keys) if keys elsif keys fobj.kanji_configure(conf.update(keys)) else fobj.kanji_configure(conf) end else fobj.kanji_replace(knj) end end def tagfont_copy(tagOrId, window, wintag=nil) if wintag window.tagfontobj(wintag).configinfo.each{|key,value| tagfontobj(tagOrId).configure(key,value) } tagfontobj(tagOrId).replace(window.tagfontobj(wintag).latin_font, window.tagfontobj(wintag).kanji_font) else window.tagfont(wintag).configinfo.each{|key,value| tagfontobj(tagOrId).configure(key,value) } tagfontobj(tagOrId).replace(window.fontobj.latin_font, window.fontobj.kanji_font) end end def latintagfont_copy(tagOrId, window, wintag=nil) if wintag tagfontobj(tagOrId).latin_replace(window.tagfontobj(wintag).latin_font) else tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font) end end alias asciitagfont_copy latintagfont_copy def kanjitagfont_copy(tagOrId, window, wintag=nil) if wintag tagfontobj(tagOrId).kanji_replace(window.tagfontobj(wintag).kanji_font) else tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font) end endendclass TkObject<TkKernel include Tk include TkTreatFont include TkBindCore def path return @path end def epath return @path end def to_eval @path end def tk_send(cmd, *rest) tk_call path, cmd, *rest end private :tk_send def method_missing(id, *args) name = id.id2name case args.length when 1 configure name, args[0] when 0 begin cget name rescue fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at end else fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at end end def [](id) cget id
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -