python wnck not returning any data until after a pdb.set_trace()
On Ubuntu Linux / Gnome, I am trying to use python's wnck binding to get a list of all the open wi开发者_高级运维ndows.
My code looks like this:
#! /usr/bin/python
from pprint import pprint
import wnck
screen = wnck.screen_get_default()
pprint(screen.get_windows())
import pdb ; pdb.set_trace()
pprint(screen.get_windows())
The output is like this:
** (windowlist.py:4501): WARNING **: Trying to register gtype 'WnckWindowState' as enum when in fact it is of type 'GFlags'
** (windowlist.py:4501): WARNING **: Trying to register gtype 'WnckWindowActions' as enum when in fact it is of type 'GFlags'
** (windowlist.py:4501): WARNING **: Trying to register gtype 'WnckWindowMoveResizeMask' as enum when in fact it is of type 'GFlags'
[]
> /home/rory/personal/diriu/windowlist.py(12)<module>()
-> pprint(screen.get_windows())
(Pdb) c
[<wnck.Window object at 0xb61db0cc (WnckWindow at 0x992c000)>,
<wnck.Window object at 0xb61db0f4 (WnckWindow at 0x992c0a8)>,
<wnck.Window object at 0xb61db11c (WnckWindow at 0x992c150)>,
<wnck.Window object at 0xb61db144 (WnckWindow at 0x992c1f8)>,
<wnck.Window object at 0xb61db16c (WnckWindow at 0x992c2a0)>,
<wnck.Window object at 0xb61db194 (WnckWindow at 0x992c348)>,
<wnck.Window object at 0xb61db1bc (WnckWindow at 0x992c3f0)>,
<wnck.Window object at 0xb61db1e4 (WnckWindow at 0x992c498)>,
<wnck.Window object at 0xb61db20c (WnckWindow at 0x992c540)>,
<wnck.Window object at 0xb61db234 (WnckWindow at 0x992c5e8)>,
<wnck.Window object at 0xb61db25c (WnckWindow at 0x992c690)>,
<wnck.Window object at 0xb61db284 (WnckWindow at 0x992c738)>]
The first get_windows()
call returns []
, an empty list. The second get_windows()
call returns a list of open windows. In the pdb
, I only press c
to continue and do nothing (in pdb).
If I comment out the pdb
, the both get_windows()
calls return []
. If I repeat the get_windows()
call many time before the pdb, there is nothing. If I repeat the get_windows()
call many times after the pdb, i continually get a full list.
Why is this call only working after an empty pdb? How do I make it work without a pdb?
File so-wnck.py (from How might I grab all windows with a certain word in their titles?)
import pygtk
pygtk.require('2.0')
import gtk
import wnck
screen = wnck.screen_get_default()
while gtk.events_pending():
gtk.main_iteration()
windows = screen.get_windows()
print (windows)
python so-wnck.py
** (so-wnck.py:2367): WARNING **: Trying to register gtype 'WnckWindowState' as enum when in fact it is of type 'GFlags'
** (so-wnck.py:2367): WARNING **: Trying to register gtype 'WnckWindowActions' as enum when in fact it is of type 'GFlags'
** (so-wnck.py:2367): WARNING **: Trying to register gtype 'WnckWindowMoveResizeMask' as enum when in fact it is of type 'GFlags'
[<wnck.Window object at 0xb7566694 (WnckWindow at 0x97c51f8)>,
<wnck.Window object at 0xb75666bc (WnckWindow at 0x97c52a0)>,
<wnck.Window object at 0xb75666e4 (WnckWindow at 0x97c5348)>,
<wnck.Window object at 0xb756670c (WnckWindow at 0x97c53f0)>,
<wnck.Window object at 0xb7566734 (WnckWindow at 0x97c5498)>,
<wnck.Window object at 0xb756675c (WnckWindow at 0x97c5540)>,
<wnck.Window object at 0xb7566784 (WnckWindow at 0x97c55e8)>]
I doesn't work with wnck but I think that in case with pdb time between two calls to get_window enough to windows list initialized. Try to use sleep with some delay before call to get_window.
精彩评论