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

Arnel A. Borja's avatar
Arnel A. Borja committed
3
import sys, signal, os, locale, gettext
4 5

# Make sure we'll find the pygobject module, even in JHBuild
6
sys.path.insert(1, '@pyexecdir@')
7 8
# Make sure we'll find the gnomemusic module, even in JHBuild
sys.path.insert(1, '@pythondir@')
9

10
from gi.repository import Gio, Gtk
11 12
import gnomemusic

Arnel A. Borja's avatar
Arnel A. Borja committed
13
localedir='@localedir@'
14 15 16
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')
17
    pkgdatadir = os.path.join(srcdir, 'data')
18 19
    libgd_libdir = os.path.join(srcdir, 'libgd', '.libs')
    libgd_typelibdir = os.path.join(srcdir, 'libgd')
20 21
    if not os.environ.get('GSETTINGS_SCHEMA_DIR'):
        os.environ['GSETTINGS_SCHEMA_DIR'] = pkgdatadir
22
else:
23
    pkgdatadir = '@pkgdatadir@'
24 25 26 27 28 29 30
    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
31 32 33

from gnomemusic.application import Application

34 35
def install_excepthook():
    """ Make sure we exit when an unhandled exception occurs. """
36
    from gi.repository import Gtk
37 38 39 40 41 42 43 44
    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
45
if __name__ == "__main__":
46 47
    install_excepthook()

Arnel A. Borja's avatar
Arnel A. Borja committed
48 49 50 51 52
    locale.bindtextdomain('gnome-music', localedir)
    locale.textdomain('gnome-music')
    gettext.bindtextdomain('gnome-music', localedir)
    gettext.textdomain('gnome-music')

53
    resource = Gio.resource_load(os.path.join(pkgdatadir, 'gnome-music.gresource'))
54 55
    Gio.Resource._register(resource)

56
    app = Application()
Vadim Rutkovsky's avatar
Vadim Rutkovsky committed
57
    signal.signal(signal.SIGINT, signal.SIG_DFL)
58 59
    exit_status = app.run(sys.argv)
    sys.exit(exit_status)