~tomasgroth/openlp/portable-path

« back to all changes in this revision

Viewing changes to openlp/core/app.py

  • Committer: Tomas Groth
  • Date: 2019-04-30 19:02:42 UTC
  • mfrom: (2829.2.32 openlp)
  • Revision ID: tomasgroth@yahoo.dk-20190430190242-6zwjk8724tyux70m
trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection                                      #
6
6
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2018 OpenLP Developers                                   #
 
7
# Copyright (c) 2008-2019 OpenLP Developers                                   #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it     #
10
10
# under the terms of the GNU General Public License as published by the Free  #
33
33
from datetime import datetime
34
34
from traceback import format_exception
35
35
 
36
 
from PyQt5 import QtCore, QtWidgets
 
36
from PyQt5 import QtCore, QtWebEngineWidgets, QtWidgets  # noqa
37
37
 
 
38
from openlp.core.state import State
38
39
from openlp.core.common import is_macosx, is_win
39
40
from openlp.core.common.applocation import AppLocation
 
41
from openlp.core.loader import loader
40
42
from openlp.core.common.i18n import LanguageManager, UiStrings, translate
41
 
from openlp.core.common.path import create_paths, copytree, str_to_path
 
43
from openlp.core.common.path import copytree, create_paths, str_to_path
42
44
from openlp.core.common.registry import Registry
43
45
from openlp.core.common.settings import Settings
44
46
from openlp.core.display.screens import ScreenList
45
47
from openlp.core.resources import qInitResources
46
 
from openlp.core.ui import SplashScreen
 
48
from openlp.core.server import Server
47
49
from openlp.core.ui.exceptionform import ExceptionForm
48
50
from openlp.core.ui.firsttimeform import FirstTimeForm
49
51
from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm
50
52
from openlp.core.ui.mainwindow import MainWindow
 
53
from openlp.core.ui.splashscreen import SplashScreen
51
54
from openlp.core.ui.style import get_application_stylesheet
52
 
from openlp.core.server import Server
53
55
from openlp.core.version import check_for_update, get_version
54
56
 
 
57
 
55
58
__all__ = ['OpenLP', 'main']
56
59
 
57
60
 
72
75
        """
73
76
        self.is_event_loop_active = True
74
77
        result = QtWidgets.QApplication.exec()
75
 
        self.server.close_server()
 
78
        if hasattr(self, 'server'):
 
79
            self.server.close_server()
76
80
        return result
77
81
 
78
82
    def run(self, args):
97
101
            ftw.initialize(screens)
98
102
            if ftw.exec() == QtWidgets.QDialog.Accepted:
99
103
                Settings().setValue('core/has run wizard', True)
100
 
            elif ftw.was_cancelled:
 
104
            else:
101
105
                QtCore.QCoreApplication.exit()
102
106
                sys.exit()
103
107
        # Correct stylesheet bugs
113
117
        # Check if OpenLP has been upgrade and if a backup of data should be created
114
118
        self.backup_on_upgrade(has_run_wizard, can_show_splash)
115
119
        # start the main app window
 
120
        loader()
116
121
        self.main_window = MainWindow()
117
122
        Registry().execute('bootstrap_initialise')
 
123
        State().flush_preconditions()
118
124
        Registry().execute('bootstrap_post_set_up')
119
125
        Registry().initialise = False
120
126
        self.main_window.show()
132
138
        if Settings().value('core/update check'):
133
139
            check_for_update(self.main_window)
134
140
        self.main_window.is_display_blank()
135
 
        self.main_window.app_startup()
 
141
        Registry().execute('bootstrap_completion')
136
142
        return self.exec()
137
143
 
138
144
    @staticmethod
288
294
    :return: a tuple of parsed options of type optparse.Value and a list of remaining argsZ
289
295
    """
290
296
    # Set up command line options.
291
 
    parser = argparse.ArgumentParser(prog='openlp.py')
 
297
    parser = argparse.ArgumentParser(prog='openlp')
292
298
    parser.add_argument('-e', '--no-error-form', dest='no_error_form', action='store_true',
293
299
                        help='Disable the error notification form.')
294
300
    parser.add_argument('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
313
319
    """
314
320
    create_paths(log_path, do_not_log=True)
315
321
    file_path = log_path / 'openlp.log'
316
 
    # TODO: FileHandler accepts a Path object in Py3.6
317
 
    logfile = logging.FileHandler(str(file_path), 'w', encoding='UTF-8')
318
 
    logfile.setFormatter(logging.Formatter('%(asctime)s %(name)-55s %(levelname)-8s %(message)s'))
 
322
    logfile = logging.FileHandler(file_path, 'w', encoding='UTF-8')
 
323
    logfile.setFormatter(logging.Formatter('%(asctime)s %(threadName)s %(name)-55s %(levelname)-8s %(message)s'))
319
324
    log.addHandler(logfile)
320
325
    if log.isEnabledFor(logging.DEBUG):
321
326
        print('Logging to: {name}'.format(name=file_path))
328
333
    :param args: Some args
329
334
    """
330
335
    args = parse_options(args)
331
 
    qt_args = []
 
336
    qt_args = ['--disable-web-security']
 
337
    # qt_args = []
332
338
    if args and args.loglevel.lower() in ['d', 'debug']:
333
339
        log.setLevel(logging.DEBUG)
334
340
    elif args and args.loglevel.lower() in ['w', 'warning']:
362
368
        portable_settings_path = data_path / 'OpenLP.ini'
363
369
        # Make this our settings file
364
370
        log.info('INI file: {name}'.format(name=portable_settings_path))
365
 
        Settings.set_filename(str(portable_settings_path))
 
371
        Settings.set_filename(portable_settings_path)
366
372
        portable_settings = Settings()
367
373
        # Set our data path
368
374
        log.info('Data path: {name}'.format(name=data_path))
403
409
                None, translate('OpenLP', 'Settings Upgrade'),
404
410
                translate('OpenLP', 'Your settings are about to be upgraded. A backup will be created at '
405
411
                                    '{back_up_path}').format(back_up_path=back_up_path))
406
 
            settings.export(back_up_path)
 
412
            try:
 
413
                settings.export(back_up_path)
 
414
            except OSError:
 
415
                QtWidgets.QMessageBox.warning(
 
416
                    None, translate('OpenLP', 'Settings Upgrade'),
 
417
                    translate('OpenLP', 'Settings back up failed.\n\nContinuining to upgrade.'))
407
418
        settings.upgrade_settings()
408
419
    # First time checks in settings
409
420
    if not Settings().value('core/has run wizard'):