# -*- coding: utf-8 -*-
"""
Created on Mon Mar 28 22:27:17 2016

@author: ander
"""
from PyQt5 import QtGui, QtCore, QtWidgets
import sys

def main(args, version=None):

    app = QtWidgets.QApplication(args)
    splash_pix = QtGui.QPixmap('splash_loading.png')
    splash = QtWidgets.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint)
    splash.setMask(splash_pix.mask())
    splash.show()
    app.processEvents()
    app.setOrganizationName("SSHF")
    app.setApplicationName("OpenDXMC {}".format(version))
    import time
    time.sleep(5)
    from opendxmc.app.gui import MainWindow
    win = MainWindow()
    win.show()
    splash.finish(win)

    return app.exec_()



def start(version=None):
    # exit code 1 triggers a restart
    # Also testing for memory error
    try:
        while main(sys.argv, version=version) == 1:
            continue
    except MemoryError:
        msg = QtWidgets.QMessageBox()
        msg.setText("Ouch, OpenDXMC ran out of memory.")
        msg.setIcon(msg.Critical)
        msg.exec_()
    sys.exit(0)


if __name__ == "__main__":
    pass
