Validate entry in Gtk::Entry
- From: Chris Dunlop <chris onthe net au>
- To: gtk-perl-list gnome org
- Subject: Validate entry in Gtk::Entry
- Date: Wed, 21 Mar 2001 21:33:21 +1100
Hi,
I'm working on my first ever GTK program, using:
gtk+-1.2.8
Gtk-Perl-0.7005
Glade-Perl-0.57
I'm trying to do input checking for a Gtk::Entry widget. The checking
is for a valid date, so I need to check the field once all changes have
been made rather than as each individual change is made. I thought the
way to do this would be be to use the "focus_out_event" to do the
checking, and prevent the focus leaving the widget if the input wasn't
valid. My code is like this:
$widget->signal_connect('changed', "$class\::on_field_changed");
$widget->signal_connect('focus_out_event', "$class\::on_field_focus_out");
sub on_field_changed
{
++shift->{changed};
}
sub on_field_focus_out
{
my $self = shift;
if ($self->{changed}) {
if (...invalid input...) {
print "Uh-oh. Invalid input...\n";
$self->signal_emit_stop_by_name("focus_out_event");
$self->grab_focus();
return 1;
}
}
$self->{changed} = 0;
return 0;
}
This _nearly_ works: the widget I'm trying to prevent the focus from
leaving looks to be still selected ie. it has a highlight around it, and
it still has a vertical cursor in it. However the following widget
(also a Gtk::Entry widget) is _also_ selected, and _also_ has a cursor
in it. And when I start typing, the characters go into the following
widget rather than the original one I'm interested in. Bummer. Also,
if I switch the focus between my application and something else on my
screen (eg. clicking on an XTerm), the "phantom" highlighting and cursor
stay on the original widget but come and go on the following widget. So
I guess it's a bug, but I've no idea if it's in my code (quite likely!)
or in Glade-Perl or Gtk-Perl or Gtk...
The gtkperl-tutorial mentions "stuff" about this:
http://personal.riverusers.com/~swilhelm/gtkperl-tutorial/signalsandevents.html#AEN546
However it's quite terse and I'll freely admit admit that my
understanding of the signal mechanism is poor, so I'm reduced to trial
and error: I've tried with and without the $self->grab_focus(), with
and without the $self->signal_emit_stop_by_name(), with the grab_focus
before and after the signal_emit_stop_by_name, and with
$widget->signal_connect_after() in place of $widget->signal_connect().
But no go.
"signal_emit_stop_by_name" is only mentioned in the one place in the
tutorial but it's not clear when or where it should be used. I tried
searching for it in the the list archives at:
http://mail.gnome.org/archives/gtk-perl-list/
But it returned no results for "signal_emit_stop_by_name", and also no
results returned for "validate".
I got a bit excited when I found:
GTK FAQ: 6.15. How do I validate/limit/filter the input to a GtkEntry?
http://www.gtk.org/faq/#AEN812
But unfortunately I can't relate the Gtk-Perl interface to the sample C
code.
I don't know if I'm missing something painfully obvious, but I'd really
appreciate some help!
Cheers,
Chris.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]