2016-06-26 3 views
0

appindicator 및 Gtk로 약간의 응용 프로그램을 만들려고합니다. 내 목표는 그들에 대한 링크가있는 서버 목록을 표시하는 것입니다.Python : appindicator에 메뉴에 URL 추가

from gi.repository import Gtk as gtk 
from gi.repository import AppIndicator3 as appindicator 

def main(): 
    indicator = appindicator.Indicator.new(APPINDICATOR_ID, img, appindicator.IndicatorCategory.SYSTEM_SERVICES) 
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE) 
    indicator.set_menu(build_menu()) 
    gtk.main() 

def build_menu(): 
    menu = gtk.Menu() 

    value = "label" 
    item = gtk.MenuItem() 
    button = gtk.LinkButton("http://url/host/id", label=value) 
    button.show() 

    item.add(button) 
    item.show() 

    menu.append(item) 
    menu.show_all() 

    return menu 

if __name__ == "__main__": 
    main() 

하는 작업을하고 내가 오류가없는 것 그 다음은

내가 시도 할 것입니다. 그러나 wen 응용 프로그램을 시작하고 항목이 있지만 링크가없는 메뉴 만 있습니다.

gtk.Window에는 많은 예제가 있지만 appindicator에는 메뉴가 없습니다.

이 메뉴에 링크가있는 방법이 있습니까?

고마워요.

답변

0

그 방법을 찾았습니다. 나는 그것이 최선의 방법이라고 확신하지 않지만, 효과적이다. LinkItem에를 만드는 대신에

, 나는 URL 열기위한 기능했습니다 :

def open_url(source): 
    webbrowser.open("http://url/host/id") 

을 그리고 connect로, 이후 호출 :

item.connect("activate", open_url) 

내 응용 프로그램과 클릭을 실행 내 항목에서 예상대로 URL을 엽니 다. 나는 웹에 많은 게시물을 참조로

def build_menu(): 
    menu = gtk.Menu() 

    value = "label" 
    item = gtk.MenuItem(value) 
    item.connect("activate", open_url) 

    menu.append(item) 
    menu.show_all() 

    return menu 

, appindicator이 제한되어 기능이 정상의 GTK 응용 프로그램에 비해 : 여기에 코드 작업의 일부입니다.