Skip to content

Implement the gui.messageBox API #13007

@seanbudd

Description

@seanbudd

See also: #12344, #12353, #10799, #8709, #13579

Current problems:

Requirements for the API

A developer should be able to:

  • rename buttons
  • associate context help with the given message box
  • show the dialog as a modal or a non-modal
  • for non modal dialogs:
    • 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

wx.Dialog or wx.MessageDialog is required to add the following:

  • rename buttons
  • associate context help with the given message box

wx.MessageBox is a function that doesn't support this.
Using wx.MessageDialog directly also can implement this.

wx.Dialog with .Show is required to add the following :

  • 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

wx.Dialog.ShowModal is blocking, so .Show must be used.
wx.MessageBox and wx.MessageDialog doesn't support .Show(), but wx.Dialog does.

Suggestions moving forward:

In 2022.1:

In a future release

  • Create a new gui.MessageDialog class, encourage migration to using it instead of gui.messageBox.
    • gui.messageDialog should not subclass wx.MessageDialog, and instead be a custom wx.Dialog subclass
    • override Show and ShowModal to track instances to track in IsInMessageBox
  • Run COM Registration fixing tool Dialog can't be closed by ALT+F4 or ESC #10799 wx.CANCEL should be replaced with wx.NO to enable esc/alt+f4, with the buttons renamed

Reference documentation

Additional context

Fix up #12984
#12976

Draft Sample API

class MessageBoxReturnCode(IntEnum):
	OK = wx.OK
	YES = wx.YES
	NO = wx.NO
	CANCEL = wx.CANCEL


class MessageDialog(
		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)

	def Show(self) -> None:
		"""Show a non-blocking dialog.
		Attach buttons with button handlers"""
		pass

	def defaultAction(self) -> None:
	       return None

	@staticmethod
	def CloseInstances() -> None:
		"""Close all dialogs with a default action"""
		pass

	@staticmethod
	def BlockingInstancesExist() -> bool:
		"""Check if dialogs are open without a default return code
		(eg Show without `self._defaultReturnCode`, or ShowModal without `wx.CANCEL`)"""
		pass

	@staticmethod
	def FocusBlockingInstances() -> None:
		"""Raise and focus open dialogs without a default return code
		(eg Show without `self._defaultReturnCode`, or ShowModal without `wx.CANCEL`)"""
		pass

Metadata

Metadata

Assignees

Labels

Addon/APIChanges to NVDA's API for addons to support addon development.api-breaking-changebug squash targetmerge-earlyMerge Early in a developer cyclep2https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priorityrelease/blockingthis issue blocks the milestone release

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions