|
Re: Verifying Entry inputs: msg#00140gnome.gtk+.python
On Fri, 2005-02-25 at 10:57 +0000, John Gill wrote: >See attached code for a way to provide visual feedback as the entry is >edited. I was recently faced with the same problem. I thought about this very same solution, but in the end I gave it up because hardcoding background colour is bad when interacting with themes. For instance, you change the background between white and red. This particular pair of colours make look bad in some themes. Moreover, dark themes will likely have a white or light text colour, and in this case white text in white background will disappear. My solution, although also not perfect, was to place a small gtk.STOCK_DIALOG_WARNING icon inside the entry, and toggle between making it insensitive (=value OK) or sensitive (=bad value). Regards. > >John > >Hans-Joachim Widmaier wrote: >>Hi all, >> >>I'd like to have Entry widgets that allow only numbers (float) as >>inputs, and only >>in a certain range. This verification should be done as soon as the >>user is done >>with editing. I tried the focus-out-event, but pygtk didn't like me >>bringing up a >>modal (error) dialog in the callback. Second try was with an >>insert-text handler >>which just ignored invalid inputs. It looks like this: >> >>def myInsertText(self, widget, new_text, new_text_length, position): >> oldtext = widget.get_text() >> # Avoid recursion >> widget.handler_block(widget.mySigHandID) >> # Insert text and check for validity >> pos = widget.get_position() >> widget.insert_text(new_text, pos) >> newtext = widget.get_text() >> try: >> value = float(newtext) >> except ValueError: >> # Restore previous contents >> widget.delete_text(pos, pos + new_text_length) >> # XXX Something like a beep might be nice here >> else: >> widget.set_position(pos + new_text_length) >> widget.handler_unblock(widget.mySigHandID) >> >> # Keep normal handler from running >> widget.stop_emission("insert-text") >> >>In this version I simply can't get the cursor to appear *after* the >>inserted text, the widget.set_position() call seems to do just >>nothing. >> >>Is there a fundamental flaw in my routine or my whole concept? >>I'd be really glad to get some recommendations. >> >>Thanks, >>Hans-J. Widmaier >>______________________________________________________________ >>Verschicken Sie romantische, coole und witzige Bilder per SMS! >>Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193 >> >>_______________________________________________ >>pygtk mailing list pygtk@xxxxxxxxxx >>http://www.daa.com.au/mailman/listinfo/pygtk >>Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ >> >_______________________________________________ >pygtk mailing list pygtk@xxxxxxxxxx >http://www.daa.com.au/mailman/listinfo/pygtk >Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/ -- Gustavo J. A. M. Carneiro <gjc@xxxxxxxxxxxxx> <gustavo@xxxxxxxxxxxxxxxxxxxxx> The universe is always one step beyond logic.
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> |
|---|---|---|
| Previous by Date: | Re: Verifying Entry inputs: 00140, John Gill |
|---|---|
| Next by Date: | Re: Verifying Entry inputs: 00140, Rafael Villar Burke |
| Previous by Thread: | Re: Verifying Entry inputsi: 00140, John Gill |
| Next by Thread: | Re: Verifying Entry inputs: 00140, Rafael Villar Burke |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |