python wnck 在 pdb.set_trace() 之后才返回任何数据

发布于 2024-10-24 06:48:07 字数 2062 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小墨 2024-10-31 06:48:07

文件 so-wnck.py (来自 我如何抓取标题中含有特定单词的所有窗口?

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)>]

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)>]
∝单色的世界 2024-10-31 06:48:07

我不使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文