def startmain():
    """
    Initialise the application and display the main window.
    """
    app = QApplication(sys.argv)
    app.cleanup_files = []

    QApplication.setStyle(QStyleFactory.create('CleanLooks'))
    QApplication.setPalette(QApplication.style().standardPalette())

    QApplication.setApplicationName('Bing Wallpaper Changer')
    QApplication.setApplicationVersion(VERSION)
    QApplication.setOrganizationName('overThere.co.uk')
    QApplication.setWindowIcon(QIcon(':/icons/ui/ot_icon.svg'))

    print 'AppName: %s' % QApplication.applicationName()
    print 'AppVersion: %s' % QApplication.applicationVersion()
    print 'Company Name: %s' % QApplication.organizationName()

    QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedKingdom))

    # Add passed arguments to app.
    app.args = parse_arguments()
    print 'Args:', app.args

    # Check to see if application already running.
    existing_pid = instance_check(app)
    if existing_pid:
        print existing_pid
        if app.args.quit_existing:
            # Command line argument passed to close existing program. Do that, then quit.
            if platform.system() == "Windows":
                subprocess.Popen("taskkill /F /T /PID %i" % existing_pid, shell=True)
            else:
                os.killpg(existing_pid, signal.SIGKILL)
        else:
            message_box_error('Program already running.',
                              'You can only have one copy of the Bing Wallpaper Changer running at once.')
        sys.exit()

    mainwindow = MainWindow()
    # mainwindow.show()
    sys.exit(app.exec_())
def start_main():
    app = QApplication(sys.argv)

    icon = QIcon(':/icons/application.png')
    app.setWindowIcon(icon)

    # If compiled as a one-file PyInstaller package look for Qt4 Plugins in the TEMP folder.
    try:
        extra_path = [os.path.join(sys._MEIPASS, 'qt4_plugins')]
        app.setLibraryPaths(app.libraryPaths() + extra_path)
        app.utils_path = os.path.join(sys._MEIPASS, 'utils')
    except AttributeError:
        app.utils_path = os.path.join(os.getcwd(), 'utils')

    # Error handling stuff.
    if hasattr(sys, 'frozen'):
        sys.excepthook = except_hook

    app.setApplicationName('ABBYY Automator')
    app.setApplicationVersion(VERSION)
    app.setOrganizationName('Pearl Scan Solutions')

    print 'AppName: %s' % app.applicationName()
    print 'AppVersion: %s' % app.applicationVersion()
    print 'Company Name: %s' % app.organizationName()

    app.setStyle(QStyleFactory.create('Cleanlooks'))
    app.setPalette(QApplication.style().standardPalette())

    if not instance_check(app):
        message_box_error('Program already running.',
                          'You can only have one copy of ABBYY Automator running at once.')
        sys.exit()

    mainwindow = MainWindow()
    mainwindow.show()
    app.exec_()
    app.closeAllWindows()
    app.quit()