[pygtk] sending X messages to other windows
Antoine Martin
antoine at nagafix.co.uk
Tue Jun 23 13:34:40 WST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
DOH, sorry for the line noise... there was a bug somewhere else in my
code (a while(True) loop...) which I will blame on lack of sleep.
One question remains: is any locking needed at all?
Is this doing anything useful/harmful:
gtk.gdk.flush()
try:
gtk.gdk.threads_enter()
window.send_event(event)
display.sync()
finally:
gtk.gdk.threads_leave()
Antoine Martin wrote:
> Hi,
>
> 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:
> 1) python-wnck:
> find the matching pid on the windows from screen.get_windows():
> window.get_application().get_pid()
> 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,
> then win32gui.PostMessage(...)
>
> 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:
> window.send_event(ClientMessage(...))
>
> 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...
>
> What gives?
>
> Thanks
> Antoine
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEAREKAAYFAkpAaW8ACgkQGK2zHPGK1rveuQCfVla3KBjQ/pJEqCXpkvH92Tqy
c6kAniHGv5nRW/7N+Q1akirjMZTiTsoz
=xf2i
-----END PGP SIGNATURE-----
More information about the pygtk
mailing list