sandbox_mail wrote: > Hi folks, > in my GUI I have an entry where the user is supposed to enter an > expression according to a specific syntax. > If the user makes a mistake, the entry turn red. > > This works quite well but there is one usability flaw: > Right now I use the "changed" signal to invoke checking of the contents. > Therefore the entry turns red right after the first character has been > entered. > > Is there an elegant way (maybe another signal) to delay the checking? > Like in a wordprocessor I would like to change the color only after no > further typing was done for ~1 sec. or if the entry loses focus. > > Thanks for any hints!
I have used code that looks roughly like this: class DelayedCall(object): def __init__(self, delay, callback): self._delay = delay self._callback = callback self._id = 0 def call(self): if self._id != 0: gobject.source_remove(self._id) self._id = gobject.timeout_add(self._delay, self._timeout) def _timeout(self): self._id = 0 self._callback() return False Call 'call()' whenever the entry changes. Your callback will be called when nothing has happened in the last 'delay' milliseconds. You may need something to force an early check on focus-out-event for the entry or when the user clicks an "Ok" button for example. -- Tim Evans Applied Research Associates NZ http://www.aranz.com/ _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/