#!/usr/bin/python

#    Copyright 2012, SIL International
#    All rights reserved.
#
#    This library is free software; you can redistribute it and/or modify
#    it under the terms of the GNU Lesser General Public License as published
#    by the Free Software Foundation; either version 2.1 of License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Lesser General Public License for more details.
#
#    You should also have received a copy of the GNU Lesser General Public
#    License along with this library in the file named "LICENSE".
#    If not, write to the Free Software Foundation, 51 Franklin Street,
#    suite 500, Boston, MA 02110-1335, USA or visit their web page on the 
#    internet at http://www.fsf.org/licenses/lgpl.html.

import sys, os

if 'QT_API' not in os.environ :
    os.environ['QT_API'] = 'pyside2'

from qtpy import QtCore, QtWidgets
from graide import main
from argparse import ArgumentParser
from configparser import RawConfigParser

app = QtWidgets.QApplication(sys.argv)

p = ArgumentParser()
p.add_argument("-p","--project",help="Project configuration file")
p.add_argument("-f","--font",help="Font .ttf file to process")
p.add_argument("-a","--ap",help="AP XML database file for font")
p.add_argument("-g","--gdx",help="grcompiler debug output file")
p.add_argument("-r","--results",help="graphite JSON debug output")
p.add_argument("-s","--size",type=int,help="Size of glyphs to render in pixels")
args = p.parse_args()

config = RawConfigParser()
if args.project :
    config.read([args.project])
else :
    for s in ('main', 'build', 'ui') :
        config.add_section(s)

if args.font : config.set('main', 'font', args.font)
if args.ap : config.set('main', 'ap', args.ap)
if args.size and args.size > 0 : config.set('main', 'size', str(args.size))
if args.gdx : config.set('main', 'gdx', args.gdx)
if args.project :
    (dname, args.project) = os.path.split(args.project)
    if dname : os.chdir(dname)

mainWindow = main.MainWindow(config, args.project, args.results)
mainWindow.show()
sys.exit(app.exec_())
