2015-12-07 16:17:57 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
from os.path import dirname, abspath
|
|
|
|
import subprocess
|
|
|
|
import webbrowser
|
2016-01-09 10:11:42 +00:00
|
|
|
import _thread
|
2015-12-07 16:17:57 +00:00
|
|
|
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk, GLib
|
2016-01-09 10:31:51 +00:00
|
|
|
try:
|
|
|
|
gi.require_version('AppIndicator3', '0.1')
|
|
|
|
from gi.repository import AppIndicator3 as appindicator
|
|
|
|
except:
|
|
|
|
appindicator = None
|
|
|
|
|
2015-12-07 16:17:57 +00:00
|
|
|
|
|
|
|
base = dirname(dirname(dirname(abspath(__file__))))
|
|
|
|
icon = os.path.join(base, 'openmedialibrary/static/png/oml.png')
|
|
|
|
title = "Open Media Library"
|
|
|
|
ctl = base + '/ctl'
|
|
|
|
|
2016-01-09 10:31:51 +00:00
|
|
|
|
2015-12-07 16:17:57 +00:00
|
|
|
class OMLIcon:
|
|
|
|
menu = None
|
2016-01-09 10:31:51 +00:00
|
|
|
icon = None
|
|
|
|
indicator = None
|
2015-12-07 16:17:57 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2016-01-09 10:31:51 +00:00
|
|
|
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)
|
|
|
|
self.icon.connect("activate", self._click)
|
|
|
|
self.icon.connect("popup-menu", self._click)
|
2016-01-09 10:11:42 +00:00
|
|
|
self._p = subprocess.Popen([ctl, 'start'])
|
2015-12-07 16:17:57 +00:00
|
|
|
GLib.timeout_add_seconds(1, self._open, None)
|
2016-01-09 10:11:42 +00:00
|
|
|
_thread.start_new_thread(self._wait, ())
|
|
|
|
|
|
|
|
def _wait(self):
|
|
|
|
self._p.wait()
|
|
|
|
self._quit(None)
|
2015-12-07 16:17:57 +00:00
|
|
|
|
2016-01-09 10:31:51 +00:00
|
|
|
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
|
|
|
|
|
2016-01-05 17:43:52 +00:00
|
|
|
def _click(self, icon, button=None, time=None):
|
2015-12-07 16:17:57 +00:00
|
|
|
if self.menu:
|
|
|
|
self.menu.destroy()
|
|
|
|
self.menu = None
|
|
|
|
else:
|
2016-01-09 10:31:51 +00:00
|
|
|
self.menu = self.get_menu()
|
2015-12-07 16:17:57 +00:00
|
|
|
button = 1
|
|
|
|
time = Gtk.get_current_event_time()
|
2016-01-09 10:31:51 +00:00
|
|
|
self.menu.popup(None, None, self.icon.position_menu, icon, button, time)
|
2015-12-07 16:17:57 +00:00
|
|
|
|
|
|
|
def _quit(self, q):
|
|
|
|
Gtk.main_quit()
|
|
|
|
p = subprocess.Popen([ctl, 'stop'])
|
|
|
|
self.menu = None
|
|
|
|
|
|
|
|
def _open(self, *args):
|
|
|
|
url = 'file://' + base + '/openmedialibrary/static/html/load.html'
|
|
|
|
webbrowser.open_new_tab(url)
|
|
|
|
self.menu = None
|
|
|
|
|
|
|
|
OMLIcon()
|
|
|
|
Gtk.main()
|