Discussion:
Tk bindings!
(too old to reply)
Simon Bachmann
2004-01-07 20:09:14 UTC
Permalink
Hi!

I've got a question/problem about tk bindigs (`bind' command).

Suppose you are writing an editor in tcl/tk which should have, of
course, braces highligthing ( --> when you close a ),] or } the
openening brace blinks).
To implement that you use someting similar:

bind .textwidget parenright
{command_to_search_and_blink_corresponding_brace...}
bind .textwidget braceright
{command_to_search_and_blink_corresponding_brace...}
bind .textwidget bracketright
{command_to_search_and_blink_corresponding_brace...}

....and all works fine.

Then your editor is used by a user with a keyboard layout where to
insert {}'s and []'s he needs to press the `Alt-Gr' key (Keysym on my
system: Mode_switch) together with anoter key. Your brace highligthin
won't work!!!
In facts, pressing AltGr with anoter key, the event that is generated is
this key to be pressed alone, and not the combination. Here's an example
for more clairity:
to insert a '}' you need to press AltGr-$. Pressing this key combination
the <KeyPress-$> event occurs, and not <KeyPress-braceright> (but the
inserted character is '}' and not '$')!

Is that a bug?

Thanks...
Bryan Oakley
2004-01-07 21:53:06 UTC
Permalink
Post by Simon Bachmann
Then your editor is used by a user with a keyboard layout where to
insert {}'s and []'s he needs to press the `Alt-Gr' key (Keysym on my
system: Mode_switch) together with anoter key. Your brace highligthin
won't work!!!
In facts, pressing AltGr with anoter key, the event that is generated is
this key to be pressed alone, and not the combination. Here's an example
to insert a '}' you need to press AltGr-$. Pressing this key combination
the <KeyPress-$> event occurs, and not <KeyPress-braceright> (but the
inserted character is '}' and not '$')!
Is that a bug?
I would have to say no, it's not a bug. Making a binding says "when the
user presses this key, do this action". By your own description the user
isn't pressing that particular key.

What you want probably isn't "when the user presses }, do this" but
rather "when the user inserts a } do this". They can enter a "}" in
several ways -- pressing }, pressing AltGr-$, pasting a } with
control-v, etc.

For that you would probaby want to override the widget command and
examine every insert. Another way to potentially solve your problem is
to bind to <Any-KeyPress> and check %A for one of the special
characters. The former would let your brace-matching work on paste, the
latter would only work for keyboard presses that insert those particular
characters.
Simon Bachmann
2004-01-09 05:08:03 UTC
Permalink
Post by Bryan Oakley
Post by Simon Bachmann
Then your editor is used by a user with a keyboard layout where to
insert {}'s and []'s he needs to press the `Alt-Gr' key (Keysym on my
system: Mode_switch) together with anoter key. Your brace highligthin
won't work!!!
In facts, pressing AltGr with anoter key, the event that is generated is
this key to be pressed alone, and not the combination. Here's an example
to insert a '}' you need to press AltGr-$. Pressing this key combination
the <KeyPress-$> event occurs, and not <KeyPress-braceright> (but the
inserted character is '}' and not '$')!
Is that a bug?
I would have to say no, it's not a bug. Making a binding says "when the
user presses this key, do this action". By your own description the user
isn't pressing that particular key.
Well, I expected that the 'Alt Gr' key behaves something like the shift
keys: if you press <Shift-a>, event 'A' occurs, not 'a'; <Shift-8>
generates event '(' not '8' ....

However, thanks for your help!

Continue reading on narkive:
Loading...