[gtkada] Need help with Entry and Signals

Bobby D. Bryant bdbryant at mail.utexas.edu
Mon Jun 5 06:24:01 CEST 2000


Preben Randhol wrote:

> I'm trying to add a "filter" to a entry widget so that I can filter out
> those keys that are not allowed to input. That is such as GDK_Left and
> GDK_Right and more. I also want to use this Handler to check the keys
> inputted against another string.

...

> Now this works, but when I press the left arrow the Entry Widget looses
> the Focus. I think this is because as the Entry widget isn't processing
> the left arrow, the window thinks that it should move the focus to the
> next widget. Is this right. And how can I prevent this from happening?

I have not tried it with an Entry, but I had a similar problem with trapping
keypresses within a page of a Notebook, and I finally fixed it by adding this to
my keypress callback handler:

      Gtk.Handlers.Emit_Stop_By_Name( Object => Widget,
                                      Name   => "key_press_event" );

where Widget is the same object that the callback handler was attached to (i.e.,
the first argument to the callback handler -- the Entry in your case).

The way I understand things [someone please correct me if I'm leading him
astray!] is that when you establish a callback for an object it does *not* bump
off any existing callback even for the same event; it simply puts the new
callback in a line with the others (at the head of the line, unless you use the
"After" variant).  Thus even after your handler has finished its business, some
existing handler is still intercepting and acting on the arrow key.  However, by
using Emit_Stop_By_Name you tell all the handlers in line after the current one
to ignore the current event of the type in the name.

This worked wonders for my program with the Notebook widgets, because they are
set up by GTK+ to interpret the keypad keys as commands to navigate the tabs in
a notebook (or even between levels, if one notebook is inside another).  Now I
can trap the keys in my page-level widget, and keep the Notebook from
interpreting certain ones as a command to change focus.  It looks like your
problem is exactly analogous to mine.

If you still have problems after adding the call described above, you might want
to take a peak at the C source code for GTK+ to see exactly what callbacks it is
setting up for an Entry widget.

Good luck,

Bobby Bryant
Austin, Texas








More information about the gtkada mailing list