Compare commits
No commits in common. "269c6e511f7f48ab2f6bc50ad6e7b7887c33305a" and "d97d396ef306a4bba9ab156f470c9db6d435d4d0" have entirely different histories.
269c6e511f
...
d97d396ef3
2 changed files with 33 additions and 39 deletions
|
|
@ -9,9 +9,15 @@ import webbrowser
|
||||||
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/svg/oml.svg')
|
icon = os.path.join(base, 'openmedialibrary/static/png/oml.png')
|
||||||
title = "Open Media Library"
|
title = "Open Media Library"
|
||||||
ctl = base + '/ctl'
|
ctl = base + '/ctl'
|
||||||
|
|
||||||
|
|
@ -28,29 +34,26 @@ def check_pid(pid):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def preexec(): # Don't forward signals.
|
class OMLIcon:
|
||||||
os.setpgrp()
|
|
||||||
|
|
||||||
|
|
||||||
class OMLStatus:
|
|
||||||
menu = None
|
menu = None
|
||||||
icon = None
|
icon = None
|
||||||
|
indicator = None
|
||||||
|
|
||||||
def __init__(self, autostart=False):
|
def __init__(self, autostart=False):
|
||||||
self.autostart = autostart
|
self.autostart = autostart
|
||||||
self.create_pid()
|
self.create_pid()
|
||||||
self.win = Gtk.Window()
|
if appindicator:
|
||||||
self.win.set_icon_from_file(icon)
|
self.indicator = appindicator.Indicator.new("OML", icon,
|
||||||
self.win.set_title(title)
|
appindicator.IndicatorCategory.APPLICATION_STATUS)
|
||||||
#self.win.show_all()
|
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
|
||||||
self.win.iconify()
|
self.menu = self.get_menu()
|
||||||
'''
|
self.indicator.set_menu(self.menu)
|
||||||
self.icon = Gtk.StatusIcon()
|
else:
|
||||||
self.icon.set_from_file(icon)
|
self.icon = Gtk.StatusIcon()
|
||||||
self.icon.set_title(title)
|
self.icon.set_from_file(icon)
|
||||||
self.icon.connect("activate", self._click)
|
self.icon.set_title(title)
|
||||||
self.icon.connect("popup-menu", self._click)
|
self.icon.connect("activate", self._click)
|
||||||
'''
|
self.icon.connect("popup-menu", self._click)
|
||||||
subprocess.Popen([ctl, 'start'], close_fds=True, preexec_fn=preexec)
|
subprocess.Popen([ctl, 'start'], close_fds=True, preexec_fn=preexec)
|
||||||
if not self.autostart:
|
if not self.autostart:
|
||||||
GLib.timeout_add_seconds(1, self._open, None)
|
GLib.timeout_add_seconds(1, self._open, None)
|
||||||
|
|
@ -149,14 +152,16 @@ class OMLStatus:
|
||||||
url += '#%s' % port
|
url += '#%s' % port
|
||||||
webbrowser.open_new_tab(url)
|
webbrowser.open_new_tab(url)
|
||||||
|
|
||||||
|
def preexec(): # Don't forward signals.
|
||||||
|
os.setpgrp()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import signal
|
import signal
|
||||||
autostart = len(sys.argv) > 1 and sys.argv[1] == '--autostart'
|
autostart = len(sys.argv) > 1 and sys.argv[1] == '--autostart'
|
||||||
if OMLStatus.is_running():
|
if OMLIcon.is_running():
|
||||||
OMLStatus.load()
|
OMLIcon.load()
|
||||||
else:
|
else:
|
||||||
oml = OMLStatus(autostart)
|
oml = OMLIcon(autostart)
|
||||||
main_loop = GLib.MainLoop()
|
main_loop = GLib.MainLoop()
|
||||||
try:
|
try:
|
||||||
main_loop.run()
|
main_loop.run()
|
||||||
|
|
|
||||||
|
|
@ -22,32 +22,23 @@ logger = logging.getLogger(__name__)
|
||||||
MAX_WORKERS = 4
|
MAX_WORKERS = 4
|
||||||
|
|
||||||
|
|
||||||
class Icons(dict):
|
|
||||||
|
|
||||||
|
class Icons(dict):
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
self._db = db
|
self._db = db
|
||||||
self.create()
|
self.create()
|
||||||
|
|
||||||
def is_available(self):
|
|
||||||
folder = os.path.dirname(self._db)
|
|
||||||
if os.path.exists(folder):
|
|
||||||
if not os.path.exists(self._db):
|
|
||||||
self.create()
|
|
||||||
return os.path.exists(self._db)
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
conn = sqlite3.connect(self._db, timeout=90)
|
conn = sqlite3.connect(self._db, timeout=90)
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
folder = os.path.dirname(self._db)
|
conn = self.connect()
|
||||||
if os.path.exists(folder):
|
c = conn.cursor()
|
||||||
conn = self.connect()
|
c.execute('CREATE TABLE IF NOT EXISTS icon (id varchar(64) unique, data blob)')
|
||||||
c = conn.cursor()
|
c.execute('CREATE TABLE IF NOT EXISTS setting (key varchar(256) unique, value text)')
|
||||||
c.execute('CREATE TABLE IF NOT EXISTS icon (id varchar(64) unique, data blob)')
|
if int(self.get_setting(c, 'version', 0)) < 1:
|
||||||
c.execute('CREATE TABLE IF NOT EXISTS setting (key varchar(256) unique, value text)')
|
self.set_setting(c, 'version', 1)
|
||||||
if int(self.get_setting(c, 'version', 0)) < 1:
|
|
||||||
self.set_setting(c, 'version', 1)
|
|
||||||
|
|
||||||
def get_setting(self, c, key, default=None):
|
def get_setting(self, c, key, default=None):
|
||||||
c.execute('SELECT value FROM setting WHERE key = ?', (key, ))
|
c.execute('SELECT value FROM setting WHERE key = ?', (key, ))
|
||||||
|
|
@ -148,8 +139,6 @@ def get_icons_db_path():
|
||||||
return icons_db_path
|
return icons_db_path
|
||||||
|
|
||||||
def get_icon_sync(id, type_, size):
|
def get_icon_sync(id, type_, size):
|
||||||
if not icons.is_available():
|
|
||||||
return ''
|
|
||||||
if size:
|
if size:
|
||||||
skey = '%s:%s:%s' % (type_, id, size)
|
skey = '%s:%s:%s' % (type_, id, size)
|
||||||
data = icons[skey]
|
data = icons[skey]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue