I want to create two or more panel indicator using a single indicator class. This is the code:
#!/usr/bin/env python
import os
from gi.repository import Gtk
from gi.repository import AppIndicator3
class IndicatorObject:
def create_indicator(self, indicator_id):
indicator = AppIndicator3.Indicator.new(indicator_id, os.path.abspath('sample_icon.svg'), AppIndicator3.IndicatorCategory.SYSTEM_SERVICES)
indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
menu = Gtk.Menu()
item_quit = Gtk.MenuItem('Quit')
menu.append(item_quit)
indicator.set_menu(menu)
menu.show_all()
print indicator_id
indicator1 = IndicatorObject()
indicator1.create_indicator("first_indicator")
indicator2 = IndicatorObject()
indicator2.create_indicator("second_indicator")
Gtk.main()
But nothing happens when i run the script. How can i create two or more indicator using single class?
#!/usr/bin/env python
import os
from gi.repository import Gtk
from gi.repository import AppIndicator3
class AppIndicatorExample:
def __init__(self, indicator_id):
self.ind = AppIndicator3.Indicator.new(str(indicator_id), os.path.abspath('sample_icon.svg'), AppIndicator3.IndicatorCategory.SYSTEM_SERVICES)
self.ind.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
# create a menu
self.menu = Gtk.Menu()
item = Gtk.MenuItem(str(indicator_id))
item.show()
self.menu.append(item)
image = Gtk.ImageMenuItem(Gtk.STOCK_QUIT)
image.connect("activate", self.quit)
image.show()
self.menu.append(image)
self.menu.show()
self.ind.set_menu(self.menu)
def quit(self, widget, data=None):
Gtk.main_quit()
if __name__ == "__main__":
indicator = AppIndicatorExample(1)
indicator2 = AppIndicatorExample(2)
indicator3 = AppIndicatorExample(3)
indicator4 = AppIndicatorExample(4)
indicator5 = AppIndicatorExample(5)
indicator6 = AppIndicatorExample(6)
indicator7 = AppIndicatorExample(7)
indicator8 = AppIndicatorExample(8)
Gtk.main()
This is the right way to using single class to create one or more appindicator.