TkEntry with { (left brace) characters

I’ve tried to boil this down to be as meaningful as possible. I’m
guessing this is a Tk issue, but since I’m using Ruby (1.8.0) I thought
I’d start here.

Type any English text character into the entry box, and the target proc
sees the character as typed (e.g. type an a and it sees an “a”, type a b
and it sees the field contains “ab”).

The exception is the “{” (left brace). Type one in and the entry box has
one “{”, but The TkVariable @myText displays it as empty (the TkComm
object sees that as an escaped character “{” ). Type a second left
brace and the entry field has 2 braces and the TkVariable @myText still
extracts an empty string.

Type a 3rd brace and now the @myText.to_s gives back 1 brace (all right
of the first 2?).

Thanks for any insight.

Mac

require ‘tk’;

def puts_KeyChar(tkcommObj);
puts ‘key release - ’ + tkcommObj.char() + ’ -’;
puts ‘entry variable - ’ + @myText.to_s + ’ -’;
end

myWindowRoot = TkRoot.new {title ‘Tk Test’};
@myText = TkVariable.new(’’);

myEntry = TkEntry.new(myWindowRoot);
myEntry.textvariable(@myText);

myEntry.pack(‘side’=>‘top’);
myEntry.bind(‘Any-KeyRelease’,proc {|tkcommObj| puts_KeyChar(tkcommObj)});

Tk.mainloop;

Hi,

···

From: Mac webrg.ruby-talk.com@Panscend.com
Subject: TkEntry with { (left brace) characters
Date: Mon, 9 Feb 2004 03:54:59 +0900
Message-ID: <C3uVb.251427$xy6.1311894@attbi_s02>

The exception is the “{” (left brace). Type one in and the entry box has
one “{”, but The TkVariable @myText displays it as empty (the TkComm
object sees that as an escaped character “{” ). Type a second left
brace and the entry field has 2 braces and the TkVariable @myText still
extracts an empty string.

Sorry. It’s a bug of TkVariable#to_s (TkComm::string).
Please use TkVariable#value instead of TkVariable#to_s.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hi,

···

From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: TkEntry with { (left brace) characters
Date: Mon, 9 Feb 2004 04:22:49 +0900
Message-ID: 20040209.042243.74736283.nagai@ai.kyutech.ac.jp

Sorry. It’s a bug of TkVariable#to_s (TkComm::string).
Please use TkVariable#value instead of TkVariable#to_s.

I committed the following patch to CVS head.
It makes TkVariable#to_s to call TkVariable#value.
At the same time, I think it will fix the bug to treat a
Tcl/Tk’s string with escaping special characters.

However, I remain ambivalence about backporting to Ruby 1.8.x.
Although the patch fixes some problems (e.g. A validatecommand
of TkEntry cannot acquire a right string when the entry box has
a string which has unbalanced braces such as “a {”), Ruby/Tk
loses backward compatibility.

An easily understandable example of incompatibility is a return
value of TkComm::Event#char. When a key event about a left brace
occurs, Ruby/Tk without the patch returns an escaped left brace
“{”. But with the patch, returns only a left brace “{”. Of cource,
it is a bug to return “{”. Though a bug, some scripts may presume
an escaped left brace.

Your comments on the patch are welcome.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Message-ID: 20040212.004101.74730738.nagai@ai.kyutech.ac.jp

I committed the following patch to CVS head.

Sorry. I forgot to attach the patch.

tk.rb-diff (9.3 KB)

···

From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: TkEntry with { (left brace) characters
Date: Thu, 12 Feb 2004 00:41:03 +0900

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hidetoshi NAGAI wrote:

Hi,

From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: TkEntry with { (left brace) characters
Date: Mon, 9 Feb 2004 04:22:49 +0900
Message-ID: 20040209.042243.74736283.nagai@ai.kyutech.ac.jp

snip

However, I remain ambivalence about backporting to Ruby 1.8.x.
Although the patch fixes some problems (e.g. A validatecommand
of TkEntry cannot acquire a right string when the entry box has
a string which has unbalanced braces such as “a {”), Ruby/Tk
loses backward compatibility.

snip

Your comments on the patch are welcome.

I don’t mind if you dont’ backport the patch. I went ahead with 1.8.1
and applied the patch (final version :slight_smile: ) to that. I figured if I was
going to recompile I’d have the next stable release. I need to retest
anyway. Might as well get caught up.

I do think that anyone that coded around the escaped left brace could be
just as surprised when they move on to a new version as they would have
been if they found it in a supposedly “same” version.

But I might not backport it just because of needing to draw a line
somewhere. How many versions back would you go with a backport? 1.8.0?
1.6.1? ??? I’d just leave well enough alone and make sure it’s documented.

Mac

Hi,

···

From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: TkEntry with { (left brace) characters
Date: Thu, 12 Feb 2004 00:45:04 +0900
Message-ID: 20040212.004502.71110787.nagai@ai.kyutech.ac.jp

Sorry. I forgot to attach the patch.

Sorry, again. The patch has some bugs.
I fixed on CVS head. Please get the newest version from CVS.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hidetoshi NAGAI wrote:

Hi,

From: Hidetoshi NAGAI nagai@ai.kyutech.ac.jp
Subject: Re: TkEntry with { (left brace) characters
Date: Thu, 12 Feb 2004 00:45:04 +0900
Message-ID: 20040212.004502.71110787.nagai@ai.kyutech.ac.jp

Sorry. I forgot to attach the patch.

Sorry, again. The patch has some bugs.
I fixed on CVS head. Please get the newest version from CVS.

Just got the patch and applied it to ruby 1.8.1 . It works well so far.
Got both my bugs and doesn’t seem to have detrimental side effects. I’ll
keep an eye on it as I continue working with it.

Thanks for the update!

Mac