2011-04-26 103 views
2

我剛開始使用PyGI(在Ubuntu Natty上),雖然我從來沒有用過pygtk。 我已經在wxPython程序中使用了wnck,並且很容易獲得當前打開的窗口的列表。從PyGI,窗口列表總是空的。 相關的代碼位:如何使用PyGI獲取Wnck的窗口列表?

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 == []。 謝謝!

+0

謝謝,我ptomato如何能做到這一點我自己 – crazedpsyc 2011-04-26 20:04:15

回答

4

您需要在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)>] 
+0

能否請你分享鏈接到可用的文檔我找不到它 – ganesshkumar 2013-10-23 14:56:29

+1

的例子標題中提到:HTTPS ://developer.gnome.org/libwnck/stable/getting-started.html – Cas 2015-08-17 21:09:19

0

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

相關問題