diff --git a/src/textual/widgets/__init__.py b/src/textual/widgets/__init__.py index 12c7071957f..50f04fea326 100644 --- a/src/textual/widgets/__init__.py +++ b/src/textual/widgets/__init__.py @@ -48,6 +48,7 @@ "Checkbox", "ContentSwitcher", "DataTable", + "DigitDisplay", "DirectoryTree", "Footer", "Header", @@ -77,7 +78,6 @@ "Tooltip", "Tree", "Welcome", - "DigitDisplay", ] _WIDGETS_LAZY_LOADING_CACHE: dict[str, type[Widget]] = {} diff --git a/src/textual/widgets/_digit_display.py b/src/textual/widgets/_digit_display.py index c58769af294..66ed7b62ae7 100644 --- a/src/textual/widgets/_digit_display.py +++ b/src/textual/widgets/_digit_display.py @@ -6,8 +6,10 @@ _character_map: dict[str, str] = {} -# in the mappings below, we use underscores to make spaces more visible, -# we will strip them out later +_VIRTUAL_SPACE = "·" + +# in the mappings below, we use a dot instead of spaces to make them more +# visible, we will strip them out later _character_map[ "0" ] = """ @@ -189,8 +191,6 @@ """ -_VIRTUAL_SPACE = "·" - # here we strip spaces and replace virtual spaces with spaces _character_map = { k: v.strip().replace(_VIRTUAL_SPACE, " ") for k, v in _character_map.items() @@ -202,11 +202,11 @@ class _SingleDigitDisplay(Static): """The digit to display.""" DEFAULT_CSS = """ - _SingleDigitDisplay { - height: 3; - min-width: 2; - max-width: 3; - } + _SingleDigitDisplay { + height: 3; + min-width: 2; + max-width: 3; + } """ def __init__(self, initial_value=" ", **kwargs): @@ -243,8 +243,15 @@ class DigitDisplay(Widget): } """ - def __init__(self, initial_value="", **kwargs): - super().__init__(**kwargs) + def __init__( + self, + initial_value: str = "", + name: str | None = None, + id: str | None = None, + classes: str | None = None, + disabled: bool = False, + ): + super().__init__(name=name, id=id, classes=classes, disabled=disabled) self._displays = [_SingleDigitDisplay(d) for d in initial_value] self.digits = initial_value