44# This file may be used under the terms of the GNU General Public License, version 2 or later.
55# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
66
7+ from typing import Set
8+ import weakref
79import wx
810
911import config
@@ -36,10 +38,12 @@ class WelcomeDialog(
3638 "Press NVDA+n at any time to activate the NVDA menu.\n "
3739 "From this menu, you can configure NVDA, get help and access other NVDA functions."
3840 )
41+ _instances : Set ["WelcomeDialog" ] = weakref .WeakSet ()
3942
4043 def __init__ (self , parent ):
4144 # Translators: The title of the Welcome dialog when user starts NVDA for the first time.
4245 super ().__init__ (parent , wx .ID_ANY , _ ("Welcome to NVDA" ))
46+ WelcomeDialog ._instances .add (self )
4347
4448 mainSizer = wx .BoxSizer (wx .VERTICAL )
4549 # Translators: The header for the Welcome dialog when user starts NVDA for the first time.
@@ -108,6 +112,7 @@ def onOk(self, evt):
108112 except Exception :
109113 log .debugWarning ("Could not save" , exc_info = True )
110114 self .EndModal (wx .ID_OK )
115+ self .Close ()
111116
112117 @classmethod
113118 def run (cls ):
@@ -117,9 +122,17 @@ def run(cls):
117122 gui .mainFrame .prePopup ()
118123 d = cls (gui .mainFrame )
119124 d .ShowModal ()
120- wx .CallAfter (d .Destroy )
121125 gui .mainFrame .postPopup ()
122126
127+ @classmethod
128+ def saveAndCloseInstances (cls ):
129+ instances = list (cls ._instances )
130+ for instance in instances :
131+ if instance and not instance .IsBeingDeleted () and instance .IsModal ():
132+ instance .onOk (None ) # Save and close
133+ else :
134+ cls ._instances .remove (instance )
135+
123136
124137class LauncherDialog (
125138 gui .contextHelp .ContextHelpMixin ,
0 commit comments