Skip to content

Commit 2b4f1ad

Browse files
committed
label done
1 parent 4bfcd5f commit 2b4f1ad

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ def __init__(self, font, **kwargs):
9191
self.local_group
9292
) # the local_group will always stay in the self Group
9393

94-
self.tab_replacement = kwargs.get("tab_replacement", (4, " "))
95-
self.tab_text = self.tab_replacement[1] * self.tab_replacement[0]
94+
self._tab_replacement = kwargs.get("tab_replacement", (4, " "))
95+
self._tab_text = self._tab_replacement[1] * self._tab_replacement[0]
9696
text = kwargs.get("text", "")
97-
self._text = self.tab_text.join(text.split("\t"))
97+
self._text = self._tab_text.join(text.split("\t"))
9898

9999
# Create the two-color palette
100100

@@ -171,14 +171,14 @@ def _reset_text(
171171
if base_alignment is not None:
172172
self.base_alignment = base_alignment
173173
if tab_replacement is not None:
174-
self.tab_replacement = tab_replacement
174+
self._tab_replacement = tab_replacement
175175

176176
# if text is not provided as a parameter (text is None), use the previous value.
177177
if (text is None) and self._save_text:
178178
text = self._text
179179

180180
if self._save_text: # text string will be saved
181-
self._text = self.tab_text.join(text.split("\t"))
181+
self._text = self._tab_text.join(text.split("\t"))
182182
else:
183183
self._text = None # save a None value since text string is not saved
184184

@@ -552,5 +552,5 @@ def _set_font(self, new_font):
552552
raise RuntimeError("font is immutable when save_text is False")
553553

554554
def _set_text(self, new_text, scale):
555-
new_text = self.tab_text.join(new_text.split("\t"))
555+
new_text = self._tab_text.join(new_text.split("\t"))
556556
self._reset_text(text=new_text, scale=self.scale)

adafruit_display_text/label.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ class Label(LabelBase):
6363
containing x,y pixel coordinates.
6464
:param int scale: Integer value of the pixel scaling
6565
:param bool base_alignment: when True allows to align text label to the baseline.
66-
This is helpful when two or more labels need to be aligned to the same baseline"""
66+
This is helpful when two or more labels need to be aligned to the same baseline
67+
:param: (int,str) tab_replacement: tuple with tab character replace information. When
68+
(4, " ") will indicate a tab replacement of 4 spaces, defaults to 4 spaces by
69+
tab character"""
6770

6871
# pylint: disable=too-many-instance-attributes, too-many-locals
6972
# This has a lot of getters/setters, maybe it needs cleanup.
@@ -76,6 +79,9 @@ def __init__(self, font, **kwargs):
7679

7780
if not max_glyphs and not text:
7881
raise RuntimeError("Please provide a max size, or initial text")
82+
self._tab_replacement = kwargs.get("tab_replacement", (4, " "))
83+
self._tab_text = self._tab_replacement[1] * self._tab_replacement[0]
84+
text = self._tab_text.join(text.split("\t"))
7985
if not max_glyphs:
8086
max_glyphs = len(text)
8187
# add one to max_size for the background bitmap tileGrid
@@ -300,6 +306,7 @@ def _update_text(
300306
self._update_background_color(self._background_color)
301307

302308
def _reset_text(self, new_text):
309+
new_text = self._tab_text.join(new_text.split("\t"))
303310
try:
304311
current_anchored_position = self.anchored_position
305312
self._update_text(str(new_text))

0 commit comments

Comments
 (0)