gnome-music.in 1.5 KB
Newer Older
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
1
#!/usr/bin/env python3
Guillaume Quintard's avatar
Guillaume Quintard committed
2

3
import sys, signal, os
4 5
sys.path.insert(1, '@pyexecdir@')

6
from gi.repository import Gio, Gtk
7 8 9 10 11
import gnomemusic

srcdir = os.path.abspath(os.path.join(os.path.dirname(gnomemusic.__file__), '..'))
if os.path.exists(os.path.join(srcdir, 'gnome-music.doap')):
    print('Running from source tree, using local files')
12
    pkgdatadir = os.path.join(srcdir, 'data')
13 14 15
    libgd_libdir = os.path.join(srcdir, 'libgd', '.libs')
    libgd_typelibdir = os.path.join(srcdir, 'libgd')
else:
16
    pkgdatadir = '@pkgdatadir@'
17 18 19 20 21 22 23
    libgd_libdir = '@pkglibdir@'
    libgd_typelibdir = '@pkglibdir@/girepository-1.0'

# We use our own libgd.so, so let gi.repository find it
from gi.repository import GIRepository
GIRepository.Repository.prepend_search_path(libgd_typelibdir)
GIRepository.Repository.prepend_library_path(libgd_libdir)
Guillaume Quintard's avatar
Guillaume Quintard committed
24 25 26

from gnomemusic.application import Application

27 28
def install_excepthook():
    """ Make sure we exit when an unhandled exception occurs. """
29
    from gi.repository import Gtk
30 31 32 33 34 35 36 37
    old_hook = sys.excepthook
    def new_hook(etype, evalue, etb):
        old_hook(etype, evalue, etb)
        while Gtk.main_level():
            Gtk.main_quit()
        sys.exit()
    sys.excepthook = new_hook

Guillaume Quintard's avatar
Guillaume Quintard committed
38
if __name__ == "__main__":
39 40
    install_excepthook()

41
    resource = Gio.resource_load(os.path.join(pkgdatadir, 'gnome-music.gresource'))
42 43
    Gio.Resource._register(resource)

44
    app = Application()
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
45
    signal.signal(signal.SIGINT, signal.SIG_DFL)
46 47
    exit_status = app.run(sys.argv)
    sys.exit(exit_status)