Merge pull request #4070 from Ultimaker/CURA-5384_confirm_upon_exit

CURA-5384 confirm upon exit
This commit is contained in:
alekseisasin 2018-07-13 11:54:14 +02:00 committed by GitHub
commit 31891e631c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 167 additions and 92 deletions

View file

@ -5,6 +5,7 @@ import copy
import os
import sys
import time
from typing import cast, TYPE_CHECKING, Optional
import numpy
@ -13,8 +14,6 @@ from PyQt5.QtGui import QColor, QIcon
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType
from typing import cast, TYPE_CHECKING
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Camera import Camera
from UM.Math.Vector import Vector
@ -97,6 +96,8 @@ from . import CuraSplashScreen
from . import CameraImageProvider
from . import MachineActionManager
from cura.TaskManagement.OnExitCallbackManager import OnExitCallbackManager
from cura.Settings.MachineManager import MachineManager
from cura.Settings.ExtruderManager import ExtruderManager
from cura.Settings.UserChangesModel import UserChangesModel
@ -158,6 +159,8 @@ class CuraApplication(QtApplication):
self._boot_loading_time = time.time()
self._on_exit_callback_manager = OnExitCallbackManager(self)
# Variables set from CLI
self._files_to_open = []
self._use_single_instance = False
@ -522,8 +525,8 @@ class CuraApplication(QtApplication):
def setNeedToShowUserAgreement(self, set_value = True):
self._need_to_show_user_agreement = set_value
## The "Quit" button click event handler.
@pyqtSlot()
# DO NOT call this function to close the application, use checkAndExitApplication() instead which will perform
# pre-exit checks such as checking for in-progress USB printing, etc.
def closeApplication(self):
Logger.log("i", "Close application")
main_window = self.getMainWindow()
@ -532,6 +535,32 @@ class CuraApplication(QtApplication):
else:
self.exit(0)
# This function first performs all upon-exit checks such as USB printing that is in progress.
# Use this to close the application.
@pyqtSlot()
def checkAndExitApplication(self) -> None:
self._on_exit_callback_manager.resetCurrentState()
self._on_exit_callback_manager.triggerNextCallback()
@pyqtSlot(result = bool)
def getIsAllChecksPassed(self) -> bool:
return self._on_exit_callback_manager.getIsAllChecksPassed()
def getOnExitCallbackManager(self) -> "OnExitCallbackManager":
return self._on_exit_callback_manager
def triggerNextExitCheck(self) -> None:
self._on_exit_callback_manager.triggerNextCallback()
showConfirmExitDialog = pyqtSignal(str, arguments = ["message"])
def setConfirmExitDialogCallback(self, callback):
self._confirm_exit_dialog_callback = callback
@pyqtSlot(bool)
def callConfirmExitDialogCallback(self, yes_or_no: bool):
self._confirm_exit_dialog_callback(yes_or_no)
## Signal to connect preferences action in QML
showPreferencesWindow = pyqtSignal()
@ -1703,22 +1732,3 @@ class CuraApplication(QtApplication):
@pyqtSlot()
def showMoreInformationDialogForAnonymousDataCollection(self):
cast(SliceInfo, self._plugin_registry.getPluginObject("SliceInfoPlugin")).showMoreInfoDialog()
## Signal to check whether the application can be closed or not
checkCuraCloseChange = pyqtSignal()
# This variable is necessary to ensure that all methods that were subscribed for the checkCuraCloseChange event
# have been passed checks
_isCuraCanBeClosed = True
def setCuraCanBeClosed(self, value: bool):
self._isCuraCanBeClosed = value
@pyqtSlot(result=bool)
def preCloseEventHandler(self)-> bool:
# If any of checks failed then then _isCuraCanBeClosed should be set to False and Cura will not be closed
# after clicking the quit button
self.checkCuraCloseChange.emit()
return self._isCuraCanBeClosed