From: Paul on
Hi,

I'm using the entry widget, and what I want to do is when the user
presses '{' I want to automatically insert a '}' character in the
position following the typed in '{' character, and position the cursor
between the braces.

So far I've tried:

(1) bind .myentry <leftbrace> {.cmd insert insert \}}, for this I get
braces in the wrong order, i.e. "}{"

(2) bind .myentry <leftbrace> {.cmd insert insert \{ \}}, for this I
get "{}{", so that would work if I could consume the initial '{'
keypress, i.e. not let it get through to the entry widget.

Any help appreciated,

Paul.



From: Colin Macleod on
Paul <pault.eg(a)googlemail.com> wrote in news:6d7c0559-2672-4220-98d6-
15ae7ef8169c(a)c22g2000vbb.googlegroups.com:
>
> (2) bind .myentry <leftbrace> {.cmd insert insert \{ \}}, for this I
> get "{}{", so that would work if I could consume the initial '{'
> keypress, i.e. not let it get through to the entry widget.
>
You can fix this version by adding a break to prevent further processing of
the keystroke, ie. (not tested):
bind .myentry <leftbrace> {.cmd insert insert \{ \}; break}
From: Paul on
On May 31, 9:49 am, Colin Macleod <colin.macl...(a)tesco.dot.net.nospam>
wrote:

> You can fix this version by adding a break to prevent further processing of
> the keystroke, ie. (not tested):
> bind .myentry <leftbrace> {.cmd insert insert \{ \}; break}

Thanks, that works.

Now all I've got to do is move the cursor. I can move it by:

..myentry icursor $newPos

The newPos variable needs to be set to current position + 1, so that
it's between the braces, but I can't find how to get the current
position. I'm sure it's there somewhere, just can't see it....
From: Uwe Klein on
Paul wrote:
> On May 31, 9:49 am, Colin Macleod <colin.macl...(a)tesco.dot.net.nospam>
> wrote:
>
>
>>You can fix this version by adding a break to prevent further processing of
>>the keystroke, ie. (not tested):
>>bind .myentry <leftbrace> {.cmd insert insert \{ \}; break}
>
>
> Thanks, that works.
>
> Now all I've got to do is move the cursor. I can move it by:
>
> .myentry icursor $newPos
>
> The newPos variable needs to be set to current position + 1, so that
> it's between the braces, but I can't find how to get the current
> position. I'm sure it's there somewhere, just can't see it....

entry .en; pack .en

bind .en <leftbrace> {
event generate .en <rightbrace>
event generate .en <Left>
}

uwe
From: Donal K. Fellows on
On 31/05/2010 11:04, Paul wrote:
> Now all I've got to do is move the cursor. I can move it by:
>
> .myentry icursor $newPos
>
> The newPos variable needs to be set to current position + 1, so that
> it's between the braces, but I can't find how to get the current
> position. I'm sure it's there somewhere, just can't see it....

The current position is returned by:

.myentry index insert

Donal.