35
35
36
36
from PyQt5 .QtCore import PYQT_VERSION_STR
37
37
from PyQt5 .QtCore import QT_VERSION_STR
38
- from PyQt5 .QtCore import Qt
38
+ from PyQt5 .QtCore import Qt , pyqtSlot
39
39
from PyQt5 .QtGui import QPalette , QColor , QFontDatabase , QFont
40
40
from PyQt5 .QtWidgets import QApplication , QStyleFactory , QMessageBox
41
41
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
+
42
50
try :
43
51
# QtWebEngineWidgets must be loaded prior to creating a QApplication
44
52
# But on systems with only WebKit, this will fail (and we ignore the failure)
@@ -76,17 +84,10 @@ def __init__(self, *args, mode=None):
76
84
log .info (time .asctime ().center (48 ))
77
85
log .info ('Starting new session' .center (48 ))
78
86
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
+ )
90
91
import openshot
91
92
92
93
# Re-route stdout and stderr to logger
@@ -255,6 +256,9 @@ def __init__(self, *args, mode=None):
255
256
self .updates .reset ()
256
257
self .window .updateStatusChanged (False , False )
257
258
259
+ # Connect our exit signals
260
+ self .aboutToQuit .connect (self .cleanup )
261
+
258
262
log .info ('Process command-line arguments: %s' % args )
259
263
if len (args [0 ]) == 2 :
260
264
path = args [0 ][1 ]
@@ -275,17 +279,17 @@ def _tr(self, message):
275
279
# Start event loop
276
280
def run (self ):
277
281
""" Start the primary Qt event loop for the interface """
282
+ return self .exec_ ()
278
283
279
- res = self .exec_ ()
280
-
284
+ @pyqtSlot ()
285
+ def cleanup (self ):
286
+ """aboutToQuit signal handler for application exit"""
281
287
try :
282
288
from classes .logger import log
283
289
self .settings .save ()
284
290
except Exception :
285
291
log .error ("Couldn't save user settings on exit." , exc_info = 1 )
286
292
287
- # return exit result
288
- return res
289
293
290
294
291
295
# Log the session's end
0 commit comments