forked from openlp/openlp
Block 2 Instances of OpenLp running at the same time.
Fixes: https://launchpad.net/bugs/742122
This commit is contained in:
parent
be7eeb9e6a
commit
f19baafb9c
22
openlp.pyw
22
openlp.pyw
@ -34,6 +34,7 @@ from subprocess import Popen, PIPE
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import Receiver, check_directory_exists
|
from openlp.core.lib import Receiver, check_directory_exists
|
||||||
|
from openlp.core.lib.ui import UiStrings
|
||||||
from openlp.core.resources import qInitResources
|
from openlp.core.resources import qInitResources
|
||||||
from openlp.core.ui.mainwindow import MainWindow
|
from openlp.core.ui.mainwindow import MainWindow
|
||||||
from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm
|
from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm
|
||||||
@ -151,6 +152,13 @@ class OpenLP(QtGui.QApplication):
|
|||||||
log.info(u'Openlp version %s' % app_version[u'version'])
|
log.info(u'Openlp version %s' % app_version[u'version'])
|
||||||
return app_version
|
return app_version
|
||||||
|
|
||||||
|
def exec_(self):
|
||||||
|
"""
|
||||||
|
Override exec method to allow the shared memory to be released on exit
|
||||||
|
"""
|
||||||
|
QtGui.QApplication.exec_()
|
||||||
|
self.sharedMemory.detach()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
Run the OpenLP application.
|
Run the OpenLP application.
|
||||||
@ -201,6 +209,17 @@ class OpenLP(QtGui.QApplication):
|
|||||||
VersionThread(self.mainWindow, app_version).start()
|
VersionThread(self.mainWindow, app_version).start()
|
||||||
return self.exec_()
|
return self.exec_()
|
||||||
|
|
||||||
|
def isAlreadyRunning(self):
|
||||||
|
self.sharedMemory = QtCore.QSharedMemory('OpenLP')
|
||||||
|
if self.sharedMemory.attach():
|
||||||
|
QtGui.QMessageBox.critical(None,
|
||||||
|
UiStrings.Error, UiStrings.OpenLPStart,
|
||||||
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.sharedMemory.create(1)
|
||||||
|
return False
|
||||||
|
|
||||||
def hookException(self, exctype, value, traceback):
|
def hookException(self, exctype, value, traceback):
|
||||||
if not hasattr(self, u'mainWindow'):
|
if not hasattr(self, u'mainWindow'):
|
||||||
log.exception(''.join(format_exception(exctype, value, traceback)))
|
log.exception(''.join(format_exception(exctype, value, traceback)))
|
||||||
@ -275,6 +294,9 @@ def main():
|
|||||||
app = OpenLP(qt_args)
|
app = OpenLP(qt_args)
|
||||||
# Define the settings environment
|
# Define the settings environment
|
||||||
settings = QtCore.QSettings(u'OpenLP', u'OpenLP')
|
settings = QtCore.QSettings(u'OpenLP', u'OpenLP')
|
||||||
|
# Instance check
|
||||||
|
if app.isAlreadyRunning():
|
||||||
|
sys.exit()
|
||||||
# First time checks in settings
|
# First time checks in settings
|
||||||
# Use explicit reference as not inside a QT environment yet
|
# Use explicit reference as not inside a QT environment yet
|
||||||
if not settings.value(u'general/has run wizard',
|
if not settings.value(u'general/has run wizard',
|
||||||
|
@ -75,6 +75,7 @@ class UiStrings(object):
|
|||||||
NISp = translate('OpenLP.Ui', 'No Items Selected', 'Plural')
|
NISp = translate('OpenLP.Ui', 'No Items Selected', 'Plural')
|
||||||
OLPV1 = translate('OpenLP.Ui', 'openlp.org 1.x')
|
OLPV1 = translate('OpenLP.Ui', 'openlp.org 1.x')
|
||||||
OLPV2 = translate('OpenLP.Ui', 'OpenLP 2.0')
|
OLPV2 = translate('OpenLP.Ui', 'OpenLP 2.0')
|
||||||
|
OpenLPStart = translate('OpenLP.Ui', 'OpenLP is already running')
|
||||||
OpenService = translate('OpenLP.Ui', 'Open Service')
|
OpenService = translate('OpenLP.Ui', 'Open Service')
|
||||||
Preview = translate('OpenLP.Ui', 'Preview')
|
Preview = translate('OpenLP.Ui', 'Preview')
|
||||||
PreviewPanel = translate('OpenLP.Ui', 'Preview Panel')
|
PreviewPanel = translate('OpenLP.Ui', 'Preview Panel')
|
||||||
|
Loading…
Reference in New Issue
Block a user