[英]How can I get a list of windows with Wnck, using PyGI?
I just started using PyGI (on Ubuntu Natty), although I have never used pygtk before. 我刚刚开始使用PyGI(在Ubuntu Natty上),尽管我以前从未使用过pygtk。 I have used wnck in a wxPython program though, and it was easy enough to get a list of currently opened windows. 我在wxPython程序中使用了wnck,并且很容易获得当前打开的窗口的列表。 From PyGI, the window list is always empty. 在PyGI中,窗口列表始终为空。 relevant code bits: 相关代码位:
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()
with that, wins == []
. 这样, wins == []
。 Thanks! 谢谢!
You need to call screen.force_update()
before screen.get_windows()
returns list of windows. 您需要先调用screen.force_update()
然后screen.get_windows()
返回窗口列表。 Unfortunately docs are lacking this part :( 不幸的是,文档缺少这一部分:(
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)>]
在您的示例中,您必须使用: Gtk.main_iteration_do(False)
而不是Gtk.main_iteration()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.