[pygtk] sending X messages to other windows
antoine at nagafix.co.uk
Tue Jun 23 06:43:11 WST 2009
-----BEGIN PGP SIGNED MESSAGE-----
I've got a little app in pygtk that needs to send X events (just close
and minimize for now) to other applications only known by their pid.
I've got 2 working implementations using:
find the matching pid on the windows from screen.get_windows():
and call "minimize()" or "close(n)" or whatever on the "wnck.Window" object.
2) the win32 implementation does it using:
win32gui.GetWindow(..) in a loop and
win32process.GetWindowThreadProcessId(window) to match the pid,
Problem is that python-wnck brings in far too many dependencies.
Since gtk/gdk can't seem to access windows that were not created by the
current program, I thought I'd try to use python-xlib to fill the gap.
So I did in python-xlib:
for each screen on the current display, iterate over all the top level
windows using screen.root.query_tree().children,
find the pid with some get_property magic:
window.get_property(self.net_wm_pid_atom, X.AnyPropertyType, 0, 10)
Then just send the event:
The window does close as expected, but my app becomes unresponsive, like
GTK is stuck or something.
So I thought that maybe I needed locking around the send_event() and
added a "gtk.gdk.flush()" before, I also added "gtk.gdk.threads_enter()"
/ "gtk.gdk.threads_leave()" around it.
To no avail...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the pygtk