From: matz@... (Yukihiro Matsumoto) Date: 1997-08-01T13:17:35+09:00 Subject: [ruby-list:3556] Re: text tag (ruby/tk) まつもと ゆきひろです In message "[ruby-list:3544] text tag (ruby/tk)" on 97/07/31, Noritsugu Nakamura writes: |中村です。 | |また、分からないことが出てきてしまいました。 |ruby/tk の Text Widget での tag の使用法に |ついてです。 | |例えば、以下と同じプログラムを書きたいのですが、 |どう書けばよいのでしょうか? | |#!/usr/local/bin/wish4.2 | |text .t -width 30 -height 10 |pack .t | |.t tag configure big -font -*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-* | |.t insert end "Text Tag\n" big |.t insert end "normal size\n" いやあ,バグってました.添付のパッチを当てた後では以下のよう になります. #!/usr/local/bin/ruby require "tk" text = TkText.new { width 30 height 10 pack } big = TkTextTag.new(text,"font" => "-*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*") text.insert "end", "Text Tag\n", big text.insert "end", "normal size\n" Tk.mainloop -- --- lib/tktext.rb~ Sun Jul 27 00:27:59 1997 +++ lib/tktext.rb Fri Aug 1 13:06:24 1997 @@ -26,6 +26,5 @@ end - def _addtag(cmd) - @cmdtbl.push id + def _addtag(name, obj) + @tags[name] = obj end - private :_addcmd, :_addtag def tag_names @@ -88,3 +87,3 @@ $tk_text_tag = 'tag0000' - def initialize(parent) + def initialize(parent, keys=nil) if not parent.kind_of?(TkText) @@ -93,5 +92,5 @@ @t = parent - @path = parent.path - @id = $tk_text_tag + @path = @id = $tk_text_tag $tk_text_tag = $tk_text_tag.succ + tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) @t._addtag id, self @@ -103,7 +102,7 @@ def add(*index) - tk_call path, 'tag', 'add', @id, *index + tk_call @t.path, 'tag', 'add', @id, *index end - def configure(slot, value) - tk_call path, 'tag', 'configure', id, "-#{slot}", value + def configure(keys) + tk_call @t.path, 'tag', 'configure', @id, *hash_kv(keys) end @@ -112,3 +111,3 @@ id = install_cmd(cmd) - tk_call path, 'tag', 'bind', tag, "<#{seq}>", id + tk_call @t, 'tag', 'bind', tag, "<#{seq}>", id @t._addcmd cmd @@ -117,3 +116,3 @@ def lower(below=None) - tk_call path, 'tag', 'lower', below + tk_call @t.path, 'tag', 'lower', below end @@ -121,3 +120,3 @@ def destroy - tk_call path, 'tag', 'delete', @id + tk_call @t.path, 'tag', 'delete', @id end @@ -132,6 +131,5 @@ @t = parent - @path = parent.path - @id = $tk_text_mark + @path = @id = $tk_text_mark $tk_text_mark = $tk_text_mark.succ - tk_call @t, 'set', @id, index + tk_call @t.path, 'set', @id, index @t._addtag id, self @@ -143,3 +141,3 @@ def set(where) - tk_call path, 'mark', 'unset', @id, where + tk_call @t.path, 'mark', 'unset', @id, where end @@ -147,3 +145,3 @@ def unset - tk_call path, 'mark', 'unset', @id + tk_call @t.path, 'mark', 'unset', @id end @@ -158,5 +156,4 @@ @t = parent - @path = parent.path - @index = index - tk_call @path, 'window', 'create', index, *args + @path = @index = index + tk_call @t.path, 'window', 'create', index, *args end @@ -164,3 +161,3 @@ def configure(slot, value) - tk_call path, 'window', 'configure', @index, "-#{slot}", value + tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value end