import pygtk, gtk, gobject, ...
class MyEntry(gtk.Entry):
def __init__(self, is_OK):
gtk.Entry.__init__(self)
self.is_OK=is_OK
self.add_events(gtk.gdk.FOCUS_CHANGE)
self.focus_out_id=self.connect('focus-out-event',
self.on_focus_out)
def on_focus_out(self, sender, event):
if self.is_OK(self.get_text()): return False
else:
# don't want another focus-out-event because of show_message
self.disconnect(self.focus_out_id)
# self.grab_focus()
show_message("Wrong value for entry")
self.focus_out_id=self.connect('focus-out-event',
self.on_focus_out)
return False
# Leaving focus in not_OK case results:
# GtkWarning: GtkEntry - did not receive focus-out-event.
# If you connect a handler to this signal, it must return
# FALSE so the entry gets the event as well
# The required False is given, but may be the messagebox
# times it out.
# My second trial was to include self.grab_focus() before
# show_message, but it gives focus to the toplevel
# gtk.gdk.Window and I lose access to the entry.
# Any suggestions?
# Tuomas Vesterinen