use appindicator to also show icon in unity
This commit is contained in:
parent
6ade6c0928
commit
f57b75ac03
1 changed files with 34 additions and 15 deletions
|
@ -8,21 +8,37 @@ import _thread
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, GLib
|
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__))))
|
base = dirname(dirname(dirname(abspath(__file__))))
|
||||||
icon = os.path.join(base, 'openmedialibrary/static/png/oml.png')
|
icon = os.path.join(base, 'openmedialibrary/static/png/oml.png')
|
||||||
title = "Open Media Library"
|
title = "Open Media Library"
|
||||||
ctl = base + '/ctl'
|
ctl = base + '/ctl'
|
||||||
|
|
||||||
|
|
||||||
class OMLIcon:
|
class OMLIcon:
|
||||||
menu = None
|
menu = None
|
||||||
|
icon = None
|
||||||
|
indicator = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.icon = Gtk.StatusIcon()
|
if appindicator:
|
||||||
self.icon.set_from_file(icon)
|
self.indicator = appindicator.Indicator.new("OML", icon,
|
||||||
self.icon.set_title(title)
|
appindicator.IndicatorCategory.APPLICATION_STATUS)
|
||||||
self.icon.connect("activate", self._click)
|
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
|
||||||
self.icon.connect("popup-menu", self._click)
|
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)
|
||||||
|
self.icon.connect("activate", self._click)
|
||||||
|
self.icon.connect("popup-menu", self._click)
|
||||||
self._p = subprocess.Popen([ctl, 'start'])
|
self._p = subprocess.Popen([ctl, 'start'])
|
||||||
GLib.timeout_add_seconds(1, self._open, None)
|
GLib.timeout_add_seconds(1, self._open, None)
|
||||||
_thread.start_new_thread(self._wait, ())
|
_thread.start_new_thread(self._wait, ())
|
||||||
|
@ -31,23 +47,26 @@ class OMLIcon:
|
||||||
self._p.wait()
|
self._p.wait()
|
||||||
self._quit(None)
|
self._quit(None)
|
||||||
|
|
||||||
|
def get_menu(self):
|
||||||
|
menu = Gtk.Menu()
|
||||||
|
about = Gtk.MenuItem(label="Open")
|
||||||
|
about.connect("activate", self._open)
|
||||||
|
menu.append(about)
|
||||||
|
quit = Gtk.MenuItem(label="Quit")
|
||||||
|
quit.connect("activate", self._quit)
|
||||||
|
menu.append(quit)
|
||||||
|
menu.show_all()
|
||||||
|
return menu
|
||||||
|
|
||||||
def _click(self, icon, button=None, time=None):
|
def _click(self, icon, button=None, time=None):
|
||||||
if self.menu:
|
if self.menu:
|
||||||
self.menu.destroy()
|
self.menu.destroy()
|
||||||
self.menu = None
|
self.menu = None
|
||||||
else:
|
else:
|
||||||
|
self.menu = self.get_menu()
|
||||||
button = 1
|
button = 1
|
||||||
time = Gtk.get_current_event_time()
|
time = Gtk.get_current_event_time()
|
||||||
menu = Gtk.Menu()
|
self.menu.popup(None, None, self.icon.position_menu, icon, button, time)
|
||||||
about = Gtk.MenuItem(label="Open")
|
|
||||||
about.connect("activate", self._open)
|
|
||||||
menu.append(about)
|
|
||||||
quit = Gtk.MenuItem(label="Quit")
|
|
||||||
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
|
|
||||||
|
|
||||||
def _quit(self, q):
|
def _quit(self, q):
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
|
|
Loading…
Reference in a new issue