4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection #
6
6
# --------------------------------------------------------------------------- #
7
# Copyright (c) 2008-2015 OpenLP Developers #
7
# Copyright (c) 2008-2016 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
from optparse import OptionParser
34
34
from traceback import format_exception
37
from PyQt4 import QtCore, QtGui
37
from PyQt5 import QtCore, QtGui, QtWidgets
39
39
from openlp.core.common import Registry, OpenLPMixin, AppLocation, Settings, UiStrings, check_directory_exists, \
40
40
is_macosx, is_win, translate
168
168
self.shared_memory = QtCore.QSharedMemory('OpenLP')
169
169
if self.shared_memory.attach():
170
status = QtGui.QMessageBox.critical(None, UiStrings().Error, UiStrings().OpenLPStart,
171
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
172
QtGui.QMessageBox.No))
173
if status == QtGui.QMessageBox.No:
170
status = QtWidgets.QMessageBox.critical(None, UiStrings().Error, UiStrings().OpenLPStart,
171
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes |
172
QtWidgets.QMessageBox.No))
173
if status == QtWidgets.QMessageBox.No:
207
207
Settings().setValue('core/application version', openlp_version)
208
208
# If data_version is different from the current version ask if we should backup the data folder
209
209
elif data_version != openlp_version:
210
if QtGui.QMessageBox.question(None, translate('OpenLP', 'Backup'),
211
translate('OpenLP', 'OpenLP has been upgraded, '
212
'do you want to create a backup of OpenLPs data folder?'),
213
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
214
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes:
210
if QtWidgets.QMessageBox.question(None, translate('OpenLP', 'Backup'),
211
translate('OpenLP', 'OpenLP has been upgraded, do you want to create '
212
'a backup of OpenLPs data folder?'),
213
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
214
QtWidgets.QMessageBox.Yes) == QtWidgets.QMessageBox.Yes:
215
215
# Create copy of data folder
216
216
data_folder_path = AppLocation.get_data_path()
217
217
timestamp = time.strftime("%Y%m%d-%H%M%S")
220
220
shutil.copytree(data_folder_path, data_folder_backup_path)
222
QtGui.QMessageBox.warning(None, translate('OpenLP', 'Backup'),
223
translate('OpenLP', 'Backup of the data folder failed!'))
222
QtWidgets.QMessageBox.warning(None, translate('OpenLP', 'Backup'),
223
translate('OpenLP', 'Backup of the data folder failed!'))
225
QtGui.QMessageBox.information(None, translate('OpenLP', 'Backup'),
226
translate('OpenLP', 'A backup of the data folder has been created at %s')
227
% data_folder_backup_path)
225
QtWidgets.QMessageBox.information(None, translate('OpenLP', 'Backup'),
227
'A backup of the data folder has been created at %s')
228
% data_folder_backup_path)
228
229
# Update the version in the settings
229
230
Settings().setValue('core/application version', openlp_version)
282
283
:return: a tuple of parsed options of type optparse.Value and a list of remaining argsZ
284
285
# Set up command line options.
285
usage = 'Usage: %prog [options] [qt-options]'
286
parser = OptionParser(usage=usage)
287
parser.add_option('-e', '--no-error-form', dest='no_error_form', action='store_true',
288
help='Disable the error notification form.')
289
parser.add_option('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
290
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
291
parser.add_option('-p', '--portable', dest='portable', action='store_true',
292
help='Specify if this should be run as a portable app, off a USB flash drive (not implemented).')
293
parser.add_option('-d', '--dev-version', dest='dev_version', action='store_true',
294
help='Ignore the version file and pull the version directly from Bazaar')
295
parser.add_option('-s', '--style', dest='style', help='Set the Qt4 style (passed directly to Qt4).')
286
parser = argparse.ArgumentParser(prog='openlp.py')
287
parser.add_argument('-e', '--no-error-form', dest='no_error_form', action='store_true',
288
help='Disable the error notification form.')
289
parser.add_argument('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
290
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
291
parser.add_argument('-p', '--portable', dest='portable', action='store_true',
292
help='Specify if this should be run as a portable app, '
293
'off a USB flash drive (not implemented).')
294
parser.add_argument('-d', '--dev-version', dest='dev_version', action='store_true',
295
help='Ignore the version file and pull the version directly from Bazaar')
296
parser.add_argument('-s', '--style', dest='style', help='Set the Qt5 style (passed directly to Qt5).')
297
parser.add_argument('rargs', nargs='?', default=[])
296
298
# Parse command line options and deal with them. Use args supplied pragmatically if possible.
297
299
return parser.parse_args(args) if args else parser.parse_args()
319
321
:param args: Some args
321
(options, args) = parse_options(args)
323
args = parse_options(args)
323
if options.loglevel.lower() in ['d', 'debug']:
325
if args and args.loglevel.lower() in ['d', 'debug']:
324
326
log.setLevel(logging.DEBUG)
325
elif options.loglevel.lower() in ['w', 'warning']:
327
elif args and args.loglevel.lower() in ['w', 'warning']:
326
328
log.setLevel(logging.WARNING)
328
330
log.setLevel(logging.INFO)
330
qt_args.extend(['-style', options.style])
331
if args and args.style:
332
qt_args.extend(['-style', args.style])
331
333
# Throw the rest of the arguments at Qt, just in case.
334
qt_args.extend(args.rargs)
333
335
# Bug #1018855: Set the WM_CLASS property in X11
334
336
if not is_win() and not is_macosx():
335
337
qt_args.append('OpenLP')
339
341
application = OpenLP(qt_args)
340
342
application.setOrganizationName('OpenLP')
341
343
application.setOrganizationDomain('openlp.org')
344
application.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
345
if args and args.portable:
343
346
application.setApplicationName('OpenLPPortable')
344
347
Settings.setDefaultFormat(Settings.IniFormat)
345
348
# Get location OpenLPPortable.ini