我该如何抓住所有带有标题的单词的窗口? [英] How might I grab all windows with a certain word in their titles?
问题描述
我正在运行gnome,并且有一个程序可以产生大量独立的进程,每个进程都有自己的gui窗口.我希望能够有选择地抓住标题匹配特定模式的打开的窗口以将其关闭.有人知道轻松实现此目的的方法吗?
I'm running gnome and have a program that spawns off a large number of separate processes each with its own gui window. I'd like to be able to selectively grab open windows whose titles match a certain pattern to close them. Anyone know a way to do this easily ?
推荐答案
您肯定要使用python-wnck
(对于文档,您可能需要查找python-gnome-extras
,Perl绑定或纯C文档. ). WNCK的编写旨在使您轻松查看屏幕,工作区和窗口.像这样:
You definitely want to use python-wnck
(for documentation, you might need to look for python-gnome-extras
, or the Perl bindings, or just the plain C documentation). WNCK is written to make it easy to look at screens, workspaces, and windows. Something like this:
import pygtk
pygtk.require('2.0')
import gtk
import wnck
screen = wnck.screen_get_default()
while gtk.events_pending():
gtk.main_iteration()
windows = screen.get_windows()
for w in windows:
if w.get_name() == 'foo':
w.close(0)
...但是我还没有测试.
...but I haven't tested it.
(而且,这不是特定于GNOME的.它可在任何桌面环境中使用.)
(Also, this won't be GNOME-specific. It works with any desktop environment.)
这篇关于我该如何抓住所有带有标题的单词的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!