3

I just started using PyGI (on Ubuntu Natty), although I have never used pygtk before. I have used wnck in a wxPython program though, and it was easy enough to get a list of currently opened windows. From PyGI, the window list is always empty. 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 == []. Thanks!

MestreLion
  • 12,698
  • 8
  • 66
  • 57
crazedpsyc
  • 65
  • 1
  • 4

2 Answers2

6

You need to call screen.force_update() before screen.get_windows() returns list of 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)>]
plaes
  • 31,788
  • 11
  • 91
  • 89
1

In your example you have to use: Gtk.main_iteration_do(False) instead of Gtk.main_iteration().

gpoo
  • 8,408
  • 3
  • 38
  • 53