python - 如何在 Ubuntu 中获取 PyGTK 或 GTK 中打开的窗口列表?

标签 python ubuntu gtk pygtk window-management

如何在 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/

相关文章:

python - 乘以包含 NaN 的 Pandas 系列行

python - pip 差错误 : 'module' object has no attribute 'Cryptography_HAS_SSL_ST'

c++ - 使用 GTK+ 中的文本将 GtkButton 添加到 GtkListStore

c - 如何使用 GTK 和 Pango 判断字体是否为等宽字体?

python - GTK 聚焦事件

python - 当 argparse 中未设置 optinal 时如何采用两个位置参数

python - sqlalchemy:使模式反射为所有实例查找/使用自定义类型

ruby - 在 ubuntu 服务器上使用 RubyGems

c++ - Poco进程不退出

python - 安装 Pillow 后无法导入 PIL