Merge pull request #11818 from Ultimaker/CURA-9155_cant_stop_wont_stop

[CURA-9155] Fix Cura not closing properly on Windows.
This commit is contained in:
Jaime van Kessel 2022-04-19 15:07:00 +02:00 committed by GitHub
commit 3bfd2679ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,7 @@ import time
from typing import cast, TYPE_CHECKING, Optional, Callable, List, Any, Dict
import numpy
from PyQt6.QtCore import QObject, QTimer, QUrl, pyqtSignal, pyqtProperty, QEvent, pyqtEnum
from PyQt6.QtCore import QObject, QTimer, QUrl, pyqtSignal, pyqtProperty, QEvent, pyqtEnum, QCoreApplication
from PyQt6.QtGui import QColor, QIcon
from PyQt6.QtQml import qmlRegisterUncreatableType, qmlRegisterUncreatableMetaObject, qmlRegisterSingletonType, qmlRegisterType
from PyQt6.QtWidgets import QMessageBox
@ -122,7 +122,6 @@ if TYPE_CHECKING:
numpy.seterr(all = "ignore")
class CuraApplication(QtApplication):
# SettingVersion represents the set of settings available in the machine/extruder definitions.
# You need to make sure that this version number needs to be increased if there is any non-backwards-compatible
@ -623,11 +622,14 @@ class CuraApplication(QtApplication):
# the QML code then gets `null` as the global stack and can deal with that as it deems fit.
self.getMachineManager().setActiveMachine(None)
QtApplication.getInstance().closeAllWindows()
main_window = self.getMainWindow()
if main_window is not None:
main_window.close()
else:
self.exit(0)
QtApplication.closeAllWindows()
QCoreApplication.quit()
# This function first performs all upon-exit checks such as USB printing that is in progress.
# Use this to close the application.
@ -1098,6 +1100,12 @@ class CuraApplication(QtApplication):
else:
self._open_file_queue.append(event.file())
if int(event.type()) == 20: # 'QEvent.Type.Quit' enum isn't there, even though it should be according to docs.
# Once we're at this point, everything should have been flushed already (past OnExitCallbackManager).
# It's more difficult to call sys.exit(0): That requires that it happens as the result of a pyqtSignal-emit.
# (See https://doc.qt.io/qt-6/qcoreapplication.html#quit)
os._exit(0)
return super().event(event)
def getAutoSave(self) -> Optional[AutoSave]: