python wnck 在 pdb.set_trace() 之后才返回任何数据
在 Ubuntu Linux / Gnome 上,我尝试使用 python 的 wnck 绑定来获取所有打开的窗口的列表。
我的代码如下所示:
#! /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())
输出如下:
** (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)>]
第一个 get_windows()
调用返回 []
,一个空列表。第二个 get_windows()
调用返回打开的窗口列表。在 pdb
中,我只按 c
继续而不执行任何操作(在 pdb 中)。
如果我注释掉 pdb
,则两个 get_windows()
调用都会返回 []
。如果我在 pdb 之前多次重复 get_windows() 调用,则什么也没有。如果我在 pdb 之后多次重复 get_windows()
调用,我会不断获得完整列表。
为什么此调用仅在空 pdb 之后才有效?在没有 pdb 的情况下如何使其工作?
On Ubuntu Linux / Gnome, I am trying to use python's wnck binding to get a list of all the open windows.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文件 so-wnck.py (来自 我如何抓取标题中含有特定单词的所有窗口?)
File so-wnck.py (from How might I grab all windows with a certain word in their titles?)
我不使用 wnck,但我认为如果 pdb 两次调用 get_window 之间的时间足以初始化窗口列表。在调用 get_window 之前尝试使用睡眠并延迟一些。
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.