11# A part of NonVisual Desktop Access (NVDA)
2- # Copyright (C) 2023 NV Access Limited
2+ # Copyright (C) 2023 NV Access Limited, Cyrille Bougot
33# This file is covered by the GNU General Public License.
44# See the file COPYING for more details.
55
3232
3333
3434class ErrorAddonInstallDialogWithYesNoButtons (ErrorAddonInstallDialog ):
35+ def __init__ (self , * args , useRememberChoiceCheckbox = False , ** kwargs ):
36+ self .useRememberChoiceCheckbox = useRememberChoiceCheckbox
37+ super ().__init__ (* args , ** kwargs )
38+
3539 def _addButtons (self , buttonHelper : ButtonHelper ) -> None :
3640 addonInfoButton = buttonHelper .addButton (
3741 self ,
@@ -58,6 +62,21 @@ def _addButtons(self, buttonHelper: ButtonHelper) -> None:
5862 noButton .SetDefault ()
5963 noButton .Bind (wx .EVT_BUTTON , lambda evt : self .EndModal (wx .NO ))
6064
65+ def _addContents (self , contentsSizer : BoxSizerHelper ):
66+ if self .useRememberChoiceCheckbox :
67+ # Translators: A checkbox in the dialog to remember the choice made when installing or enabling
68+ # incompatible add-ons, or when removing add-ons.
69+ self .rememberChoiceCheckbox = wx .CheckBox (
70+ self ,
71+ label = pgettext ("addonStore" , "Remember this choice for subsequent add-ons" ),
72+ )
73+ contentsSizer .addItem (self .rememberChoiceCheckbox )
74+
75+ def shouldRememberChoice (self ):
76+ if self .useRememberChoiceCheckbox :
77+ return self .rememberChoiceCheckbox .IsChecked ()
78+ return False
79+
6180
6281def _shouldProceedWhenInstalledAddonVersionUnknown (
6382 parent : wx .Window ,
@@ -92,26 +111,34 @@ def _shouldProceedWhenInstalledAddonVersionUnknown(
92111
93112
94113def _shouldProceedToRemoveAddonDialog (
95- addon : "SupportsVersionCheck"
114+ parent ,
115+ addon : "SupportsVersionCheck" ,
116+ useRememberChoiceCheckbox : bool = False ,
96117) -> bool :
97- return messageBox (
98- pgettext (
99- "addonStore" ,
100- # Translators: Presented when attempting to remove the selected add-on.
101- # {addon} is replaced with the add-on name.
102- "Are you sure you wish to remove the {addon} add-on from NVDA? "
103- "This cannot be undone."
104- ).format (addon = addon .name ),
118+ removeMessage = pgettext (
119+ "addonStore" ,
120+ # Translators: Presented when attempting to remove the selected add-on.
121+ # {addon} is replaced with the add-on name.
122+ "Are you sure you wish to remove the {addon} add-on from NVDA? "
123+ "This cannot be undone."
124+ ).format (addon = addon .name )
125+ dlg = ErrorAddonInstallDialogWithYesNoButtons (
126+ parent = parent ,
105127 # Translators: Title for message asking if the user really wishes to remove the selected Add-on.
106- pgettext ("addonStore" , "Remove Add-on" ),
107- wx .YES_NO | wx .NO_DEFAULT | wx .ICON_WARNING
108- ) == wx .YES
128+ title = pgettext ("addonStore" , "Remove Add-on" ),
129+ message = removeMessage ,
130+ showAddonInfoFunction = lambda : _showAddonInfo (addon ),
131+ useRememberChoiceCheckbox = useRememberChoiceCheckbox ,
132+ )
133+ res = displayDialogAsModal (dlg )
134+ return (res == wx .YES ), dlg .shouldRememberChoice ()
109135
110136
111137def _shouldInstallWhenAddonTooOldDialog (
112138 parent : wx .Window ,
113- addon : _AddonGUIModel
114- ) -> bool :
139+ addon : _AddonGUIModel ,
140+ useRememberChoiceCheckbox : bool = False ,
141+ ) -> tuple [bool , bool ]:
115142 incompatibleMessage = pgettext (
116143 "addonStore" ,
117144 # Translators: The message displayed when installing an add-on package that is incompatible
@@ -128,20 +155,23 @@ def _shouldInstallWhenAddonTooOldDialog(
128155 lastTestedNVDAVersion = addonAPIVersion .formatForGUI (addon .lastTestedNVDAVersion ),
129156 NVDAVersion = addonAPIVersion .formatForGUI (addonAPIVersion .CURRENT )
130157 )
131- res = displayDialogAsModal ( ErrorAddonInstallDialogWithYesNoButtons (
158+ dlg = ErrorAddonInstallDialogWithYesNoButtons (
132159 parent = parent ,
133160 # Translators: The title of a dialog presented when an error occurs.
134161 title = pgettext ("addonStore" , "Add-on not compatible" ),
135162 message = incompatibleMessage ,
136- showAddonInfoFunction = lambda : _showAddonInfo (addon )
137- ))
138- return res == wx .YES
163+ showAddonInfoFunction = lambda : _showAddonInfo (addon ),
164+ useRememberChoiceCheckbox = useRememberChoiceCheckbox ,
165+ )
166+ res = displayDialogAsModal (dlg )
167+ return (res == wx .YES ), dlg .shouldRememberChoice ()
139168
140169
141170def _shouldEnableWhenAddonTooOldDialog (
142171 parent : wx .Window ,
143- addon : _AddonGUIModel
144- ) -> bool :
172+ addon : _AddonGUIModel ,
173+ useRememberChoiceCheckbox : bool = False ,
174+ ) -> tuple [bool , bool ]:
145175 incompatibleMessage = pgettext (
146176 "addonStore" ,
147177 # Translators: The message displayed when enabling an add-on package that is incompatible
@@ -158,14 +188,16 @@ def _shouldEnableWhenAddonTooOldDialog(
158188 lastTestedNVDAVersion = addonAPIVersion .formatForGUI (addon .lastTestedNVDAVersion ),
159189 NVDAVersion = addonAPIVersion .formatForGUI (addonAPIVersion .CURRENT )
160190 )
161- res = displayDialogAsModal ( ErrorAddonInstallDialogWithYesNoButtons (
191+ dlg = ErrorAddonInstallDialogWithYesNoButtons (
162192 parent = parent ,
163193 # Translators: The title of a dialog presented when an error occurs.
164194 title = pgettext ("addonStore" , "Add-on not compatible" ),
165195 message = incompatibleMessage ,
166- showAddonInfoFunction = lambda : _showAddonInfo (addon )
167- ))
168- return res == wx .YES
196+ showAddonInfoFunction = lambda : _showAddonInfo (addon ),
197+ useRememberChoiceCheckbox = useRememberChoiceCheckbox ,
198+ )
199+ res = displayDialogAsModal (dlg )
200+ return (res == wx .YES ), dlg .shouldRememberChoice ()
169201
170202
171203def _showAddonInfo (addon : _AddonGUIModel ) -> None :
0 commit comments