0
我想用回调将动作添加到我的Notification
。我使用pygobject用下面的代码:在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()
当我运行该脚本,我看到与“提交”按钮的通知,但是当我点击按钮的回调无法运行(据我可以告诉)。
当我使用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
?然后我检查那个类:
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运行。