Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the gui.messageBox API #13007

Open
seanbudd opened this issue Oct 29, 2021 · 11 comments
Open

Implement the gui.messageBox API #13007

seanbudd opened this issue Oct 29, 2021 · 11 comments
Assignees
Labels
Addon/API Changes to NVDA's API for addons to support addon development. api-breaking-change bug squash target merge-early Merge Early in a developer cycle p2 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority release/blocking this issue blocks the milestone release

Comments

@seanbudd
Copy link
Member

seanbudd commented Oct 29, 2021

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
@seanbudd seanbudd added Addon/API Changes to NVDA's API for addons to support addon development. deprecated/2022.1 Label used to track deprecations due for removal in the 2022.1 release labels Oct 29, 2021
@seanbudd seanbudd added this to the 2022.1 milestone Oct 29, 2021
@feerrenrut

This comment was marked as off-topic.

@lukaszgo1

This comment was marked as resolved.

@seanbudd seanbudd added api-breaking-change release/blocking this issue blocks the milestone release and removed deprecated/2022.1 Label used to track deprecations due for removal in the 2022.1 release labels Dec 10, 2021
@seanbudd seanbudd changed the title Improve the gui.messageBox API and usages Determine the gui.messageBox API Feb 7, 2022
@seanbudd seanbudd changed the title Determine the gui.messageBox API Design the gui.messageBox API Feb 7, 2022
@seanbudd seanbudd self-assigned this Feb 9, 2022
@seanbudd

This comment was marked as duplicate.

@lukaszgo1

This comment was marked as resolved.

@lukaszgo1

This comment was marked as resolved.

@XLTechie

This comment was marked as resolved.

@seanbudd

This comment was marked as resolved.

@seanbudd
Copy link
Member Author

See also: #8453

I think this is unrelated as these controls don't use wx.MessageBox/wx.MessageDialog. The progress dialog is an wx.ProgressDialog and log viewer is a wx.Frame.

@seanbudd

This comment was marked as duplicate.

seanbudd added a commit that referenced this issue Mar 3, 2022
…essageBoxActive (#13376)

Relates to #13007, as the new design should be backwards compatible, we can implement the API changes as-is for 2022.1.
Follow up to the API proposed in #12984

Summary of the issue:
The API for gui.message had not yet been determined for 2022.1, as per #13007.
As the future API is intended to be backwards compatible, this PR commits to the API proposed in #12984.

Description of how this pull request fixes the issue:
gui.IsInMessageBox was a boolean, this has been replaced by a function gui.message.isModalMessageBoxActive, which tracks if a messageBox is open in a safer manner.

Changes logic gui/message.py to be safer with locking and handling errors.
@seanbudd seanbudd removed their assignment Mar 3, 2022
@seanbudd seanbudd changed the title Design the gui.messageBox API Implement the gui.messageBox API Mar 4, 2022
@seanbudd
Copy link
Member Author

seanbudd commented Mar 8, 2022

We have similar functions in NVDA that should be assimilated into a final design:

  • gui.message.messageBox - blocking
  • gui.runScriptModalDialog - non-blocking modal with a callback
  • nvdaControls.MessageDialog - a dialog subclass that could potentially form the base of the new design.

@seanbudd seanbudd removed this from the 2022.1 milestone Mar 17, 2022
@feerrenrut feerrenrut added p3 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority p2 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority and removed p3 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority labels May 17, 2022
@feerrenrut feerrenrut added the merge-early Merge Early in a developer cycle label Jul 12, 2022
@seanbudd seanbudd added merge-early Merge Early in a developer cycle and removed merge-early Merge Early in a developer cycle labels Jul 12, 2022
@seanbudd seanbudd self-assigned this Jul 18, 2022
@feerrenrut
Copy link
Contributor

feerrenrut commented Oct 25, 2022

Ensure that the test Quits from keyboard with about dialog open is re-enabled and works.

It was tagged with # Excluded to be fixed still (#12976), however that issue is closed.

I've added this to the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Addon/API Changes to NVDA's API for addons to support addon development. api-breaking-change bug squash target merge-early Merge Early in a developer cycle p2 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority release/blocking this issue blocks the milestone release
Projects
None yet
Development

No branches or pull requests

4 participants