#!/usr/local/bin/python3
'''
Creates an instance of the program GUI and starts the main event loop.

@author: Peter Parente
@author: Eitan Isaacson
@organization: IBM Corporation
@copyright: Copyright (c) 2006 IBM Corporation
@license: BSD

All rights reserved. This program and the accompanying materials are made
available under the terms of the BSD which accompanies this distribution, and
is available at U{http://www.opensource.org/licenses/bsd-license.php}
'''
import gi

from gi.repository import GLib

import sys, os

# force running on X11/XWayland because window positioning
# needed for the highlighting feature doesn't work on Wayland
os.environ['GDK_BACKEND'] = 'x11'

# make the accerciser directory part of the path to aid user imports
sys.path.append(os.path.join(GLib.get_user_config_dir(), 'accerciser'))
# We can't rely on prefix if we're installed by relocated RPM. Instead, we
# use __file__ and for now hope that lib is relative to bin.
sys.prefix = '/usr/local'
libs = os.path.join(sys.prefix, 'lib',
                    'python3.12', 'site-packages')
# point to the proper site-packages path
sys.path.insert(1, libs)

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
# initialize threads
# get global icon resources
it = gtk.IconTheme()
try:
  icons = [it.load_icon('accerciser', size, gtk.IconLookupFlags.NO_SVG)
           for size in (16, 22, 32)]
except Exception:
  # ignore errors, and just don't use the icon
  pass
else:
  # TODO: REVIEW
  gtk.Window.set_default_icon_list(icons)


import accerciser
accerciser.main()
