#!/usr/bin/python

import sys
import os
import locale
import gettext

sys.path.insert(1, '/usr/lib/python3.7')
sys.path.insert(1, '/usr/lib/python3.7/site-packages')

from gi.repository import Gio

localedir = '/usr/share/locale'
pkgdatadir = '/usr/share/passwordsafe'
extensiondir = '/usr/lib/passwordsafe'

from passwordsafe.application import Application

def install_excepthook():
    """ Make sure we exit when an unhandled exception occurs. """
    from gi.repository import Gtk
    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

if __name__ == "__main__":
    install_excepthook()

    locale.bindtextdomain('passwordsafe', localedir)
    locale.textdomain('passwordsafe')
    gettext.bindtextdomain('passwordsafe', localedir)
    gettext.textdomain('passwordsafe')

    resource = Gio.resource_load(os.path.join(pkgdatadir, 'passwordsafe.gresource'))
    Gio.Resource._register(resource)

    if "" == 'Devel':
    	Application.development_mode = True
    	Application.application_id = 'org.gnome.PasswordSafeDevel'
    else:
    	Application.development_mode = False

    app = Application()

    exit_status = app.run(sys.argv)
    sys.exit(exit_status)
