13
13
`prompt_toolkit.shortcuts.dialogs` on the other hand is considered stable.
14
14
"""
15
15
from functools import partial
16
- from typing import Callable , Generic , List , Optional , Tuple , TypeVar , Union
16
+ from typing import (
17
+ Callable ,
18
+ Generic ,
19
+ List ,
20
+ Optional ,
21
+ Sequence ,
22
+ Tuple ,
23
+ TypeVar ,
24
+ Union ,
25
+ )
17
26
18
27
from prompt_toolkit .application .current import get_app
19
28
from prompt_toolkit .auto_suggest import AutoSuggest , DynamicAutoSuggest
@@ -583,17 +592,7 @@ class _DialogList(Generic[_T]):
583
592
checked_style : str = ""
584
593
multiple_selection : bool = False
585
594
586
- def _handle_enter (self ) -> None :
587
- if self .multiple_selection :
588
- val = self .values [self ._selected_index ][0 ]
589
- if val in self .current_values :
590
- self .current_values .remove (val )
591
- else :
592
- self .current_values .append (val )
593
- else :
594
- self .current_value = self .values [self ._selected_index ][0 ]
595
-
596
- def __init__ (self , values : List [Tuple [_T , AnyFormattedText ]]) -> None :
595
+ def __init__ (self , values : Sequence [Tuple [_T , AnyFormattedText ]]) -> None :
597
596
assert len (values ) > 0
598
597
599
598
self .values = values
@@ -658,6 +657,16 @@ def _(event: E) -> None:
658
657
],
659
658
dont_extend_height = True )
660
659
660
+ def _handle_enter (self ) -> None :
661
+ if self .multiple_selection :
662
+ val = self .values [self ._selected_index ][0 ]
663
+ if val in self .current_values :
664
+ self .current_values .remove (val )
665
+ else :
666
+ self .current_values .append (val )
667
+ else :
668
+ self .current_value = self .values [self ._selected_index ][0 ]
669
+
661
670
def _get_text_fragments (self ) -> StyleAndTextTuples :
662
671
def mouse_handler (mouse_event : MouseEvent ) -> None :
663
672
"""
@@ -708,7 +717,7 @@ def __pt_container__(self) -> Container:
708
717
return self .window
709
718
710
719
711
- class RadioList (_DialogList ):
720
+ class RadioList (_DialogList [ _T ] ):
712
721
"""
713
722
List of radio buttons. Only one can be checked at the same time.
714
723
@@ -723,7 +732,7 @@ class RadioList(_DialogList):
723
732
multiple_selection = False
724
733
725
734
726
- class CheckboxList (_DialogList ):
735
+ class CheckboxList (_DialogList [ _T ] ):
727
736
"""
728
737
List of checkbox buttons. Several can be checked at the same time.
729
738
@@ -738,7 +747,7 @@ class CheckboxList(_DialogList):
738
747
multiple_selection = True
739
748
740
749
741
- class Checkbox (CheckboxList ):
750
+ class Checkbox (CheckboxList [ str ] ):
742
751
"""Backward compatibility util: creates a 1-sized CheckboxList
743
752
744
753
:param text: the text
0 commit comments