use appindicator to also show icon in unity

This commit is contained in:
j 2016-01-09 16:01:51 +05:30
parent 6ade6c0928
commit f57b75ac03

View file

@ -8,16 +8,32 @@ import _thread
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
try:
gi.require_version('AppIndicator3', '0.1')
from gi.repository import AppIndicator3 as appindicator
except:
appindicator = None
base = dirname(dirname(dirname(abspath(__file__))))
icon = os.path.join(base, 'openmedialibrary/static/png/oml.png')
title = "Open Media Library"
ctl = base + '/ctl'
class OMLIcon:
menu = None
icon = None
indicator = None
def __init__(self):
if appindicator:
self.indicator = appindicator.Indicator.new("OML", icon,
appindicator.IndicatorCategory.APPLICATION_STATUS)
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
self.menu = self.get_menu()
self.indicator.set_menu(self.menu)
else:
self.icon = Gtk.StatusIcon()
self.icon.set_from_file(icon)
self.icon.set_title(title)
@ -31,13 +47,7 @@ class OMLIcon:
self._p.wait()
self._quit(None)
def _click(self, icon, button=None, time=None):
if self.menu:
self.menu.destroy()
self.menu = None
else:
button = 1
time = Gtk.get_current_event_time()
def get_menu(self):
menu = Gtk.Menu()
about = Gtk.MenuItem(label="Open")
about.connect("activate", self._open)
@ -46,8 +56,17 @@ class OMLIcon:
quit.connect("activate", self._quit)
menu.append(quit)
menu.show_all()
menu.popup(None, None, self.icon.position_menu, icon, button, time)
self.menu = menu
return menu
def _click(self, icon, button=None, time=None):
if self.menu:
self.menu.destroy()
self.menu = None
else:
self.menu = self.get_menu()
button = 1
time = Gtk.get_current_event_time()
self.menu.popup(None, None, self.icon.position_menu, icon, button, time)
def _quit(self, q):
Gtk.main_quit()