logo       

Re: Verifying Entry inputs: msg#00160

gnome.gtk+.python

Subject: Re: Verifying Entry inputs

> Thanks for all of your suggestions! Looks like I wasn't too far off.
> Looking at entryvalidator.py, I cannot help but wonder why the
> insert-text callback receives the arguments it does ... Especially
> the position argument is of absolutely no use.

Yes, the position argument to the 'insert-text' callback is
frustrating. It can be used in C and C++, but it's an opaque type in
pygtk. GTK+ passes it by reference, and this design seems to be quite
hostile to language bindings. The gtk.idle_add() trick to set the
cursor is either a clever solution or an ugly hack depending on how
you look at it. I consider it to be a necessary evil and I salute
those who came up with the idea and shared it with the rest of us.

There was some discussion of how to provide feedback for invalid
entries. I'm not sure there's a single best way to do this, but here
are some more ideas. It's really just brainstorming to throw some
ideas out there. Some of these can be used together, others are
mutually exclusive.

1. You suggest beeping in a comment in your code. Good idea, as long
as you provide other feedback for deaf users. Use
gtk.gdk.Display.beep().

2. In some cases you can simply not allow any invalid characters to be
inserted into the entry. This is the very best technique if it
works for your situation. It's easy to do if every prefix of a
valid entry is also a valid entry because then the entry will
always be in a valid state. Since there's no way for the user to
enter invalid data you never have to worry about signalling an
error. The floating point input example you are talking about is
an excellent example of where this is not the case so this
technique is hard to apply here.

3. A typical GNOME app would probably put an error message in the
status bar at the bottom of the application window. Unfortunately
a lot of validation is done in property windows which usually don't
have status bars.

4. Don't allow focus to leave the entry if the input is invalid.
Sometimes this behavior is really annoying, but I think it can work
well as long as you at least temporarily allow the user to clear
the entry and proceed.

5. If instead you do allow focus to leave the entry if input is
invalid, make sure that after a failed attempt to apply or an error
is indicated that you set focus on the entry with invalid input.

6. When invalid input is entered, select the invalid characters using
editable.select_region(). (Unfortunately this has to be done in an
idle callback.) I like this because it gives a visual indication
of the bad input and makes it easy for the user to repair. As soon
as the user starts typing in the entry the bad input will be
overwritten.

7. Set the tooltip text on the entry to indicate what the problem is.
I've never tried this and I suspect it wouldn't really help much.

8. Make the OK or Apply buttons insensitive until all the necessary
fields validate. I think there are two differing views of this.
Because there's no way to submit invalid data, you don't need to
pop an error dialog to tell the user what he did wrong. On the
other hand, it's hard to give the user an explanation of why the
buttons are insensitive and that may cause frustration if the
reason is an obscure validation problem. Maybe whether this is a
good idea or not depends on your application. You could set a
tooltip on the OK or Apply button to indicate why they are
insensitive.

9. Flash the entry on invalid input by switching the foreground and
background colors a few times. This is similar to other's
suggestions. I've never tried this because I don't like to work
that hard and I'm not sure it would work well.

10. Use Gustavo's suggestion of using a small icon in the entry to
indicate bad input. I've also thought about using doing something
similar to indicate required fields.
_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise