Skip to content

Commit 707dea5

Browse files
committed
app: Cleanup w/o relying on return from exec_()
1 parent 0237c70 commit 707dea5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/classes/app.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@
3535

3636
from PyQt5.QtCore import PYQT_VERSION_STR
3737
from PyQt5.QtCore import QT_VERSION_STR
38-
from PyQt5.QtCore import Qt
38+
from PyQt5.QtCore import Qt, pyqtSlot
3939
from PyQt5.QtGui import QPalette, QColor, QFontDatabase, QFont
4040
from PyQt5.QtWidgets import QApplication, QStyleFactory, QMessageBox
4141

42+
try:
43+
# This apparently has to be done before loading QtQuick
44+
# (via QtWebEgine) AND before creating the QApplication instance
45+
QApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
46+
from OpenGL import GL # noqa
47+
except (ImportError, AttributeError):
48+
pass
49+
4250
try:
4351
# QtWebEngineWidgets must be loaded prior to creating a QApplication
4452
# But on systems with only WebKit, this will fail (and we ignore the failure)
@@ -76,17 +84,10 @@ def __init__(self, *args, mode=None):
7684
log.info(time.asctime().center(48))
7785
log.info('Starting new session'.center(48))
7886

79-
if mode != "unittest" and (
80-
not info.WEB_BACKEND
81-
or info.WEB_BACKEND in ["auto", "webengine"]):
82-
try:
83-
from OpenGL import GL
84-
self.setAttribute(Qt.AA_ShareOpenGLContexts)
85-
except (ImportError, AttributeError):
86-
pass
87-
88-
from classes import settings, project_data, updates, language, ui_util, logger_libopenshot
89-
from . import openshot_rc # noqa
87+
from classes import (
88+
settings, project_data, updates, language, ui_util,
89+
logger_libopenshot
90+
)
9091
import openshot
9192

9293
# Re-route stdout and stderr to logger
@@ -255,6 +256,9 @@ def __init__(self, *args, mode=None):
255256
self.updates.reset()
256257
self.window.updateStatusChanged(False, False)
257258

259+
# Connect our exit signals
260+
self.aboutToQuit.connect(self.cleanup)
261+
258262
log.info('Process command-line arguments: %s' % args)
259263
if len(args[0]) == 2:
260264
path = args[0][1]
@@ -275,17 +279,17 @@ def _tr(self, message):
275279
# Start event loop
276280
def run(self):
277281
""" Start the primary Qt event loop for the interface """
282+
return self.exec_()
278283

279-
res = self.exec_()
280-
284+
@pyqtSlot()
285+
def cleanup(self):
286+
"""aboutToQuit signal handler for application exit"""
281287
try:
282288
from classes.logger import log
283289
self.settings.save()
284290
except Exception:
285291
log.error("Couldn't save user settings on exit.", exc_info=1)
286292

287-
# return exit result
288-
return res
289293

290294

291295
# Log the session's end

0 commit comments

Comments
 (0)