我创建了一个程序,在其中创建了几个菜单项并将它们最后存储在“ci”中。每当我单击其中一个菜单项时,它都会执行“checkStatus”功能。我想知道我单击了哪些菜单项(ci[0] 或 ci[1] 或其他),因为我的功能将按照我点击的项目。
#!/usr/bin/python
import requests
from bs4 import BeautifulSoup
import appindicator
import pynotify
import gtk
appindicator.CATEGORY_APPLICATION_STATUS)
a = appindicator.Indicator('tubecheck', 'indicator-messages', appindicator.CATEGORY_APPLICATION_STATUS)
a.set_label('Live cricket score')
a.set_status( appindicator.STATUS_ACTIVE )
m = gtk.Menu()
ci = []
url = 'http://static.cricinfo.com/rss/livescores.xml'
sc = requests.get(url)
soup = BeautifulSoup(sc.text,'lxml')
data = soup.select('item')
for i in range(len(data)):
ci.append(gtk.MenuItem(str(i+1)+'. '+data[i].find('title').text))
m.append(ci[i])
qi = gtk.MenuItem( str(i+2)+'. '+'Quit' )
m.append(qi)
a.set_menu(m)
for i in range(len(ci)):
ci[i].show()
qi.show()
def checkStatus(item):
pynotify.init('test')
n = pynotify.Notification('Live Cricket score',data[i].text)
n.show()
ci[i].connect('activate', checkStatus)
def quit(item):
gtk.main_quit()
qi.connect('activate', quit)
gtk.main()