1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
""" A dialog that allows the user to chose a single item from a list. """
from .constant import OK
from .toolkit import toolkit_object
# Import the toolkit specific version.
SingleChoiceDialog = toolkit_object("single_choice_dialog:SingleChoiceDialog")
# Convenience functions.
def choose_one(parent, message, choices, title="Choose", cancel=True):
""" Convenience method to show an information message dialog.
Parameters
----------
parent : toolkit control or None
The toolkit control that should be the parent of the dialog.
message : str
The text of the message to display.
choices : list
List of objects to choose from.
title : str
The text of the dialog title.
cancel : bool
Whether or not the dialog can be cancelled.
Returns
-------
choice : Any
The selected object, or None if cancelled.
"""
dialog = SingleChoiceDialog(
parent=parent,
message=message,
choices=choices,
title=title,
cancel=cancel,
)
result = dialog.open()
if result == OK:
choice = dialog.choice
else:
choice = None
return choice
|