Skip to content

Commit

Permalink
Expose more arguments to confirm function (#1221)
Browse files Browse the repository at this point in the history
Straightforward addition of extra arguments.

Fixes #1009
  • Loading branch information
corranwebster authored Mar 17, 2023
1 parent 16b1418 commit 44ec41e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pyface/confirmation_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@
ConfirmationDialog = toolkit_object("confirmation_dialog:ConfirmationDialog")


def confirm(parent, message, title=None, cancel=False, default=NO):
def confirm(
parent,
message,
title=None,
cancel=False,
default=NO,
no_label="",
yes_label="",
informative="",
detail="",
):
""" Convenience method to show a confirmation dialog.
Parameters
Expand All @@ -33,6 +43,15 @@ def confirm(parent, message, title=None, cancel=False, default=NO):
``True`` if the dialog should contain a Cancel button.
default : NO, YES or CANCEL
Which button should be the default button.
no_label : str
Text to display in the NO button.
yes_label : str
Text to display in the YES button.
informative : str
Explanatory text to display along with the message.
detail : str
Further details about the message (displayed when the user clicks
"Show details").
"""
if title is None:
title = "Confirmation"
Expand All @@ -42,7 +61,11 @@ def confirm(parent, message, title=None, cancel=False, default=NO):
message=message,
cancel=cancel,
default=default,
no_label=no_label,
yes_label=yes_label,
title=title,
informative=informative,
detail=detail,
)

return dialog.open()
18 changes: 18 additions & 0 deletions pyface/tests/test_confirmation_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,24 @@ def setUp(self):
def tearDown(self):
GuiTestAssistant.tearDown(self)

@unittest.skipIf(no_modal_dialog_tester, "ModalDialogTester unavailable")
def test_extras(self):
# test that label and extra text arguments work
tester = ModalDialogTester(
lambda: confirm(
None,
"message",
default=NO,
no_label="Reject",
yes_label="Confirm",
informative="informative",
detail="detail",
)
)
tester.open_and_run(when_opened=lambda x: x.close(accept=True))

self.assertEqual(tester.result, OK)

@unittest.skipIf(no_modal_dialog_tester, "ModalDialogTester unavailable")
def test_reject(self):
# test that cancel works as expected
Expand Down

0 comments on commit 44ec41e

Please sign in to comment.