Merge pull request #13082 from digitalfrost/200822

OnExitCallbackManager.py: improve documentation
This commit is contained in:
Jelle Spijker 2022-08-23 10:27:21 +02:00 committed by GitHub
commit 63dc79dca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,10 +10,13 @@ if TYPE_CHECKING:
# #
# This class manages a all registered upon-exit checks that need to be perform when the application tries to exit. # This class manages all registered upon-exit checks
# For example, to show a confirmation dialog when there is USB printing in progress, etc. All callbacks will be called # that need to be performed when the application tries to exit.
# in the order of when they got registered. If all callbacks "passes", that is, for example, if the user clicks "yes" # For example, show a confirmation dialog when there is USB printing in progress.
# on the exit confirmation dialog or nothing that's blocking the exit, then the application will quit after that. # All callbacks will be called in the order of when they were registered.
# If all callbacks "pass", for example:
# if the user clicks "yes" on the exit confirmation dialog
# and nothing else is blocking the exit, then the application will quit.
# #
class OnExitCallbackManager: class OnExitCallbackManager:
@ -35,10 +38,12 @@ class OnExitCallbackManager:
def getIsAllChecksPassed(self) -> bool: def getIsAllChecksPassed(self) -> bool:
return self._is_all_checks_passed return self._is_all_checks_passed
# Trigger the next callback if available. If not, it means that all callbacks have "passed", which means we should # Trigger the next callback if there is one.
# not block the application to quit, and it will call the application to actually quit. # If not, all callbacks have "passed",
# which means we should not prevent the application from quitting,
# and we call the application to actually quit.
def triggerNextCallback(self) -> None: def triggerNextCallback(self) -> None:
# Get the next callback and schedule that if # Get the next callback and schedule it
this_callback = None this_callback = None
if self._current_callback_idx < len(self._on_exit_callback_list): if self._current_callback_idx < len(self._on_exit_callback_list):
this_callback = self._on_exit_callback_list[self._current_callback_idx] this_callback = self._on_exit_callback_list[self._current_callback_idx]
@ -55,10 +60,11 @@ class OnExitCallbackManager:
# Tell the application to exit # Tell the application to exit
self._application.callLater(self._application.closeApplication) self._application.callLater(self._application.closeApplication)
# This is the callback function which an on-exit callback should call when it finishes, it should provide the # Callback function which an on-exit callback calls when it finishes.
# "should_proceed" flag indicating whether this check has "passed", or in other words, whether quitting the # It provides a "should_proceed" flag indicating whether the check has "passed",
# application should be blocked. If the last on-exit callback doesn't block the quitting, it will call the next # or whether quitting the application should be blocked.
# registered on-exit callback if available. # If the last on-exit callback doesn't block quitting, it will call the next
# registered on-exit callback if one is available.
def onCurrentCallbackFinished(self, should_proceed: bool = True) -> None: def onCurrentCallbackFinished(self, should_proceed: bool = True) -> None:
if not should_proceed: if not should_proceed:
Logger.log("d", "on-app-exit callback finished and we should not proceed.") Logger.log("d", "on-app-exit callback finished and we should not proceed.")