#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""
This file is part of OpenSesame.

OpenSesame is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

OpenSesame 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenSesame.  If not, see <http://www.gnu.org/licenses/>.
"""

import os
import os.path
from PyQt4 import QtGui, QtCore
import sys
import libqtopensesame.qtopensesame
import libopensesame.misc
import time

if __name__ == "__main__":

	libopensesame.misc.change_working_dir()	
	app = QtGui.QApplication(sys.argv)

	# Show the splash screen, run the app and hide the splash
	splash = QtGui.QSplashScreen(QtGui.QPixmap(libopensesame.misc.resource("splash.png")), QtCore.Qt.WindowStaysOnTopHint)
	splash.show()
	app.processEvents()
	myapp = libqtopensesame.qtopensesame.qtopensesame()
	QtCore.QObject.connect(app, QtCore.SIGNAL("quit()"), myapp.close)
	myapp.show()
	splash.finish(myapp)

	# Open an experiment if it has been specified as a command
	# line argument and suppress the new wizard in that case
	if len(sys.argv) >= 2 and os.path.isfile(sys.argv[1]):
		new_wizard = False
		myapp.open_file(path = sys.argv[1])
	else:
		new_wizard = True

	# Run the experiment if it has been specified on the
	# command line
	if myapp.options.run:
		myapp.run_experiment()
	elif myapp.options.run_in_window:
		myapp.run_experiment(False)
	else:
		myapp.check_update(always = False)
		myapp.show_random_tip(always = False)
		if new_wizard:
			myapp.start_new_wizard()

	sys.exit(app.exec_())

