There is a similar question at StackOverflow, but it didn't help me: Changing items while running. I tried asking at StackOverflow, but people there where not too active: How to change GTK menu in Unity Indicator Applet?.
The problem is, if I define the changing function outside of Gtk.main(), it would be never executed, and inside it would be executed just once. If I make an infinite loop inside, Gtk.main() would be never executed. This is my code (modified standard example).
#!/usr/bin/env python
import sys
from gi.repository import Gtk, Gdk
from gi.repository import AppIndicator3 as appindicator
if __name__ == "__main__":
ind = appindicator.Indicator.new ("example-simple-client",
"indicator-messages",
appindicator.IndicatorCategory.APPLICATION_STATUS)
ind.set_status (appindicator.IndicatorStatus.ACTIVE)
ind.set_attention_icon ("indicator-messages-new")
menu = Gtk.Menu()
menu_quit = Gtk.MenuItem('Quit')
def add_item(menu, label):
menu.append(MenuItem(label))
menu.append(menu_quit)
def quit_app(w):
sys.exit(0)
menu_quit.connect('activate', quit_app)
menu_quit.show()
ind.set_menu(menu)
Gtk.main()
Where do I put adding new menu items (or changing existing) in the code? I am a real newbie in GUI programming...
add_item()
? You should give a bit more information.