You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
provide a default return code when dialogs are forced to close (eg via an exit, perform cancel)
attach a callback to handle return codes
refocus a dialog in the event of needing to close it
if a default return code is provided, make the dialog close-able with alt+F4 and escape
for modal dialogs:
if wx.CANCEL is provided, make the dialog close-able with alt+F4 and escape
nice to have:
if wx.CANCEL is provided, perform this action when dialogs are forced to close.
refocus a dialog in the event of needing to close it
Constraints from wxPython
Support across wx.MessageBox, wx.MessageDialog and wx.Dialog for the following:
if a default return code is provided, make the dialog close-able with alt+F4 and escape
this is the behaviour already when wx.CANCEL is an option for the wx.MessageBox/wx.MessageDialog. If Yes/No is required, we should not accept alt+F4 and escape
classMessageBoxReturnCode(IntEnum):
OK=wx.OKYES=wx.YESNO=wx.NOCANCEL=wx.CANCELclassMessageDialog(
DpiScalingHelperMixinWithoutInit,
ContextHelpMixin,
wx.Dialog,
metaclass=SIPABCMeta
):
def__init__(
self,
parent: wx.Window,
message: str,
caption: str=wx.MessageBoxCaptionStr,
style: int=wx.OK|wx.CENTER,
**kwargs,
) ->None:
super().__init__(parent, message, caption, style, **kwargs)
defShow(self) ->None:
"""Show a non-blocking dialog. Attach buttons with button handlers"""passdefdefaultAction(self) ->None:
returnNone@staticmethoddefCloseInstances() ->None:
"""Close all dialogs with a default action"""pass@staticmethoddefBlockingInstancesExist() ->bool:
"""Check if dialogs are open without a default return code (eg Show without `self._defaultReturnCode`, or ShowModal without `wx.CANCEL`)"""pass@staticmethoddefFocusBlockingInstances() ->None:
"""Raise and focus open dialogs without a default return code (eg Show without `self._defaultReturnCode`, or ShowModal without `wx.CANCEL`)"""pass
See also: #12344, #12353, #10799, #8709, #13579
Current problems:
wx.OK or wx.CANCELas an option cannot be closed withAlt+F4/EscapeQuits from keyboard with about dialog openis re-enabled and works. Tagged with# Excluded to be fixed still (#12976), however that issue is closed.Requirements for the API
A developer should be able to:
wx.CANCELis provided, make the dialog close-able with alt+F4 and escapewx.CANCELis provided, perform this action when dialogs are forced to close.Constraints from wxPython
Support across
wx.MessageBox,wx.MessageDialogandwx.Dialogfor the following:wx.CANCELis an option for thewx.MessageBox/wx.MessageDialog. If Yes/No is required, we should not accept alt+F4 and escapewx.CANCELshould replacewx.NOand the buttons should be renamed appropriatelywx.Dialogorwx.MessageDialogis required to add the following:wx.MessageBoxis a function that doesn't support this.Using
wx.MessageDialogdirectly also can implement this.wx.Dialogwith.Showis required to add the following :wx.Dialog.ShowModalis blocking, so.Showmust be used.wx.MessageBoxandwx.MessageDialogdoesn't support.Show(), butwx.Dialogdoes.Suggestions moving forward:
In 2022.1:
gui.IsInMessageBoxwas a boolean, this has been replaced by a functiongui.message.isModalMessageBoxActive, which tracks if a messageBox is open in a safer manner. Done in Replace boolean gui.IsInMessageBox with function gui.message.isModalMessageBoxActive #13376 .In a future release
gui.MessageDialogclass, encourage migration to using it instead ofgui.messageBox.gui.messageDialogshould not subclasswx.MessageDialog, and instead be a customwx.DialogsubclassShowandShowModalto track instances to track inIsInMessageBoxwx.CANCELshould be replaced withwx.NOto enable esc/alt+f4, with the buttons renamedReference documentation
Additional context
Fix up #12984
#12976
Draft Sample API