如何在 PyGTK 或 GTK 或其他编程语言中获取打开的窗口列表?在 Ubuntu 中?
编辑:
我想获取在桌面上打开的目录的列表路径!
最佳答案
欢迎来到 2013 年!下面是使用 Wnck
及其现代 GObject Introspection 库的代码,而不是现在已弃用的 PyGTK 方法。您也可以查看 my other answer about wnck :
from gi.repository import Gtk, Wnck
Gtk.init([]) # necessary only if not using a Gtk.main() loop
screen = Wnck.Screen.get_default()
screen.force_update() # recommended per Wnck documentation
# loop all windows
for window in screen.get_windows():
print window.get_name()
# ... do whatever you want with this window
# clean up Wnck (saves resources, check documentation)
window = None
screen = None
Wnck.shutdown()
至于文档,请查看 Libwnck Reference Manual .它不是特定于 python,但使用 GObject Introspection 的全部意义在于在所有语言中使用相同的 API,这要归功于 gir
绑定(bind)。
此外,Ubuntu 附带了 wnck
及其相应的 gir
绑定(bind),但如果您需要安装它们:
sudo apt-get install libwnck-3-* gir1.2-wnck-3.0
这还将安装 libwnck-3-dev
,这不是必需的,但会安装有用的文档,您可以使用 DevHelp 阅读。
关于python - 如何在 Ubuntu 中获取 PyGTK 或 GTK 中打开的窗口列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1380784/