diff options
Diffstat (limited to 'ext/tk/lib')
-rw-r--r-- | ext/tk/lib/tk.rb | 145 | ||||
-rw-r--r-- | ext/tk/lib/tkcanvas.rb | 8 | ||||
-rw-r--r-- | ext/tk/lib/tkentry.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tktext.rb | 8 | ||||
-rw-r--r-- | ext/tk/lib/tkvirtevent.rb | 33 |
5 files changed, 153 insertions, 43 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index a088d5c493..262adec3f2 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -1,5 +1,5 @@ # -# tk.rb - Tk interface modue using tcltklib +# tk.rb - Tk interface module using tcltklib # $Date$ # by Yukihiro Matsumoto <matz@netlab.co.jp> @@ -351,7 +351,7 @@ module TkComm end if context.kind_of? Array context = context.collect{|ev| - if context.kind_of? TkVirtualEvent + if ev.kind_of? TkVirtualEvent ev.path else ev @@ -397,8 +397,18 @@ module TkComm end } else - tk_split_list(tk_call(*what)).collect{|seq| - seq[1..-2].gsub(/></,',') + tk_split_simplelist(tk_call(*what)).collect!{|seq| + l = seq.scan(/<*[^<>]+>*/).collect!{|subseq| + case (subseq) + when /^<<[^<>]+>>$/ + TkVirtualEvent.getobj(subseq[1..-2]) + when /^<[^<>]+>$/ + subseq[1..-2] + else + subseq.split('') + end + }.flatten + (l.size == 1) ? l[0] : l } end end @@ -651,12 +661,76 @@ module TkCore end end +module TkPackage + include TkCore + extend TkPackage + + def forget(package) + tk_call('package', 'forget', package) + nil + end + + def names + tk_split_simplelist(tk_call('package', 'names')) + end + + def provide(package, version=nil) + if version + tk_call('package', 'provide', package, version) + nil + else + tk_call('package', 'provide', package) + end + end + + def present(package, version=None) + tk_call('package', 'present', package, version) + end + + def present_exact(package, version) + tk_call('package', 'present', '-exact', package, version) + end + + def require(package, version=None) + tk_call('package', 'require', package, version) + end + + def require_exact(package, version) + tk_call('package', 'require', '-exact', package, version) + end + + def versions(package) + tk_split_simplelist(tk_call('package', 'versions', package)) + end + + def vcompare(version1, version2) + Integer(tk_call('package', 'vcompare', version1, version2)) + end + + def vsatisfies(version1, version2) + bool(tk_call('package', 'vsatisfies', version1, version2)) + end +end + module Tk include TkCore extend Tk TCL_VERSION = INTERP._invoke("info", "tclversion") TK_VERSION = INTERP._invoke("set", "tk_version") + + TCL_PATCHLEVEL = INTERP._invoke("info", "patchlevel") + TK_PATCHLEVEL = INTERP._invoke("set", "tk_patchLevel") + + TCL_LIBRARY = INTERP._invoke("set", "tcl_library") + TK_LIBRARY = INTERP._invoke("set", "tk_library") + LIBRARY = INTERP._invoke("info", "library") + + TCL_PACKAGE_PATH = INTERP._invoke("set", "tcl_pkgPath") + AUTO_PATH = tk_split_simplelist(INTERP._invoke("set", "auto_path")) + + PLATFORM = Hash[*tk_split_simplelist(INTERP._eval('array get tcl_platform'))] + JAPANIZED_TK = (INTERP._invoke("info", "commands", "kanji") != "") def root @@ -680,6 +754,10 @@ module Tk tk_tcl2ruby(tk_call('focus', '-lastfor', win)) end + def Tk.strictMotif(bool=None) + bool(tk_call('set', 'tk_strictMotif', bool)) + end + def Tk.show_kinsoku(mode='both') begin if /^8\.*/ === TK_VERSION && JAPANIZED_TK @@ -710,11 +788,11 @@ module Tk end end - def toUTF8(str,encoding) + def Tk.toUTF8(str,encoding) INTERP._toUTF8(str,encoding) end - def fromUTF8(str,encoding) + def Tk.fromUTF8(str,encoding) INTERP._fromUTF8(str,encoding) end @@ -978,6 +1056,12 @@ class TkBindTag BTagID_TBL[id]? BTagID_TBL[id]: id end + ALL = self.new + ALL.instance_eval { + @id = 'all' + BTagID_TBL[@id] = self + } + def initialize(*args) @id = Tk_BINDTAG_ID[0] Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ @@ -995,20 +1079,11 @@ class TkBindTag end class TkBindTagAll<TkBindTag - BindTagALL = [] def TkBindTagAll.new(*args) - if BindTagALL[0] - BindTagALL[0].bind(*args) if args != [] - else - new = super() - BindTagALL[0] = new - end - BindTagALL[0] - end + $stderr.puts "Warning: TkBindTagALL is obsolete. Use TkBindTag::ALL\n" - def initialize(*args) - @id = 'all' - BindTagALL[0].bind(*args) if args != [] + TkBindTag::ALL.bind(*args) if args != [] + TkBindTag::ALL end end @@ -1446,7 +1521,7 @@ module TkXIM end def useinputmethods(value=nil) - TkXIM.useinputmethods(self, value=nil) + TkXIM.useinputmethods(self, value) end def imconfigure(window, slot, value=None) @@ -2370,7 +2445,7 @@ class TkWindow<TkObject def grid_propagate(mode=nil) if mode - tk_call('grid', 'propagate', epath, bool) + tk_call('grid', 'propagate', epath, mode) else bool(tk_call('grid', 'propagate', epath)) end @@ -2507,7 +2582,7 @@ class TkWindow<TkObject def bindtags(taglist=nil) if taglist - fail unless taglist.kind_of? Array + fail ArgumentError unless taglist.kind_of? Array tk_call('bindtags', path, taglist) else list(tk_call('bindtags', path)).collect{|tag| @@ -2708,8 +2783,16 @@ class TkScale<TkWindow tk_call 'scale', path end - def get - number(tk_send('get')) + def get(x=None, y=None) + number(tk_send('get', x, y)) + end + + def coords(val=None) + tk_split_list(tk_send('coords', val)) + end + + def identify(x, y) + tk_send('identify', x, y) end def set(val) @@ -2744,8 +2827,8 @@ class TkScrollbar<TkWindow number(tk_send('fraction', x, y)) end - def identify(x=None, y=None) - tk_send('fraction', x, y) + def identify(x, y) + tk_send('identify', x, y) end def get @@ -2760,6 +2843,10 @@ class TkScrollbar<TkWindow def set(first, last) tk_send "set", first, last end + + def activate(element=None) + tk_send('activate', element) + end end class TkTextWin<TkWindow @@ -3033,12 +3120,12 @@ class TkMenu<TkWindow tk_send 'invoke', index end def insert(index, type, keys=nil) - tk_send 'add', index, type, *hash_kv(keys) + tk_send 'insert', index, type, *hash_kv(keys) end def delete(index, last=None) tk_send 'delete', index, last end - def popup(x, y, index=nil) + def popup(x, y, index=None) tk_call 'tk_popup', path, x, y, index end def post(x, y) @@ -3128,12 +3215,12 @@ class TkMenu<TkWindow end class TkMenuClone<TkMenu - def initialize(parent, type=nil) + def initialize(parent, type=None) unless parent.kind_of?(TkMenu) fail ArgumentError, "parent must be TkMenu" end @parent = parent - install_win(@parent) + install_win(@parent.path) tk_call @parent.path, 'clone', @path, type end end diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb index ff06e9305a..9b323e9cbb 100644 --- a/ext/tk/lib/tkcanvas.rb +++ b/ext/tk/lib/tkcanvas.rb @@ -172,7 +172,7 @@ class TkCanvas<TkWindow end def bbox(tagOrId, *tags) - list(tk_send('bbox', tagid(tagOrId), *tags)) + list(tk_send('bbox', tagid(tagOrId), *tags.collect{|t| tagid(t)})) end def itembind(tag, context, cmd=Proc.new, args=nil) @@ -207,7 +207,7 @@ class TkCanvas<TkWindow end def delete(*args) - tk_send 'delete', *args + tk_send 'delete', *args.collect{|t| tagid(t)} end alias remove delete @@ -375,7 +375,7 @@ class TkCanvas<TkWindow end def lower(tag, below=None) - tk_send 'lower', tagid(tag), below + tk_send 'lower', tagid(tag), tagid(below) end def move(tag, x, y) @@ -387,7 +387,7 @@ class TkCanvas<TkWindow end def raise(tag, above=None) - tk_send 'raise', tagid(tag), above + tk_send 'raise', tagid(tag), tagid(above) end def scale(tag, x, y, xs, ys) diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb index 6b25be376b..7af3f26748 100644 --- a/ext/tk/lib/tkentry.rb +++ b/ext/tk/lib/tkentry.rb @@ -136,7 +136,7 @@ class TkEntry<TkLabel tk_send 'selection', 'from', index end def selection_present() - tk_send('selection', 'present') == 1 + bool(tk_send('selection', 'present')) end def selection_range(s, e) tk_send 'selection', 'range', s, e diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index bb3d537bc4..51b5d82b60 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -189,6 +189,14 @@ class TkText<TkTextWin } end + def mark_next(index) + tagid2obj(tk_send('mark', 'next', index)) + end + + def mark_previous(index) + tagid2obj(tk_send('mark', 'previous', index)) + end + def window_names tk_send('window', 'names').collect{|elt| tagid2obj(elt) diff --git a/ext/tk/lib/tkvirtevent.rb b/ext/tk/lib/tkvirtevent.rb index b31b99062f..d3721e362e 100644 --- a/ext/tk/lib/tkvirtevent.rb +++ b/ext/tk/lib/tkvirtevent.rb @@ -7,12 +7,27 @@ require 'tk' class TkVirtualEvent<TkObject extend Tk - TkVirturlEventID = [0] - TkVirturlEventTBL = {} + TkVirtualEventID = [0] + TkVirtualEventTBL = {} + + class PreDefVirtEvent<self + def initialize(event) + @path = @id = event + TkVirtualEvent::TkVirtualEventTBL[@id] = self + end + end def TkVirtualEvent.getobj(event) - obj = TkVirturlEventTBL[event] - obj ? obj : event + obj = TkVirtualEventTBL[event] + if obj + obj + else + if tk_call('event', 'info').index("<#{event}>") + PreDefVirtEvent.new(event) + else + fail ArgumentError, "undefined virtual event '<#{event}>'" + end + end end def TkVirtualEvent.info @@ -22,8 +37,8 @@ class TkVirtualEvent<TkObject end def initialize(*sequences) - @path = @id = format("<VirtEvent%.4d>", TkVirturlEventID[0]) - TkVirturlEventID[0] += 1 + @path = @id = format("<VirtEvent%.4d>", TkVirtualEventID[0]) + TkVirtualEventID[0] += 1 add(*sequences) end @@ -31,7 +46,7 @@ class TkVirtualEvent<TkObject if sequences != [] tk_call('event', 'add', "<#{@id}>", *(sequences.collect{|seq| "<#{tk_event_sequence(seq)}>"}) ) - TkVirturlEventTBL[@id] = self + TkVirtualEventTBL[@id] = self end self end @@ -39,11 +54,11 @@ class TkVirtualEvent<TkObject def delete(*sequences) if sequences == [] tk_call('event', 'delete', "<#{@id}>") - TkVirturlEventTBL[@id] = nil + TkVirtualEventTBL[@id] = nil else tk_call('event', 'delete', "<#{@id}>", *(sequences.collect{|seq| "<#{tk_event_sequence(seq)}>"}) ) - TkVirturlEventTBL[@id] = nil if info == [] + TkVirtualEventTBL[@id] = nil if info == [] end self end |