Detecting window focus events in PyGTK

P

Peter TB Brett

Hi folks,

I'm currently trying to work out how to detect when a PyGTK window
receives the focus from the window manager -- I assume that it must
receive some kind of X event, but I can't work out which signal it
generates. Searching around the subject on the web doesn't seem to pull up
anything useful.

I tried the "focus" signal, but that doesn't work the way I'd like it
to. For example, the following code only prints the message "Received
focus!" once (immediately after startup) even when it _isn't_ the active
window.


#!/usr/bin/env python
import pygtk
pygtk.require('2.0')

import gtk

def event_focus(widget, direction):
print "Received focus!"

window = gtk.Window()
window.set_size_request(100, 100)
window.connect("focus", event_focus)
window.show_all()
gtk.main()


I suspect that I'm hacking in the wrong place, so any hints or tips much
appreciated!

Thanks,

Peter
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top