Compare commits
2 commits
d97d396ef3
...
269c6e511f
| Author | SHA1 | Date | |
|---|---|---|---|
| 269c6e511f | |||
| 2713c17550 |
2 changed files with 39 additions and 33 deletions
|
|
@ -9,15 +9,9 @@ import webbrowser
|
|||
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')
|
||||
icon = os.path.join(base, 'openmedialibrary/static/svg/oml.svg')
|
||||
title = "Open Media Library"
|
||||
ctl = base + '/ctl'
|
||||
|
||||
|
|
@ -34,26 +28,29 @@ def check_pid(pid):
|
|||
else:
|
||||
return True
|
||||
|
||||
class OMLIcon:
|
||||
def preexec(): # Don't forward signals.
|
||||
os.setpgrp()
|
||||
|
||||
|
||||
class OMLStatus:
|
||||
menu = None
|
||||
icon = None
|
||||
indicator = None
|
||||
|
||||
def __init__(self, autostart=False):
|
||||
self.autostart = autostart
|
||||
self.create_pid()
|
||||
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.win = Gtk.Window()
|
||||
self.win.set_icon_from_file(icon)
|
||||
self.win.set_title(title)
|
||||
#self.win.show_all()
|
||||
self.win.iconify()
|
||||
'''
|
||||
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)
|
||||
'''
|
||||
subprocess.Popen([ctl, 'start'], close_fds=True, preexec_fn=preexec)
|
||||
if not self.autostart:
|
||||
GLib.timeout_add_seconds(1, self._open, None)
|
||||
|
|
@ -152,16 +149,14 @@ class OMLIcon:
|
|||
url += '#%s' % port
|
||||
webbrowser.open_new_tab(url)
|
||||
|
||||
def preexec(): # Don't forward signals.
|
||||
os.setpgrp()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import signal
|
||||
autostart = len(sys.argv) > 1 and sys.argv[1] == '--autostart'
|
||||
if OMLIcon.is_running():
|
||||
OMLIcon.load()
|
||||
if OMLStatus.is_running():
|
||||
OMLStatus.load()
|
||||
else:
|
||||
oml = OMLIcon(autostart)
|
||||
oml = OMLStatus(autostart)
|
||||
main_loop = GLib.MainLoop()
|
||||
try:
|
||||
main_loop.run()
|
||||
|
|
|
|||
|
|
@ -22,17 +22,26 @@ logger = logging.getLogger(__name__)
|
|||
MAX_WORKERS = 4
|
||||
|
||||
|
||||
|
||||
class Icons(dict):
|
||||
|
||||
def __init__(self, db):
|
||||
self._db = db
|
||||
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):
|
||||
conn = sqlite3.connect(self._db, timeout=90)
|
||||
return conn
|
||||
|
||||
def create(self):
|
||||
folder = os.path.dirname(self._db)
|
||||
if os.path.exists(folder):
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute('CREATE TABLE IF NOT EXISTS icon (id varchar(64) unique, data blob)')
|
||||
|
|
@ -139,6 +148,8 @@ def get_icons_db_path():
|
|||
return icons_db_path
|
||||
|
||||
def get_icon_sync(id, type_, size):
|
||||
if not icons.is_available():
|
||||
return ''
|
||||
if size:
|
||||
skey = '%s:%s:%s' % (type_, id, size)
|
||||
data = icons[skey]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue