如何使用 Python 创建 AppIndicator?

Leo*_*nos 6 indicator python application-development

我对 Python 一无所知,但是因为 ubuntu 推荐它,所以我将它用于 appinidcator .. 所以我得到了这 2 个文件:

在此处输入图片说明

.py 文件的代码是:

#!/usr/bin/python

import appindicator
import pynotify
import gtk

a = appindicator.Indicator('wallch_indicator', '/home/paul/scripts/wallch_tray.png', appindicator.CATEGORY_APPLICATION_STATUS)
a.set_status( appindicator.STATUS_ACTIVE )
m = gtk.Menu()
ci = gtk.MenuItem( 'Check' )
qi = gtk.MenuItem( 'Quit' )

m.append(ci)
m.append(qi)

a.set_menu(m)
ci.show()
qi.show()

def checkStatus(item):
        import urllib2
        htmltext = urllib2.urlopen('http://youtube.com/wichitsombat').readlines()
        neededline = []
        for line in htmltext:
                if line.strip().find('stat-value') > -1:
                        neededline.append(line) 

        n = neededline[0]
        subs = n[n.find('>')+1:n.rfind('<')]
        n = neededline[1]
        views = n[n.find('>')+1:n.rfind('<')]

        # show the notification message
        pynotify.init('wallch_indicator')
        n = pynotify.Notification('<b>Paulgramming Channel</b>',
                'subscribers: %s   views: %s'%(subs, views),
                'notification-message-im')
        n.show()

ci.connect('activate', checkStatus)

def quit(item):
        gtk.main_quit()

qi.connect('activate', quit)

gtk.main()
Run Code Online (Sandbox Code Playgroud)

取自此视频的代码如何使用 Python 制作通知程序

当我运行时,python wallch_indicator.py它一直在运行,但我没有看到指示器..我做错了什么?

woj*_*jox 4

检查图标的路径/home/paul/scripts/wallch_tray.png