pygobject通知操作中未调用回调

2024-04-25 19:28:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用回调向我的Notification添加一个操作。我使用的pygobject代码如下:

import logging
from time import sleep

import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify

def callback(*args, **kwargs):
    print("Got callback")
    print(locals())


def main():
    Notify.init("Hello World")
    notification = Notify.Notification.new("Testing")
    notification.add_action("my action", "Submit", callback)
    notification.show()
    sleep(5)

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    main()

当我运行脚本时,我看到带有“Submit”按钮的通知,但是当我单击按钮时,回调没有运行(据我所知)。在

当我使用ipython检查东西时,我得到了add_action的帮助:

^{pr2}$

所以我看到回调应该是ActionCallback?然后我检查了这个班级:

In [67]: Notify.ActionCallback
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-67-aa40d4997598> in <module>()
----> 1 Notify.ActionCallback

/usr/lib/python3.5/site-packages/gi/module.py in __getattr__(self, name)
    231             wrapper = info.get_value()
    232         else:
--> 233             raise NotImplementedError(info)
    234
    235         # Cache the newly created wrapper which will then be

NotImplementedError: gi.CallbackInfo(ActionCallback)

…我得到了NotImplementedError。那么,通知操作是否只是没有在PyGObject中实现呢?或者我在将回调传递给add_action方法时出错了吗?在

我在ArchLinux上,使用包python-gobject3.22.0-1,与Python3.5.2一起运行。在


Tags: fromimportaddmainloggingdefcallbacknotify