overriding key bindings in tktext

M

Martin DeMello

Does tktext let me completely override bindings? For instance, if I
wanted to disable the enter key, editor.bind("Any-Key-Return") {}
doesn't do anything - the newline gets inserted.

martin
 
H

Hidetoshi NAGAI

From: Martin DeMello <[email protected]>
Subject: overriding key bindings in tktext
Date: Wed, 9 Dec 2009 02:58:01 +0900
Message-ID: said:
Does tktext let me completely override bindings? For instance, if I
wanted to disable the enter key, editor.bind("Any-Key-Return") {}
doesn't do anything - the newline gets inserted.

You have to break the evaluation of the widget's bindtag list.
By default, the bindtag list is [_the_widget_, TkText,
_toplevel_window_of_the_widget_, "all"].
You define a binding to _the_widget_. But after the callback,
Tk evaluates bindings of TkText (depends on the order of bindtags list).

You can break the evaluation of bindtags by
editor.bind("Any-Key-Return"){...; break; ...}
or editor.bind("Any-Key-Return"){...; Tk.callback_break; ...}.
If the former has no effect (depends on Ruby or Ruby/Tk version),
please use the latter.
The latter should work on any version of Ruby/Tk.
 
M

Martin DeMello

You have to break the evaluation of the widget's bindtag list.
By default, the bindtag list is [_the_widget_, TkText,
_toplevel_window_of_the_widget_, "all"].
You define a binding to _the_widget_. But after the callback,
Tk evaluates bindings of TkText (depends on the order of bindtags list).

You can break the evaluation of bindtags by
editor.bind("Any-Key-Return"){...; break; ...}
or editor.bind("Any-Key-Return"){...; Tk.callback_break; ...}.
If the former has no effect (depends on Ruby or Ruby/Tk version),
please use the latter.
The latter should work on any version of Ruby/Tk.

Thanks, that works beautifully!

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top