Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions docs/pages/dialogs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ each providing the return value (first element) and the displayed value (second

from prompt_toolkit.shortcuts import radiolist_dialog

result = radiolist_dialog(
title="RadioList dialog",
text="Which breakfast would you like ?",
values=[
("breakfast1", "Eggs and beacon"),
("breakfast2", "French breakfast"),
("breakfast3", "Equestrian breakfast")
]
result = radiolist_dialog(
title="RadioList dialog",
text="Which breakfast would you like ?",
values=[
("breakfast1", "Eggs and beacon"),
("breakfast2", "French breakfast"),
("breakfast3", "Equestrian breakfast")
],
initial_selected='breakfast2'
).run()


Expand All @@ -118,15 +119,16 @@ The :func:`~prompt_toolkit.shortcuts.checkboxlist_dialog` has the same usage and

from prompt_toolkit.shortcuts import checkboxlist_dialog

results_array = checkboxlist_dialog(
title="CheckboxList dialog",
results_array = checkboxlist_dialog(
title="CheckboxList dialog",
text="What would you like in your breakfast ?",
values=[
values=[
("eggs", "Eggs"),
("bacon", "Bacon"),
("croissants", "20 Croissants"),
("daily", "The breakfast of the day")
]
],
initial_selected=['eggs', 'croissants']
).run()


Expand Down
8 changes: 8 additions & 0 deletions prompt_toolkit/shortcuts/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def radiolist_dialog(
cancel_text: str = "Cancel",
values: Optional[List[Tuple[_T, AnyFormattedText]]] = None,
style: Optional[BaseStyle] = None,
initial_selected: Optional[_T] = None,
) -> Application[_T]:
"""
Display a simple list of element the user can choose amongst.
Expand All @@ -192,6 +193,9 @@ def ok_handler() -> None:

radio_list = RadioList(values)

if initial_selected:
radio_list.current_value = initial_selected

dialog = Dialog(
title=title,
body=HSplit(
Expand All @@ -215,6 +219,7 @@ def checkboxlist_dialog(
cancel_text: str = "Cancel",
values: Optional[List[Tuple[_T, AnyFormattedText]]] = None,
style: Optional[BaseStyle] = None,
initial_selected: Optional[List[_T]] = None,
) -> Application[List[_T]]:
"""
Display a simple list of element the user can choose multiple values amongst.
Expand All @@ -230,6 +235,9 @@ def ok_handler() -> None:

cb_list = CheckboxList(values)

if initial_selected:
cb_list.current_values = initial_selected

dialog = Dialog(
title=title,
body=HSplit(
Expand Down