使用 python gtk3 appindicator 创建两个或更多面板指示器
Ctreate two or more panel indicator using python gtk3 appindicator
我想使用一个指标创建两个或多个面板指标 class。这是代码:
#!/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()
但是当我 运行 脚本时没有任何反应。我如何使用单个 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()
这是使用单个 class 创建一个或多个 appindicator 的正确方法。
我想使用一个指标创建两个或多个面板指标 class。这是代码:
#!/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()
但是当我 运行 脚本时没有任何反应。我如何使用单个 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()
这是使用单个 class 创建一个或多个 appindicator 的正确方法。