Message dialog on 'focus-out-event'

T

Tuomas

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top