2016-11-21 2 views
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 메서드로 콜백을 전달하는 중에 잘못된 것이 있습니까?

파이썬 3.5.2와 함께 실행되는 python-gobject 3.22.0-1 패키지를 사용하여 아치 리눅스에 있습니다.

답변

2

내가 GTK의 메인 루프 실행하는 데 필요한 밝혀 : 콜백이 잘 불렀다 그런

from gi.repository import Gtk 
Gtk.main()