Skip to content

Commit

Permalink
DigitDisplay: more followup on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdorneles committed Jul 26, 2023
1 parent fc5d189 commit 8a3d411
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/textual/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"Checkbox",
"ContentSwitcher",
"DataTable",
"DigitDisplay",
"DirectoryTree",
"Footer",
"Header",
Expand Down Expand Up @@ -77,7 +78,6 @@
"Tooltip",
"Tree",
"Welcome",
"DigitDisplay",
]

_WIDGETS_LAZY_LOADING_CACHE: dict[str, type[Widget]] = {}
Expand Down
29 changes: 18 additions & 11 deletions src/textual/widgets/_digit_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
] = """
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8a3d411

Please sign in to comment.