pytermgui.widgets.interactive.toggle
This module contains the Toggle
class.
View Source
0"""This module contains the `Toggle` class.""" 1 2from __future__ import annotations 3 4from typing import Any, Callable 5 6from .checkbox import Checkbox 7 8 9class Toggle(Checkbox): 10 """A specialized checkbox showing either of two states""" 11 12 chars = {**Checkbox.chars, **{"delimiter": [" ", " "], "checked": "choose"}} 13 14 def __init__( 15 self, 16 states: tuple[str, str], 17 callback: Callable[[str], Any] | None = None, 18 **attrs: Any, 19 ) -> None: 20 """Initialize object""" 21 22 self.states = states 23 24 self.set_char("checked", states[0]) 25 self.set_char("unchecked", states[1]) 26 27 super().__init__(callback, **attrs) 28 self.toggle(run_callback=False) 29 30 def _run_callback(self) -> None: 31 """Run the toggle callback with the label as its argument""" 32 33 if self.callback is not None: 34 self.callback(self.label)
View Source
10class Toggle(Checkbox): 11 """A specialized checkbox showing either of two states""" 12 13 chars = {**Checkbox.chars, **{"delimiter": [" ", " "], "checked": "choose"}} 14 15 def __init__( 16 self, 17 states: tuple[str, str], 18 callback: Callable[[str], Any] | None = None, 19 **attrs: Any, 20 ) -> None: 21 """Initialize object""" 22 23 self.states = states 24 25 self.set_char("checked", states[0]) 26 self.set_char("unchecked", states[1]) 27 28 super().__init__(callback, **attrs) 29 self.toggle(run_callback=False) 30 31 def _run_callback(self) -> None: 32 """Run the toggle callback with the label as its argument""" 33 34 if self.callback is not None: 35 self.callback(self.label)
A specialized checkbox showing either of two states
#  
Toggle(
states: tuple[str, str],
callback: Optional[Callable[[str], Any]] = None,
**attrs: Any
)
View Source
15 def __init__( 16 self, 17 states: tuple[str, str], 18 callback: Callable[[str], Any] | None = None, 19 **attrs: Any, 20 ) -> None: 21 """Initialize object""" 22 23 self.states = states 24 25 self.set_char("checked", states[0]) 26 self.set_char("unchecked", states[1]) 27 28 super().__init__(callback, **attrs) 29 self.toggle(run_callback=False)
Initialize object
#  
chars: dict[str, typing.Union[typing.List[str], str]] = {'delimiter': [' ', ' '], 'checked': 'choose', 'unchecked': ' '}
Default characters for this class