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 [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/