Detecting window focus events in PyGTK

Peter TB Brett peter at peter-b.co.uk
Mon Aug 28 13:06:36 EDT 2006


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

-- 
v2sw6YShw7$ln5pr6ck3ma8u6/8Lw3+2m0l7Ci6e4+8t4Eb8Aen5+6g6Pa2Xs5MSr5p4
  hackerkey.com




More information about the Python-list mailing list