gpt4 book ai didi

python wnck 在 pdb.set_trace() 之前不返回任何数据

转载 作者:行者123 更新时间:2023-11-28 18:54:36 25 4
gpt4 key购买 nike

在 Ubuntu Linux/Gnome 上,我正在尝试使用 python 的 wnck 绑定(bind)来获取所有打开的窗口的列表。

我的代码是这样的:

#! /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 的情况下使其工作?

最佳答案

文件 so-wnck.py(来自 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)>]

关于python wnck 在 pdb.set_trace() 之前不返回任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5352027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com