【问题标题】:How can I get a list of windows with Wnck, using PyGI?如何使用 PyGI 获取带有 Wnck 的窗口列表?
【发布时间】:2011-04-26 17:44:27
【问题描述】:

我刚开始使用 PyGI(在 Ubuntu Natty 上),虽然我以前从未使用过 pygtk。 不过,我在 wxPython 程序中使用了 wnck,并且很容易获得当前打开的窗口的列表。在 PyGI 中,窗口列表始终为空。 相关代码位:

from gi.repository import Gtk, Wnck

while Gtk.events_pending():
    Gtk.main_iteration()
#... in my app class...
    screen = Wnck.Screen.get_default()
    wins = screen.get_windows()

这样,wins == []。 谢谢!

【问题讨论】:

  • 谢谢,番茄!我自己怎么做?

标签: python gtk pygtk pygobject wnck


【解决方案1】:

您需要在screen.get_windows() 返回窗口列表之前调用screen.force_update()。不幸的是,文档缺少这部分:(

In [1]: from gi.repository import Gtk, Wnck

In [2]: Gtk.main_iteration()
Out[2]: True

In [3]: screen = Wnck.Screen.get_default()

In [4]: screen.force_update()

In [5]: screen.get_windows()
Out[5]: 
[<Window object at 0x167bd20 (WnckWindow at 0x195d0e0)>,
 <Window object at 0x167bf00 (WnckWindow at 0x195d740)>,
 <Window object at 0x167bf50 (WnckWindow at 0x195d850)>]

【讨论】:

【解决方案2】:

在您的示例中,您必须使用:Gtk.main_iteration_do(False) 而不是 Gtk.main_iteration()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 2013-08-29
    • 2022-01-14
    • 1970-01-01
    相关资源
    最近更新 更多