Skip to content

Label init with max_glyphs instead of text value is broken #141

Closed
@flavio-fernandes

Description

@flavio-fernandes

When Label class is initialized with size instead of text.
The split function is attempted in None object instead of an empty string.
That will cause this:

      File "/lib/adafruit_display_text/label.py", line 84, in __init__
      AttributeError: 'NoneType' object has no attribute 'split'

This is code with this issue (look at lines 78 ans 84):

text = kwargs.get("text", None)
if not max_glyphs and not text:
raise RuntimeError("Please provide a max size, or initial text")
self._tab_replacement = kwargs.get("tab_replacement", (4, " "))
self._tab_text = self._tab_replacement[1] * self._tab_replacement[0]
text = self._tab_text.join(text.split("\t"))

To reproduce, simply create a Label like this:

import terminalio
from adafruit_display_text import label

text_area = label.Label(terminalio.FONT, max_glyphs=10)

This used to work, so I suspect it is a regression introduced here:
2b4f1ad

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions