Esempio n. 1
0
def preload(modules, app=None):
    if not app:
        from qtsix import QtWidgets
        app = QtWidgets.qApp

    timer = Timer()
    log = logging.getLogger(__name__)
    for modname in modules:
        log.info(app.tr('Importing %s module ...'), modname)
        app.processEvents()
        __import__(modname)
        log.debug('%s import: %d.%06ds', modname, *timer.update())
        app.processEvents()
Esempio n. 2
0
def main():
    # @IMPORTANT: force numeric locale to 'C' in order to avoid problems
    #             with GDAL and PPROJ4
    # @SEEALSO: http://trac.osgeo.org/gdal/wiki/FAQMiscellaneous#DoesGDALworkindifferentinternationalnumericlocales
    import os
    os.environ['LC_NUMERIC'] = 'C'

    args = parse_args()

    if args.log_level != 'NOTSET':
        loglevel = logging.getLevelName(args.log_level)
    else:
        loglevel = logging.INFO

    logging.basicConfig(
        level=loglevel,
        #format='%(levelname)s: %(message)s')
        format='%(asctime)s %(name)s %(levelname)s: %(message)s')

    # set the logging level explicitly on gsdview logger
    #logging.getLogger().setLevel(loglevel)
    logging.getLogger('gsdview').setLevel(loglevel)

    # PyQt loggers
    logging.getLogger('PyQt5.uic').setLevel(logging.WARNING)

    log = logging.getLogger(__name__)
    log.debug('log level set to %s', logging.getLevelName(log.level))

    # @TODO:
    # * config logging using options.configfile, USER_CFG, SYS_CFG
    # * if options.debug: set rootlogger.level = logging.DEBUG
    # * maybe set loglevelfor other loggers

    timer = Timer()

    # splash screen #########################################################
    from qtsix import QtWidgets, QtGui
    log.debug('Qt import: %d.%06ds', *timer.update())

    import sys
    from gsdview.info import name as NAME
    from gsdview.info import version as VERSION
    from gsdview.utils import getresource

    app = QtWidgets.QApplication(sys.argv)
    app.setApplicationName(NAME)
    app.setApplicationVersion(VERSION)

    pngfile = getresource(os.path.join('images', 'splash.png'), __name__)
    pixmap = QtGui.QPixmap(pngfile)
    splash = QtWidgets.QSplashScreen(pixmap)
    splash.show()
    app.processEvents()

    splash_loghandler = SplashLogHandler(splash, app)
    splash_loghandler.setFormatter(logging.Formatter('%(message)s'))

    log.addHandler(splash_loghandler)

    log.info('Splash screen setup completed')
    log.debug('splash screen setup: %d.%06ds', *timer.update())

    # modules loading #######################################################
    preload(MODULES, app)

    # GUI ###################################################################
    log.info('Build GUI ...')

    from gsdview.app import GSDView

    # @TODO: pass plugins_path??
    mainwin = GSDView(loglevel=args.log_level)
    mainwin.show()
    log.info('GUI setup completed')
    log.debug('GUI setup: %d.%06ds', *timer.update())

    # close splash and run app ##############################################
    log.removeHandler(splash_loghandler)
    splash.finish(mainwin)
    app.processEvents()

    log.info('Install the exception hook')
    sys.excepthook = mainwin.excepthook     # @TODO: check

    log.info('Enter main event loop')

    # @COMPATIBILITY: this will raise the window on Mac OS X
    mainwin.raise_()

    sys.exit(app.exec_())