logo       

Re: Verifying Entry inputs: msg#00138

gnome.gtk+.python

Subject: Re: Verifying Entry inputs

On Fri, 25 Feb 2005 09:11:56 +0100, Hans-Joachim Widmaier
<hjwidmaier@xxxxxx> wrote:
> Hi all,
>
> I'd like to have Entry widgets that allow only numbers (float) as inputs, and
> only
> in a certain range.

May be this function will help you:

def entry_float(entry, new_text, new_text_length, position):
"""Connect insert-text signal to this function to validate
floating type"""
lst_old_string = list(entry.get_chars(0, -1))
_pos = entry.get_position()
lst_new_string = lst_old_string.insert(_pos, new_text)
_string = "".join(lst_old_string)
_hid = entry.get_data('handlerid')
entry.handler_block(_hid)
try:
_val = float(_string)
_pos = entry.insert_text(new_text, _pos)
except StandardError, e:
pass
entry.handler_unblock(_hid)
gtk.idle_add(lambda t: t.set_position(t.get_position()+1), entry)
entry.stop_emission("insert-text")
pass


Usage:-
self.etrInfo = gtk.Entry()
handlerid = self.etrInfo.connect("insert_text", entry_float)
self.etrInfo.set_data('handlerid', handlerid)

Regards,
Baiju M
_______________________________________________
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