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

Добавлена поддержка изменения длины кнопок #1773

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions src/prompt_toolkit/shortcuts/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def yes_no_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
yes_text: str = "Yes",
yes_width: int = 12,
no_text: str = "No",
no_width: int = 12,
style: BaseStyle | None = None,
) -> Application[bool]:
"""
Expand All @@ -64,8 +66,8 @@ def no_handler() -> None:
title=title,
body=Label(text=text, dont_extend_height=True),
buttons=[
Button(text=yes_text, handler=yes_handler),
Button(text=no_text, handler=no_handler),
Button(text=yes_text, handler=yes_handler, width=yes_width),
Button(text=no_text, handler=no_handler, width=no_width),
],
with_background=True,
)
Expand All @@ -79,7 +81,7 @@ def no_handler() -> None:
def button_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
buttons: list[tuple[str, _T]] = [],
buttons: list[tuple[str, int, _T]] = [],
style: BaseStyle | None = None,
) -> Application[_T]:
"""
Expand All @@ -94,8 +96,8 @@ def button_handler(v: _T) -> None:
title=title,
body=Label(text=text, dont_extend_height=True),
buttons=[
Button(text=t, handler=functools.partial(button_handler, v))
for t, v in buttons
Button(text=t, handler=functools.partial(button_handler, v), width=w)
for t, w, v in buttons
],
with_background=True,
)
Expand All @@ -107,7 +109,9 @@ def input_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
ok_text: str = "OK",
ok_width: int = 12,
cancel_text: str = "Cancel",
cancel_width: int = 12,
completer: Completer | None = None,
validator: Validator | None = None,
password: FilterOrBool = False,
Expand All @@ -126,8 +130,8 @@ def accept(buf: Buffer) -> bool:
def ok_handler() -> None:
get_app().exit(result=textfield.text)

ok_button = Button(text=ok_text, handler=ok_handler)
cancel_button = Button(text=cancel_text, handler=_return_none)
ok_button = Button(text=ok_text, handler=ok_handler, width=ok_width)
cancel_button = Button(text=cancel_text, handler=_return_none, width=cancel_width)

textfield = TextArea(
text=default,
Expand Down Expand Up @@ -159,6 +163,7 @@ def message_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
ok_text: str = "Ok",
ok_width: int = 12,
style: BaseStyle | None = None,
) -> Application[None]:
"""
Expand All @@ -167,7 +172,7 @@ def message_dialog(
dialog = Dialog(
title=title,
body=Label(text=text, dont_extend_height=True),
buttons=[Button(text=ok_text, handler=_return_none)],
buttons=[Button(text=ok_text, handler=_return_none, width=ok_width)],
with_background=True,
)

Expand All @@ -178,7 +183,9 @@ def radiolist_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
ok_text: str = "Ok",
ok_width: int = 12,
cancel_text: str = "Cancel",
cancel_width: int = 12,
values: Sequence[tuple[_T, AnyFormattedText]] | None = None,
default: _T | None = None,
style: BaseStyle | None = None,
Expand All @@ -204,8 +211,8 @@ def ok_handler() -> None:
padding=1,
),
buttons=[
Button(text=ok_text, handler=ok_handler),
Button(text=cancel_text, handler=_return_none),
Button(text=ok_text, handler=ok_handler, width=ok_width),
Button(text=cancel_text, handler=_return_none, width=cancel_width),
],
with_background=True,
)
Expand All @@ -217,7 +224,9 @@ def checkboxlist_dialog(
title: AnyFormattedText = "",
text: AnyFormattedText = "",
ok_text: str = "Ok",
ok_width: int = 12,
cancel_text: str = "Cancel",
cancel_width: int = 12,
values: Sequence[tuple[_T, AnyFormattedText]] | None = None,
default_values: Sequence[_T] | None = None,
style: BaseStyle | None = None,
Expand All @@ -243,8 +252,8 @@ def ok_handler() -> None:
padding=1,
),
buttons=[
Button(text=ok_text, handler=ok_handler),
Button(text=cancel_text, handler=_return_none),
Button(text=ok_text, handler=ok_handler, width=ok_width),
Button(text=cancel_text, handler=_return_none, width=cancel_width),
],
with_background=True,
)
Expand Down
Loading