我刚刚开始使用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 == []。谢谢!
发布于 2011-05-23 20:38:54
您需要在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)>]发布于 2011-04-28 15:50:35
在您的示例中,必须使用:Gtk.main_iteration_do(False)而不是Gtk.main_iteration()。
https://stackoverflow.com/questions/5794309
复制相似问题