Bug in TkText

Ruby-1.6.7;Tcl/Tk-8.3.4
This sample code fails:

require 'tktext’
text = TkText.new
text.insert(‘end’, “abcdefghijklmno”)
tag1 = TkTextTag.new(text, ‘foreground’ => ‘red’)
tag2 = TkTextTag.new(text, ‘foreground’ => ‘blue’)
tag1.add(‘1.0’, ‘1.4’)
tag2.add(‘1.6’, ‘1.7’)
tag1.add(‘1.10’, ‘1.14’)
text.dump(‘tag’, ‘1.0’,‘1.14’)

Does anyone know a workaround?

TkText#dump method wants a block it seems. Try something like:

text.dump(‘tag’, ‘1.0’, ‘1.14’){|x| puts x}

which gives:

tagon
tag0000
1.0
tagoff
tag0000
1.4
tagon
tag0001
1.6
tagoff
tag0001
1.7
tagon
tag0000
1.1

Enjoy.

-michael

···

On Wednesday 07 August 2002 21:08, Albert Wagner wrote:

Ruby-1.6.7;Tcl/Tk-8.3.4
This sample code fails:

require 'tktext’
text = TkText.new
text.insert(‘end’, “abcdefghijklmno”)
tag1 = TkTextTag.new(text, ‘foreground’ => ‘red’)
tag2 = TkTextTag.new(text, ‘foreground’ => ‘blue’)
tag1.add(‘1.0’, ‘1.4’)
tag2.add(‘1.6’, ‘1.7’)
tag1.add(‘1.10’, ‘1.14’)
text.dump(‘tag’, ‘1.0’,‘1.14’)

Does anyone know a workaround?

++++++++++++++++++++++++++++++++++++++++++
Michael C. Libby x@ichimunki.com
public key: http://www.ichimunki.com/public_key.txt
web site: http://www.ichimunki.com
++++++++++++++++++++++++++++++++++++++++++

Perhaps this would be more illustrative:

text.dump(‘tag’, ‘1.0’,‘1.14’){|x| puts x.inspect}

which gives:

[“tagon”, “tag0000”, 1.0]
[“tagoff”, “tag0000”, 1.4]
[“tagon”, “tag0001”, 1.6]
[“tagoff”, “tag0001”, 1.7]
[“tagon”, “tag0000”, 1.1]

I don’t understand the final tagon there, it should say ‘1.10’, but has
been converted to a numeric type which is then showing only single digit
precision. Unfortunately this is wrong, because the numbers are not
decimal values. Simply extending the precision won’t help.

This could be an easy enough bug to track down, but I’m not seeing anything
pop out at me that would indicate how to fix this.

-michael

···

On Wednesday 07 August 2002 22:47, michael libby wrote:

TkText#dump method wants a block it seems. Try something like:
text.dump(‘tag’, ‘1.0’, ‘1.14’){|x| puts x}

++++++++++++++++++++++++++++++++++++++++++
Michael C. Libby x@ichimunki.com
public key: http://www.ichimunki.com/public_key.txt
web site: http://www.ichimunki.com
++++++++++++++++++++++++++++++++++++++++++

> TkText#dump method wants a block it seems. Thanks, Michael. I'll try that. I also seemed to fix working without a block by changing a statement in the dump method. I changed the argument of the single statement in the --- when 'tagoff' --- from sel to val. Sorry, but I can't give an accurate line number at the moment as the code is full of debugging statements.

def dump(type_info, *index, &block)

when 'tagoff’
result.push tk_tcl2ruby(val) #sel)

In my sample:

p text.dump(‘tag’, ‘1.0’,‘1.14’)

prints:

[[“tagon”, “tag0000”, “1.0”], [“tagoff”, “tag0000”, “1.4”], [“tagon”,
“tag0001”, “1.6”], [“tagoff”, “tag0001”, “1.7”], [“tagon”, “tag0000”,
“1.10”]]

What version of Ruby and Tcl/Tk are you using?

···

On Wednesday 07 August 2002 10:47 pm, michael libby wrote:

to val. Sorry, but I can’t give an accurate line number at the moment
as the code is full of debugging statements.

def dump(type_info, *index, &block)

when 'tagoff’
result.push tk_tcl2ruby(val) #sel)

The line that needs to be changed is line 415 by my count.

In my sample:

p text.dump(‘tag’, ‘1.0’,‘1.14’)

prints:

[[“tagon”, “tag0000”, “1.0”], [“tagoff”, “tag0000”, “1.4”], [“tagon”,
“tag0001”, “1.6”], [“tagoff”, “tag0001”, “1.7”], [“tagon”, “tag0000”,
“1.10”]]

What version of Ruby and Tcl/Tk are you using?

I get the same thing once I make the change in line 415 and adjust my test
code. I’m on Ruby 1.6.7 and Tk8.3.3 (standard Debian 3 .debs).

Interestingly, using a code block still seems to give different results.
After fixing tktext.rb, I still get decimals instead of strings with:

text.dump(‘tag’, ‘1.0’, ‘1.14’){|x| p x}

Putting the code block in an each, however:

text.dump(‘tag’, ‘1.0’, ‘1.14’).each{|x| p x}

Yields identical return values as your ‘p text.dump…’ (As expected)

  • From my reading, this seems to have something to do with adding the block
    parameter to the call to tk_send (following which lead me on something of
    a goose chase)… which means the problem with the code block may be
    outside of TkText#dump. Perhaps sending the code block outside dump can be
    avoided using a kvis.collect at the end of the method before returning the
    array.

    -michael

···

On Wednesday 07 August 2002 23:51, Albert Wagner wrote:

++++++++++++++++++++++++++++++++++++++++++
Michael C. Libby x@ichimunki.com
public key: http://www.ichimunki.com/public_key.txt
web site: http://www.ichimunki.com
++++++++++++++++++++++++++++++++++++++++++