在 pygobject 通知操作中未调用回调

Callback not called in pygobject notification action

我想通过回调向我的 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 的帮助:

In [65]: Notify.Notification.add_action?
Type:        FunctionInfo
String form: gi.FunctionInfo(add_action)
File:        /usr/lib/python3.5/site-packages/gi/__init__.py
Docstring:   add_action(self, action:str, label:str, callback:Notify.ActionCallback, user_data=None)

所以我看到回调应该是 ActionCallback?然后我检查 class:

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 方法时做错了什么?

我在 arch linux,使用包 python-gobject 3.22.0-1,运行 python 3.5.2.

事实证明我需要 运行 Gtk 主循环:

from gi.repository import Gtk
Gtk.main()

然后回调调用就好了