Example #1
0
def startApplication(argv, verbose=False, clear=[], dirs={}):
    """Preparing Luma for take-off

    Parameters:

    - `verbose`: boolean value indicating whether or not to print more
      than error messages to console.
    - `clear`: a list containing what should be cleared before start.
    - `dirs`: a dictionary containing containing possible dirs to
      consider on start-up.
    """
    app = Luma(argv)

    """ Fixed but not removed in case we change our minds """
    #import platform
    #if sys.platform.lower().startswith('win'):
        # Avoids ugly white background
        #from PyQt4.QtGui import QStyleFactory
        #QApplication.setStyle(QStyleFactory.create("plastique"))
        #QApplication.setPalette(QApplication.style().standardPalette())

    app.setOrganizationName(appinfo.ORGNAME)
    app.setApplicationName(appinfo.APPNAME)
    app.setApplicationVersion(appinfo.VERSION)
    app.setWindowIcon(QIcon(':/icons/128/luma'))

    # Setup the logging mechanism
    l = logging.getLogger()
    l.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        "[%(threadName)s] - %(name)s - %(levelname)s - %(message)s"
    )

    # Keep all logs from now until the GUI-LoggerWidget is up and can
    # be populated
    tmpLH = TempLogHandler()
    l.addHandler(tmpLH)

    settings = Settings()
    # Because we use QSettings for the application settings we
    # facilitate QSettings if the user wishes to start Luma fresh
    if 'config' in clear:
        clear.remove('config')
        settings.clear()

    if settings.configPrefix == '':
        # This will be the case on the first run, or if the user
        # have startet the application with the --clear-config option
        # We therefore need to retrive the config prefix in a best
        # practize cross-platform way
        #
        # NOTE: The first return value is a bool that indicates wheter
        #       the configprefix exists or not. As of now the config
        #       prefix is return regardless if it is writable or not.
        (_, settings.configPrefix) = getConfigPrefix()

    (_, configPrefix) = getConfigPrefix()

    if verbose:
        """If verbose mode is enabled we start logging to the console
        TODO: Add support for adjusting the level of verbosity ?
        """
        consoleHandler = logging.StreamHandler()
        consoleHandler.setFormatter(formatter)
        l.addHandler(consoleHandler)

    __handleClearOptions(configPrefix, clear)

    # Initialize the splash screen
    splash = SplashScreen()
    splash.show()

    # Initialize the main window

    from base.gui.MainWindow import MainWindow
    mainwin = MainWindow()

    # Set up logging to the loggerwidget
    llh = LumaLogHandler(mainwin.loggerWidget)
    l.removeHandler(tmpLH)  # Stop temp-logging
    l.addHandler(llh)  # Start proper logging

    # Populate the loggerWidget with the saved entries
    for x in tmpLH.logList:
        llh.emit(x)

    app.lastWindowClosed.connect(mainwin.close)

    mainwin.show()
    splash.finish(mainwin)

    # Add a exception hook to handle all
    # exceptions missed in the main application
    sys.excepthook = unhandledException

    # Need to activate the mainwindow in order to have focus,
    # if the application is started in fullscreen mode
    mainwin.activateWindow()
    sys.exit(app.exec_())