GNOME Bugzilla – Bug 172842
Expose event called on every focus in or focus out
Last modified: 2005-04-07 03:08:38 UTC
Distribution/Version: Debian sarge, ubuntu hoary Add a print statement to the expose event handler, then focus in and out without changing visibility of the window. pygtk thinks the entire window needs repainting each time there's a focus change. It's particularly obvious with mouse focus, since expose is called twice every time the mouse moves over the window. I've tested this with three window managers: metacity, icewm, and fvwm (all three in mouse focus mode). This is specific to pygtk: it does NOT happen in a normal C gtk program, nor in a C xlib program. I will attach small test programs for both pygtk and C gtk.
Created attachment 39762 [details] Test case for pygtk
Created attachment 39763 [details] gtk test case in C
Created attachment 39764 [details] Makefile for gtk C test
It's unlikely that PyGTK behavior differs from GTK+ behavior in this case. Your PyGTK and C programs differ enough that little is proved by comparison. I was able to make your PyGTK program behave like your C program by commenting out one of the differing elements: #drawing_area.set_flags(gtk.CAN_FOCUS)
Unfortunately, I to be able to get keyboard events on the drawing area, since my program uses them. The C gtk program can receive keyboard events on the drawing area, and still does not generate spurious expose events, so there's still a pygtk-specific limitation here. Is there some other way to get keyboard events, without calling drawing_area.set_flags(gtk.CAN_FOCUS) ?
GTK automatically queues a redraw for a focusable widget when it gets focused -- this is because most widgets provide some indicator that they are focused (in fact, all widgets should provide some indication of focus if they are to be accessible). As John said, any difference in behaviour is probably due to differences in your code, rather than behaviour differences between C and Python. Try doing a straight transliteration of your C example to check.