Answer the question
In order to leave comments, you need to log in
python+gtk. How to stop code when no menu is open?
I decided to make a simple application that will hang in the tray and, when you click on the icon, show a menu with the necessary information. But ran into a problem...
import pygtk, gtk, appindicator, glib
def add_item(ind):
menu = gtk.Menu()
item = gtk.MenuItem('%s' % time.time())
menu.append(item)
separator = gtk.SeparatorMenuItem()
menu.append(separator)
item = gtk.MenuItem("Settings")
item.connect("activate", settings)
menu.append(item)
item = gtk.ImageMenuItem(gtk.STOCK_QUIT)
item.connect("activate", quit)
menu.append(item)
menu.show_all()
ind.set_menu(menu)
return True
def settings(widget, data=None):
print >> sys.stderr, 'settings'
def quit(widget, data=None):
gtk.main_quit()
if __name__ == "__main__":
ind = appindicator.Indicator ("totp-indicator", "indicator-totp", appindicator.CATEGORY_APPLICATION_STATUS)
ind.set_status (appindicator.STATUS_ACTIVE)
ind.set_attention_icon ("indicator-messages-new")
ind.set_icon("gtk-dialog-authentication-panel")
glib.timeout_add(1000, add_item, ind)
gtk.main()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question