From 1ccdf8b407d83fd5c42ba85e832b56eade43716d Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 13:06:34 +1100 Subject: [PATCH 01/25] push crash dump as appveyor artifact --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 4c424a12efe..be78cfd34ba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -146,6 +146,8 @@ before_test: Add-AppveyorMessage "Unable to install NVDA prior to tests." } Push-AppveyorArtifact $installerLogFilePath + $crashDump = "$outputDir\nvda_crash.dmp" + Push-AppveyorArtifact $crashDump if($errorCode -ne 0) { $host.SetShouldExit($errorCode) } test_script: From c6054798124d67ef3eb3f554d44e82b6df61e73c Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 13:14:38 +1100 Subject: [PATCH 02/25] create safeAppExit --- source/core.py | 4 ++-- source/gui/__init__.py | 7 +++---- source/gui/guiHelper.py | 26 +++++++++++++++++++------- source/gui/installerGui.py | 4 ++-- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/source/core.py b/source/core.py index 0e77a9c6f4e..8cc8b009295 100644 --- a/source/core.py +++ b/source/core.py @@ -109,9 +109,9 @@ def onResult(ID): def restart(disableAddons=False, debugLogging=False): """Restarts NVDA by starting a new copy.""" if globalVars.appArgs.launcher: - import wx + from gui import guiHelper globalVars.exitCode=3 - wx.GetApp().ExitMainLoop() + guiHelper.safeAppExit() return import subprocess import winUser diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 368e537acd5..aa8c9967ecf 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -40,7 +40,6 @@ import speechViewer import winUser import api -from . import guiHelper import winVersion try: @@ -247,7 +246,7 @@ def onExitCommand(self, evt): d.Show() self.postPopup() else: - wx.GetApp().ExitMainLoop() + guiHelper.safeAppExit() def onNVDASettingsCommand(self,evt): self._popupSettingsDialog(NVDASettingsDialog) @@ -863,7 +862,7 @@ def onContinueRunning(self, evt): core.doStartupDialogs() def onExit(self, evt): - wx.GetApp().ExitMainLoop() + guiHelper.safeAppExit() @classmethod def run(cls): @@ -940,7 +939,7 @@ def onOk(self, evt): if action >= 2 and config.isAppX: action += 1 if action == 0: - wx.GetApp().ExitMainLoop() + guiHelper.safeAppExit() elif action == 1: queueHandler.queueFunction(queueHandler.eventQueue,core.restart) elif action == 2: diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index b33edad2875..40ea043a4d6 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -1,9 +1,7 @@ -# -*- coding: UTF-8 -*- -#guiHelper.py -#A part of NonVisual Desktop Access (NVDA) -#Copyright (C) 2016 NV Access Limited -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. +# A part of NonVisual Desktop Access (NVDA) +# Copyright (C) 2016-2021 NV Access Limited +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. """ Utilities to simplify the creation of wx GUIs, including automatic management of spacing. @@ -47,6 +45,7 @@ def __init__(self,parent): import wx from wx.lib import scrolledpanel, newevent from abc import ABCMeta +from logHandler import log #: border space to be used around all controls in dialogs BORDER_FOR_DIALOGS=10 @@ -363,7 +362,20 @@ def addDialogDismissButtons(self, buttons, separated=False): self.dialogDismissButtonsAdded = True return buttons + +def safeAppExit(): + def ensureMainLoopExited(): + if wx.GetApp().GetMainLoop(): + wx.GetApp().ExitMainLoop() + + if not wx.GetApp().GetMainLoop(): + log.warning("app trying to exit after already exited") + return + if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + wx.CallAfter(ensureMainLoopExited) + + class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): """Meta class to be used for wx subclasses with abstract methods.""" pass - diff --git a/source/gui/installerGui.py b/source/gui/installerGui.py index 8c7fd3e6377..91c7482192a 100644 --- a/source/gui/installerGui.py +++ b/source/gui/installerGui.py @@ -102,7 +102,7 @@ def doInstall( winUser.SW_SHOWNORMAL ) else: - wx.GetApp().ExitMainLoop() + guiHelper.safeAppExit() def doSilentInstall( @@ -447,7 +447,7 @@ def doCreatePortable(portableDirectory,copyUserConfig=False,silent=False,startAf return d.done() if silent: - wx.GetApp().ExitMainLoop() + guiHelper.safeAppExit() else: # Translators: The message displayed when a portable copy of NVDA has been successfully created. # %s will be replaced with the destination directory. From d57d486941e63f04e9dd209ca3615325adb5dca0 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 13:14:52 +1100 Subject: [PATCH 03/25] remove unnecessary Destroy call --- source/gui/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/source/gui/__init__.py b/source/gui/__init__.py index aa8c9967ecf..1723ee0f418 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -788,7 +788,6 @@ def run(cls): mainFrame.prePopup() d = cls(mainFrame) d.ShowModal() - d.Destroy() mainFrame.postPopup() From bf9447ef43f6063c52c72d468f1cf7b2e1aafd82 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 13:22:00 +1100 Subject: [PATCH 04/25] check if crashDump exists before pushing --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index be78cfd34ba..f422ebce674 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -147,7 +147,9 @@ before_test: } Push-AppveyorArtifact $installerLogFilePath $crashDump = "$outputDir\nvda_crash.dmp" - Push-AppveyorArtifact $crashDump + if (Test-Path -Path $crashDump){ + Push-AppveyorArtifact $crashDump + } if($errorCode -ne 0) { $host.SetShouldExit($errorCode) } test_script: From 49eb9e71c41b36946df8f84567c907d60db5aca9 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 13:38:23 +1100 Subject: [PATCH 05/25] revert d57d486941e63f04e9dd209ca3615325adb5dca0 --- source/gui/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 1723ee0f418..aa8c9967ecf 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -788,6 +788,7 @@ def run(cls): mainFrame.prePopup() d = cls(mainFrame) d.ShowModal() + d.Destroy() mainFrame.postPopup() From 684b9dec697c48d3055e8c32049655f983eb41a8 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 14:29:51 +1100 Subject: [PATCH 06/25] improve handling of welcomedialog closing --- source/gui/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/gui/__init__.py b/source/gui/__init__.py index aa8c9967ecf..cdbdb237823 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -788,7 +788,8 @@ def run(cls): mainFrame.prePopup() d = cls(mainFrame) d.ShowModal() - d.Destroy() + if d and not d.IsBeingDeleted(): + wx.CallAfter(d.Destroy) mainFrame.postPopup() From 80e41ed16cd72fd48e47445089e746491ad61203 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 14:35:28 +1100 Subject: [PATCH 07/25] revert to previous behaviour to trigger appveyor crash dump --- source/gui/guiHelper.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 40ea043a4d6..5da10dff541 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -364,16 +364,17 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - def ensureMainLoopExited(): - if wx.GetApp().GetMainLoop(): - wx.GetApp().ExitMainLoop() - - if not wx.GetApp().GetMainLoop(): - log.warning("app trying to exit after already exited") - return - if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - wx.CallAfter(ensureMainLoopExited) + wx.GetApp().ExitMainLoop() + # def ensureMainLoopExited(): + # if wx.GetApp().GetMainLoop(): + # wx.GetApp().ExitMainLoop() + + # if not wx.GetApp().GetMainLoop(): + # log.warning("app trying to exit after already exited") + # return + # if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + # return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + # wx.CallAfter(ensureMainLoopExited) class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): From 0e628c47384e1046c67f07b0e0b74bb5b5db1bd3 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 14:52:41 +1100 Subject: [PATCH 08/25] Revert "revert to previous behaviour to trigger appveyor crash dump" This reverts commit 80e41ed16cd72fd48e47445089e746491ad61203. --- source/gui/guiHelper.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 5da10dff541..40ea043a4d6 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -364,17 +364,16 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - wx.GetApp().ExitMainLoop() - # def ensureMainLoopExited(): - # if wx.GetApp().GetMainLoop(): - # wx.GetApp().ExitMainLoop() - - # if not wx.GetApp().GetMainLoop(): - # log.warning("app trying to exit after already exited") - # return - # if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - # return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - # wx.CallAfter(ensureMainLoopExited) + def ensureMainLoopExited(): + if wx.GetApp().GetMainLoop(): + wx.GetApp().ExitMainLoop() + + if not wx.GetApp().GetMainLoop(): + log.warning("app trying to exit after already exited") + return + if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + wx.CallAfter(ensureMainLoopExited) class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): From cbf39f6fcc3d02541dfff8095a55a538a8dbe4f7 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 15:44:16 +1100 Subject: [PATCH 09/25] add appveyor fail when crash dump on install process --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index f422ebce674..fca12f03a1e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -149,6 +149,8 @@ before_test: $crashDump = "$outputDir\nvda_crash.dmp" if (Test-Path -Path $crashDump){ Push-AppveyorArtifact $crashDump + Add-AppveyorMessage "Install process crashed" + $errorCode=1 } if($errorCode -ne 0) { $host.SetShouldExit($errorCode) } From a469c4dd9387c09f98cfbeca77e873236759ecb7 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 14:35:28 +1100 Subject: [PATCH 10/25] revert to previous behaviour to trigger appveyor crash dump --- source/gui/guiHelper.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 40ea043a4d6..d7194892ed0 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -45,7 +45,7 @@ def __init__(self,parent): import wx from wx.lib import scrolledpanel, newevent from abc import ABCMeta -from logHandler import log +# from logHandler import log #: border space to be used around all controls in dialogs BORDER_FOR_DIALOGS=10 @@ -364,16 +364,17 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - def ensureMainLoopExited(): - if wx.GetApp().GetMainLoop(): - wx.GetApp().ExitMainLoop() - - if not wx.GetApp().GetMainLoop(): - log.warning("app trying to exit after already exited") - return - if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - wx.CallAfter(ensureMainLoopExited) + wx.GetApp().ExitMainLoop() + # def ensureMainLoopExited(): + # if wx.GetApp().GetMainLoop(): + # wx.GetApp().ExitMainLoop() + + # if not wx.GetApp().GetMainLoop(): + # log.warning("app trying to exit after already exited") + # return + # if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + # return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + # wx.CallAfter(ensureMainLoopExited) class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): From 79aea6730ab7813394f70ad8dac7d7f1e0673d5f Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 18 Mar 2021 15:53:51 +1100 Subject: [PATCH 11/25] Revert "revert to previous behaviour to trigger appveyor crash dump" This reverts commit a469c4dd9387c09f98cfbeca77e873236759ecb7. --- source/gui/guiHelper.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index d7194892ed0..40ea043a4d6 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -45,7 +45,7 @@ def __init__(self,parent): import wx from wx.lib import scrolledpanel, newevent from abc import ABCMeta -# from logHandler import log +from logHandler import log #: border space to be used around all controls in dialogs BORDER_FOR_DIALOGS=10 @@ -364,17 +364,16 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - wx.GetApp().ExitMainLoop() - # def ensureMainLoopExited(): - # if wx.GetApp().GetMainLoop(): - # wx.GetApp().ExitMainLoop() - - # if not wx.GetApp().GetMainLoop(): - # log.warning("app trying to exit after already exited") - # return - # if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - # return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - # wx.CallAfter(ensureMainLoopExited) + def ensureMainLoopExited(): + if wx.GetApp().GetMainLoop(): + wx.GetApp().ExitMainLoop() + + if not wx.GetApp().GetMainLoop(): + log.warning("app trying to exit after already exited") + return + if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + wx.CallAfter(ensureMainLoopExited) class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): From eb89a3357d18520f86137825db83db162f04da7c Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 22 Mar 2021 13:14:19 +1100 Subject: [PATCH 12/25] add better comments --- source/gui/guiHelper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 40ea043a4d6..6d4f98be46d 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -372,7 +372,11 @@ def ensureMainLoopExited(): log.warning("app trying to exit after already exited") return if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + # it is important for that to trigger the wx exit process by destroying the top window + # ensure that this is executed on NVDA's main (GUI) thread return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + # if this is triggered by the top window being destroyed, exit the main loop + # ensure that this is executed on NVDA's main (GUI) thread wx.CallAfter(ensureMainLoopExited) From a5dc8d31cb523766d2093dc73d161402e3c97e0a Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 22 Mar 2021 15:24:37 +1100 Subject: [PATCH 13/25] rename installer crash file --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index fca12f03a1e..a0b017e7347 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -148,7 +148,8 @@ before_test: Push-AppveyorArtifact $installerLogFilePath $crashDump = "$outputDir\nvda_crash.dmp" if (Test-Path -Path $crashDump){ - Push-AppveyorArtifact $crashDump + Rename-Item -Path $crashDump -NewName "nvda_install_crash.dmp" + Push-AppveyorArtifact "$outputDir\nvda_install_crash.dmp" Add-AppveyorMessage "Install process crashed" $errorCode=1 } From da7d3073a2d68eb71866a8ba3406bc07565e7c03 Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 22 Mar 2021 15:35:55 +1100 Subject: [PATCH 14/25] improve commenting --- source/gui/guiHelper.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 6d4f98be46d..d7766a02cd0 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -364,18 +364,23 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - def ensureMainLoopExited(): - if wx.GetApp().GetMainLoop(): - wx.GetApp().ExitMainLoop() + """ + Ensures the app is exited by the top window being destroyed + and that the main loop finally exits as part of that process + """ if not wx.GetApp().GetMainLoop(): log.warning("app trying to exit after already exited") return if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - # it is important for that to trigger the wx exit process by destroying the top window + # it is important for the wxApp exit process to be triggered by destroying the top window # ensure that this is executed on NVDA's main (GUI) thread return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - # if this is triggered by the top window being destroyed, exit the main loop + + def ensureMainLoopExited(): + if wx.GetApp().GetMainLoop(): + wx.GetApp().ExitMainLoop() + # ensure that this is executed on NVDA's main (GUI) thread wx.CallAfter(ensureMainLoopExited) From 6d7da7fb5d6128a382494e6563f7a1b33fe4adf9 Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 22 Mar 2021 15:39:51 +1100 Subject: [PATCH 15/25] trigger appveyor crash --- source/gui/guiHelper.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index d7766a02cd0..3588a817fd8 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -364,25 +364,7 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - """ - Ensures the app is exited by the top window being destroyed - and that the main loop finally exits as part of that process - """ - - if not wx.GetApp().GetMainLoop(): - log.warning("app trying to exit after already exited") - return - if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - # it is important for the wxApp exit process to be triggered by destroying the top window - # ensure that this is executed on NVDA's main (GUI) thread - return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - - def ensureMainLoopExited(): - if wx.GetApp().GetMainLoop(): - wx.GetApp().ExitMainLoop() - - # ensure that this is executed on NVDA's main (GUI) thread - wx.CallAfter(ensureMainLoopExited) + wx.GetApp().ExitMainLoop() class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): From 1abbbd944feae050276194ff5e8147a9aaf1a800 Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 22 Mar 2021 15:40:38 +1100 Subject: [PATCH 16/25] Revert "trigger appveyor crash" This reverts commit 6d7da7fb5d6128a382494e6563f7a1b33fe4adf9. --- source/gui/guiHelper.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 3588a817fd8..d7766a02cd0 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -364,7 +364,25 @@ def addDialogDismissButtons(self, buttons, separated=False): def safeAppExit(): - wx.GetApp().ExitMainLoop() + """ + Ensures the app is exited by the top window being destroyed + and that the main loop finally exits as part of that process + """ + + if not wx.GetApp().GetMainLoop(): + log.warning("app trying to exit after already exited") + return + if not wx.GetApp().GetTopWindow().IsBeingDeleted(): + # it is important for the wxApp exit process to be triggered by destroying the top window + # ensure that this is executed on NVDA's main (GUI) thread + return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) + + def ensureMainLoopExited(): + if wx.GetApp().GetMainLoop(): + wx.GetApp().ExitMainLoop() + + # ensure that this is executed on NVDA's main (GUI) thread + wx.CallAfter(ensureMainLoopExited) class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): From 552711fcf38876133e1d806cf75d3438255f0f4f Mon Sep 17 00:00:00 2001 From: buddsean Date: Mon, 22 Mar 2021 16:29:48 +1100 Subject: [PATCH 17/25] simplify appveyor push --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a0b017e7347..102f207ee03 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -148,8 +148,7 @@ before_test: Push-AppveyorArtifact $installerLogFilePath $crashDump = "$outputDir\nvda_crash.dmp" if (Test-Path -Path $crashDump){ - Rename-Item -Path $crashDump -NewName "nvda_install_crash.dmp" - Push-AppveyorArtifact "$outputDir\nvda_install_crash.dmp" + Push-AppveyorArtifact $crashDump -FileName "nvda_install_crash.dmp" Add-AppveyorMessage "Install process crashed" $errorCode=1 } From 8f577c2deb76cd7771bc17bcb5d71a7acb0464d3 Mon Sep 17 00:00:00 2001 From: buddsean Date: Tue, 23 Mar 2021 12:16:31 +1100 Subject: [PATCH 18/25] move mainFrame exiting service to mainFrame, better logging --- source/core.py | 4 ++-- source/gui/__init__.py | 29 ++++++++++++++++++++++++++--- source/gui/guiHelper.py | 21 --------------------- source/gui/installerGui.py | 4 ++-- source/gui/startupDialogs.py | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/source/core.py b/source/core.py index 805835b24be..806ff335229 100644 --- a/source/core.py +++ b/source/core.py @@ -111,9 +111,9 @@ def onResult(ID): def restart(disableAddons=False, debugLogging=False): """Restarts NVDA by starting a new copy.""" if globalVars.appArgs.launcher: - from gui import guiHelper + import gui globalVars.exitCode=3 - guiHelper.safeAppExit() + gui.mainFrame.safeAppExit() return import subprocess import winUser diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 4fb5a25a2ee..5afe5239e56 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -77,7 +77,7 @@ def __init__(self): def Destroy(self): self.sysTrayIcon.Destroy() - super(MainFrame, self).Destroy() + super().Destroy() def prePopup(self): """Prepare for a popup. @@ -199,7 +199,7 @@ def onExitCommand(self, evt): d.Show() self.postPopup() else: - guiHelper.safeAppExit() + self.safeAppExit() def onNVDASettingsCommand(self,evt): self._popupSettingsDialog(NVDASettingsDialog) @@ -359,6 +359,29 @@ def onConfigProfilesCommand(self, evt): ProfilesDialog(gui.mainFrame).Show() self.postPopup() + def safeAppExit(self): + """ + Ensures the app is exited by the top window being destroyed + and that the main loop finally exits as part of that process + """ + + if not wx.GetApp().GetMainLoop(): + log.warning("app trying to exit after already exited") + return + if not self.IsBeingDeleted(): + log.warning("correct exit behaviour") + # it is important for the wxApp exit process to be triggered by destroying the top window + # ensure that this is executed on NVDA's main (GUI) thread + return wx.CallAfter(self.Destroy) + + def ensureMainLoopExited(): + if wx.GetApp().GetMainLoop(): + wx.GetApp().ExitMainLoop() + + log.warning("app trying to exit after already exited") + # ensure that this is executed on NVDA's main (GUI) thread + wx.CallAfter(ensureMainLoopExited) + class SysTrayIcon(wx.adv.TaskBarIcon): def __init__(self, frame): @@ -712,7 +735,7 @@ def onOk(self, evt): if action >= 2 and config.isAppX: action += 1 if action == 0: - guiHelper.safeAppExit() + mainFrame.safeAppExit() elif action == 1: queueHandler.queueFunction(queueHandler.eventQueue,core.restart) elif action == 2: diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index a8a42133b07..1d56e39799c 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -45,7 +45,6 @@ def __init__(self,parent): import wx from wx.lib import scrolledpanel, newevent from abc import ABCMeta -from logHandler import log #: border space to be used around all controls in dialogs BORDER_FOR_DIALOGS=10 @@ -369,26 +368,6 @@ def addDialogDismissButtons(self, buttons, separated=False): return buttons -def safeAppExit(): - """ - Ensures the app is exited by the top window being destroyed - and that the main loop finally exits as part of that process - """ - - if not wx.GetApp().GetMainLoop(): - log.warning("app trying to exit after already exited") - return - if not wx.GetApp().GetTopWindow().IsBeingDeleted(): - # it is important for the wxApp exit process to be triggered by destroying the top window - # ensure that this is executed on NVDA's main (GUI) thread - return wx.CallAfter(wx.GetApp().GetTopWindow().Destroy) - - def ensureMainLoopExited(): - if wx.GetApp().GetMainLoop(): - wx.GetApp().ExitMainLoop() - - # ensure that this is executed on NVDA's main (GUI) thread - wx.CallAfter(ensureMainLoopExited) class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): diff --git a/source/gui/installerGui.py b/source/gui/installerGui.py index 2f246b10696..fdad7eaa2f7 100644 --- a/source/gui/installerGui.py +++ b/source/gui/installerGui.py @@ -102,7 +102,7 @@ def doInstall( winUser.SW_SHOWNORMAL ) else: - guiHelper.safeAppExit() + gui.mainFrame.safeAppExit() def doSilentInstall( @@ -450,7 +450,7 @@ def doCreatePortable(portableDirectory,copyUserConfig=False,silent=False,startAf return d.done() if silent: - guiHelper.safeAppExit() + gui.mainFrame.safeAppExit() else: # Translators: The message displayed when a portable copy of NVDA has been successfully created. # %s will be replaced with the destination directory. diff --git a/source/gui/startupDialogs.py b/source/gui/startupDialogs.py index 8be7b5a2b98..c75d4f865b5 100644 --- a/source/gui/startupDialogs.py +++ b/source/gui/startupDialogs.py @@ -194,7 +194,7 @@ def onContinueRunning(self, evt): core.doStartupDialogs() def onExit(self, evt): - gui.guiHelper.safeAppExit() + gui.mainFrame.safeAppExit() @classmethod def run(cls): From d7aea3b4fdff64e8506754e438a96872315bf24e Mon Sep 17 00:00:00 2001 From: buddsean Date: Tue, 23 Mar 2021 12:43:04 +1100 Subject: [PATCH 19/25] destroy the mainFrame to exit the App --- source/core.py | 2 +- source/gui/__init__.py | 26 ++------------------------ source/gui/installerGui.py | 4 ++-- source/gui/startupDialogs.py | 2 +- 4 files changed, 6 insertions(+), 28 deletions(-) diff --git a/source/core.py b/source/core.py index 806ff335229..3f99ee8da7f 100644 --- a/source/core.py +++ b/source/core.py @@ -113,7 +113,7 @@ def restart(disableAddons=False, debugLogging=False): if globalVars.appArgs.launcher: import gui globalVars.exitCode=3 - gui.mainFrame.safeAppExit() + wx.CallAfter(gui.mainFrame.Destroy) return import subprocess import winUser diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 5afe5239e56..ed55344af6f 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -199,7 +199,7 @@ def onExitCommand(self, evt): d.Show() self.postPopup() else: - self.safeAppExit() + wx.CallAfter(self.Destroy) def onNVDASettingsCommand(self,evt): self._popupSettingsDialog(NVDASettingsDialog) @@ -359,28 +359,6 @@ def onConfigProfilesCommand(self, evt): ProfilesDialog(gui.mainFrame).Show() self.postPopup() - def safeAppExit(self): - """ - Ensures the app is exited by the top window being destroyed - and that the main loop finally exits as part of that process - """ - - if not wx.GetApp().GetMainLoop(): - log.warning("app trying to exit after already exited") - return - if not self.IsBeingDeleted(): - log.warning("correct exit behaviour") - # it is important for the wxApp exit process to be triggered by destroying the top window - # ensure that this is executed on NVDA's main (GUI) thread - return wx.CallAfter(self.Destroy) - - def ensureMainLoopExited(): - if wx.GetApp().GetMainLoop(): - wx.GetApp().ExitMainLoop() - - log.warning("app trying to exit after already exited") - # ensure that this is executed on NVDA's main (GUI) thread - wx.CallAfter(ensureMainLoopExited) class SysTrayIcon(wx.adv.TaskBarIcon): @@ -735,7 +713,7 @@ def onOk(self, evt): if action >= 2 and config.isAppX: action += 1 if action == 0: - mainFrame.safeAppExit() + wx.CallAfter(mainFrame.Destroy) elif action == 1: queueHandler.queueFunction(queueHandler.eventQueue,core.restart) elif action == 2: diff --git a/source/gui/installerGui.py b/source/gui/installerGui.py index fdad7eaa2f7..2443cf26400 100644 --- a/source/gui/installerGui.py +++ b/source/gui/installerGui.py @@ -102,7 +102,7 @@ def doInstall( winUser.SW_SHOWNORMAL ) else: - gui.mainFrame.safeAppExit() + wx.CallAfter(gui.mainFrame.Destroy) def doSilentInstall( @@ -450,7 +450,7 @@ def doCreatePortable(portableDirectory,copyUserConfig=False,silent=False,startAf return d.done() if silent: - gui.mainFrame.safeAppExit() + wx.CallAfter(gui.mainFrame.Destroy) else: # Translators: The message displayed when a portable copy of NVDA has been successfully created. # %s will be replaced with the destination directory. diff --git a/source/gui/startupDialogs.py b/source/gui/startupDialogs.py index c75d4f865b5..6c272322b19 100644 --- a/source/gui/startupDialogs.py +++ b/source/gui/startupDialogs.py @@ -194,7 +194,7 @@ def onContinueRunning(self, evt): core.doStartupDialogs() def onExit(self, evt): - gui.mainFrame.safeAppExit() + wx.CallAfter(gui.mainFrame.Destroy) @classmethod def run(cls): From 439d7c0415a8d897db67b972d94a9213ee00b437 Mon Sep 17 00:00:00 2001 From: buddsean Date: Tue, 23 Mar 2021 12:58:42 +1100 Subject: [PATCH 20/25] fix lint --- source/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/core.py b/source/core.py index 3f99ee8da7f..74d10383267 100644 --- a/source/core.py +++ b/source/core.py @@ -112,6 +112,7 @@ def restart(disableAddons=False, debugLogging=False): """Restarts NVDA by starting a new copy.""" if globalVars.appArgs.launcher: import gui + import wx globalVars.exitCode=3 wx.CallAfter(gui.mainFrame.Destroy) return From 1fc098157c9f976a2b519b580d3d00fcdc54c228 Mon Sep 17 00:00:00 2001 From: buddsean Date: Wed, 24 Mar 2021 12:48:36 +1100 Subject: [PATCH 21/25] minimize diff --- source/gui/__init__.py | 1 - source/gui/guiHelper.py | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/source/gui/__init__.py b/source/gui/__init__.py index ed55344af6f..5a2a5d50b1f 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -359,7 +359,6 @@ def onConfigProfilesCommand(self, evt): ProfilesDialog(gui.mainFrame).Show() self.postPopup() - class SysTrayIcon(wx.adv.TaskBarIcon): def __init__(self, frame): diff --git a/source/gui/guiHelper.py b/source/gui/guiHelper.py index 1d56e39799c..7531d682300 100644 --- a/source/gui/guiHelper.py +++ b/source/gui/guiHelper.py @@ -1,7 +1,9 @@ -# A part of NonVisual Desktop Access (NVDA) -# Copyright (C) 2016-2021 NV Access Limited -# This file is covered by the GNU General Public License. -# See the file COPYING for more details. +# -*- coding: UTF-8 -*- +#guiHelper.py +#A part of NonVisual Desktop Access (NVDA) +#Copyright (C) 2016 NV Access Limited +#This file is covered by the GNU General Public License. +#See the file COPYING for more details. """ Utilities to simplify the creation of wx GUIs, including automatic management of spacing. @@ -367,9 +369,6 @@ def addDialogDismissButtons(self, buttons, separated=False): self.dialogDismissButtonsAdded = True return buttons - - - class SIPABCMeta(wx.siplib.wrappertype, ABCMeta): """Meta class to be used for wx subclasses with abstract methods.""" pass From c915591ddb284c95dfb8f6ce7f455fea547e3946 Mon Sep 17 00:00:00 2001 From: buddsean Date: Wed, 24 Mar 2021 14:11:34 +1100 Subject: [PATCH 22/25] handle all top level window desctruction from safe app exit --- source/core.py | 3 +-- source/gui/__init__.py | 28 +++++++++++++++++----------- source/gui/installerGui.py | 4 ++-- source/gui/startupDialogs.py | 5 ++--- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/source/core.py b/source/core.py index 74d10383267..0bfc8dfcff8 100644 --- a/source/core.py +++ b/source/core.py @@ -112,9 +112,8 @@ def restart(disableAddons=False, debugLogging=False): """Restarts NVDA by starting a new copy.""" if globalVars.appArgs.launcher: import gui - import wx globalVars.exitCode=3 - wx.CallAfter(gui.mainFrame.Destroy) + gui.safeAppExit() return import subprocess import winUser diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 5a2a5d50b1f..58a89122d2f 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -75,10 +75,6 @@ def __init__(self): self.Show() self.Hide() - def Destroy(self): - self.sysTrayIcon.Destroy() - super().Destroy() - def prePopup(self): """Prepare for a popup. This should be called before any dialog or menu which should pop up for the user. @@ -199,7 +195,7 @@ def onExitCommand(self, evt): d.Show() self.postPopup() else: - wx.CallAfter(self.Destroy) + safeAppExit() def onNVDASettingsCommand(self,evt): self._popupSettingsDialog(NVDASettingsDialog) @@ -359,6 +355,20 @@ def onConfigProfilesCommand(self, evt): ProfilesDialog(gui.mainFrame).Show() self.postPopup() + +def safeAppExit(): + """ + Ensures the app is exited by all the top windows being destroyed + """ + + for window in wx.GetTopLevelWindows(): + if isinstance(window, wx.Dialog): + if window.IsModal(): + wx.CallAfter(window.EndModal, wx.ID_CLOSE_ALL) + else: + wx.CallAfter(window.Close) + wx.CallAfter(window.Destroy) + class SysTrayIcon(wx.adv.TaskBarIcon): def __init__(self, frame): @@ -527,10 +537,6 @@ def __init__(self, frame): self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.onActivate) self.Bind(wx.adv.EVT_TASKBAR_RIGHT_DOWN, self.onActivate) - def Destroy(self): - self.menu.Destroy() - super(SysTrayIcon, self).Destroy() - def onActivate(self, evt): mainFrame.prePopup() import appModules.nvda @@ -585,7 +591,7 @@ def terminate(): # This is called after the main loop exits because WM_QUIT exits the main loop # without destroying all objects correctly and we need to support WM_QUIT. # Therefore, any request to exit should exit the main loop. - wx.CallAfter(mainFrame.Destroy) + safeAppExit() # #4460: We need another iteration of the main loop # so that everything (especially the TaskBarIcon) is cleaned up properly. # ProcessPendingEvents doesn't seem to work, but MainLoop does. @@ -712,7 +718,7 @@ def onOk(self, evt): if action >= 2 and config.isAppX: action += 1 if action == 0: - wx.CallAfter(mainFrame.Destroy) + safeAppExit() elif action == 1: queueHandler.queueFunction(queueHandler.eventQueue,core.restart) elif action == 2: diff --git a/source/gui/installerGui.py b/source/gui/installerGui.py index 879fe6fbfcf..36a1f701b8a 100644 --- a/source/gui/installerGui.py +++ b/source/gui/installerGui.py @@ -102,7 +102,7 @@ def doInstall( winUser.SW_SHOWNORMAL ) else: - wx.CallAfter(gui.mainFrame.Destroy) + gui.safeAppExit() def doSilentInstall( @@ -450,7 +450,7 @@ def doCreatePortable(portableDirectory,copyUserConfig=False,silent=False,startAf return d.done() if silent: - wx.CallAfter(gui.mainFrame.Destroy) + gui.safeAppExit() else: # Translators: The message displayed when a portable copy of NVDA has been successfully created. # %s will be replaced with the destination directory. diff --git a/source/gui/startupDialogs.py b/source/gui/startupDialogs.py index 2fde71a322b..7bd10b47ca7 100644 --- a/source/gui/startupDialogs.py +++ b/source/gui/startupDialogs.py @@ -117,8 +117,7 @@ def run(cls): gui.mainFrame.prePopup() d = cls(gui.mainFrame) d.ShowModal() - if d and not d.IsBeingDeleted(): - wx.CallAfter(d.Destroy) + wx.CallAfter(d.Destroy) gui.mainFrame.postPopup() @@ -194,7 +193,7 @@ def onContinueRunning(self, evt): core.doStartupDialogs() def onExit(self, evt): - wx.CallAfter(gui.mainFrame.Destroy) + gui.safeAppExit() @classmethod def run(cls): From 9eb32c76821922e395ebff502a161fc7aba88684 Mon Sep 17 00:00:00 2001 From: buddsean Date: Wed, 24 Mar 2021 14:32:35 +1100 Subject: [PATCH 23/25] use close behaviour where possible --- source/gui/__init__.py | 7 ++++--- source/gui/startupDialogs.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 58a89122d2f..89d4d31aca0 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -365,9 +365,10 @@ def safeAppExit(): if isinstance(window, wx.Dialog): if window.IsModal(): wx.CallAfter(window.EndModal, wx.ID_CLOSE_ALL) - else: - wx.CallAfter(window.Close) - wx.CallAfter(window.Destroy) + if not isinstance(window, MainFrame): + wx.CallAfter(window.Close) + else: + wx.CallAfter(window.Destroy) class SysTrayIcon(wx.adv.TaskBarIcon): diff --git a/source/gui/startupDialogs.py b/source/gui/startupDialogs.py index 7bd10b47ca7..d26f7a9367a 100644 --- a/source/gui/startupDialogs.py +++ b/source/gui/startupDialogs.py @@ -117,7 +117,7 @@ def run(cls): gui.mainFrame.prePopup() d = cls(gui.mainFrame) d.ShowModal() - wx.CallAfter(d.Destroy) + d.Destroy() gui.mainFrame.postPopup() From f5eba29106828b602fd49dff070b525aa5b2a130 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 25 Mar 2021 12:21:37 +1100 Subject: [PATCH 24/25] improved logging --- source/gui/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 89d4d31aca0..43b1c80b5d4 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -362,13 +362,17 @@ def safeAppExit(): """ for window in wx.GetTopLevelWindows(): - if isinstance(window, wx.Dialog): - if window.IsModal(): - wx.CallAfter(window.EndModal, wx.ID_CLOSE_ALL) - if not isinstance(window, MainFrame): - wx.CallAfter(window.Close) - else: + if isinstance(window, wx.Dialog) and window.IsModal(): + log.info(f"ending modal {window} during exit process") + wx.CallAfter(window.EndModal, wx.ID_CLOSE_ALL) + if isinstance(window, MainFrame): + log.info(f"destroying main frame during exit process") + # the MainFrame has EVT_CLOSE bound to the ExitDialog + # which calls this function on exit, so destroy this window wx.CallAfter(window.Destroy) + else: + log.info(f"closing window {window} during exit process") + wx.CallAfter(window.Close) class SysTrayIcon(wx.adv.TaskBarIcon): From 7786252f1700d6ecfe9c4198c17ee2abcf1d7203 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 25 Mar 2021 18:40:52 +1100 Subject: [PATCH 25/25] update changes t2t --- user_docs/en/changes.t2t | 1 + 1 file changed, 1 insertion(+) diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index bdd98708d67..f7ff940b8a1 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -23,6 +23,7 @@ What's New in NVDA - Updated liblouis braille translator to [3.17.0 https://github.com/liblouis/liblouis/releases/tag/v3.17.0]. (#12137) - New braille tables: Belarusian literary braille, Belarusian computer braille, Urdu grade 1, Urdu grade 2. - Support for Adobe Flash content has been removed from NVDA due to the use of Flash being actively discouraged by Adobe. (#11131) +- NVDA will exit even with windows still open, the exit process now closes all NVDA windows and dialogs (#1740) == Bug Fixes ==