|
59 | 59 | from prompt_toolkit.layout.dimension import AnyDimension
|
60 | 60 | from prompt_toolkit.layout.dimension import Dimension as D
|
61 | 61 | from prompt_toolkit.layout.dimension import to_dimension
|
62 |
| -from prompt_toolkit.layout.margins import NumberedMargin, ScrollbarMargin |
| 62 | +from prompt_toolkit.layout.margins import ( |
| 63 | + ConditionalMargin, |
| 64 | + NumberedMargin, |
| 65 | + ScrollbarMargin, |
| 66 | +) |
63 | 67 | from prompt_toolkit.layout.processors import (
|
64 | 68 | AppendAutoSuggestion,
|
65 | 69 | BeforeInput,
|
@@ -639,6 +643,7 @@ class _DialogList(Generic[_T]):
|
639 | 643 | selected_style: str = ""
|
640 | 644 | checked_style: str = ""
|
641 | 645 | multiple_selection: bool = False
|
| 646 | + show_scrollbar: bool = True |
642 | 647 |
|
643 | 648 | def __init__(self, values: Sequence[Tuple[_T, AnyFormattedText]]) -> None:
|
644 | 649 | assert len(values) > 0
|
@@ -702,7 +707,12 @@ def _find(event: E) -> None:
|
702 | 707 | self.window = Window(
|
703 | 708 | content=self.control,
|
704 | 709 | style=self.container_style,
|
705 |
| - right_margins=[ScrollbarMargin(display_arrows=True),], |
| 710 | + right_margins=[ |
| 711 | + ConditionalMargin( |
| 712 | + margin=ScrollbarMargin(display_arrows=True), |
| 713 | + filter=Condition(lambda: self.show_scrollbar), |
| 714 | + ), |
| 715 | + ], |
706 | 716 | dont_extend_height=True,
|
707 | 717 | )
|
708 | 718 |
|
@@ -804,14 +814,24 @@ class Checkbox(CheckboxList[str]):
|
804 | 814 | :param text: the text
|
805 | 815 | """
|
806 | 816 |
|
807 |
| - def __init__(self, text: AnyFormattedText = "") -> None: |
| 817 | + show_scrollbar = False |
| 818 | + |
| 819 | + def __init__(self, text: AnyFormattedText = "", checked: bool = False) -> None: |
808 | 820 | values = [("value", text)]
|
809 | 821 | CheckboxList.__init__(self, values)
|
| 822 | + self.checked = checked |
810 | 823 |
|
811 | 824 | @property
|
812 | 825 | def checked(self) -> bool:
|
813 | 826 | return "value" in self.current_values
|
814 | 827 |
|
| 828 | + @checked.setter |
| 829 | + def checked(self, value: bool) -> None: |
| 830 | + if value: |
| 831 | + self.current_values = ["value"] |
| 832 | + else: |
| 833 | + self.current_values = [] |
| 834 | + |
815 | 835 |
|
816 | 836 | class VerticalLine(object):
|
817 | 837 | """
|
|
0 commit comments