From d99d16fea8eacc5c81267d0e7bebcf2fd21197c1 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 19 Feb 2021 21:57:17 -0500 Subject: [PATCH 1/7] Changing logic to include tab replacement and glyph calculation --- adafruit_display_text/label.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 5549871..0acca68 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -91,6 +91,7 @@ def __init__( if not max_glyphs and not text: raise RuntimeError("Please provide a max size, or initial text") if not max_glyphs: + text = " ".join(text.split("\t")) max_glyphs = len(text) # add one to max_size for the background bitmap tileGrid From c7b6fd28f00f324c8c6a201310d26a6bcab1f44b Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 19 Feb 2021 23:01:24 -0500 Subject: [PATCH 2/7] adding text treatment to address corner case when max_glyphs values is greater thant string length --- adafruit_display_text/label.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 0acca68..f8f5f37 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -93,6 +93,7 @@ def __init__( if not max_glyphs: text = " ".join(text.split("\t")) max_glyphs = len(text) + text = " ".join(text.split("\t")) # add one to max_size for the background bitmap tileGrid # instance the Group From 8c2a73b1a4ac4ef8ea6a479f2af1acbb37a1831a Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Feb 2021 12:03:56 -0500 Subject: [PATCH 3/7] Including review regarding text logic in if statement --- adafruit_display_text/label.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index f8f5f37..b93f6f7 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -90,10 +90,10 @@ def __init__( ): if not max_glyphs and not text: raise RuntimeError("Please provide a max size, or initial text") + text = " ".join(text.split("\t")) if not max_glyphs: - text = " ".join(text.split("\t")) max_glyphs = len(text) - text = " ".join(text.split("\t")) + # add one to max_size for the background bitmap tileGrid # instance the Group From 90f29737f15e4c9db6377fdc63482cf4161d25a7 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 23 Feb 2021 12:18:31 -0500 Subject: [PATCH 4/7] Black and Pylint --- adafruit_display_text/label.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index b93f6f7..8a70e09 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -95,7 +95,6 @@ def __init__( max_glyphs = len(text) # add one to max_size for the background bitmap tileGrid - # instance the Group # self Group will contain a single local_group which contains a Group (self.local_group) # which contains a TileGrid From 2e860ccac55d2b673255b6d0025c24ca627fa4eb Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 25 Feb 2021 13:34:07 -0500 Subject: [PATCH 5/7] Addding tab verification when setter is called --- adafruit_display_text/label.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 8a70e09..559328f 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -387,6 +387,7 @@ def text(self): @text.setter def text(self, new_text): + new_text = " ".join(new_text.split("\t")) try: current_anchored_position = self.anchored_position self._update_text(str(new_text)) From cbc5963230768fc463797ef573d20b5a31684d83 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 25 Feb 2021 13:49:20 -0500 Subject: [PATCH 6/7] Tab verification for Bitmap Label --- adafruit_display_text/bitmap_label.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index bb5c723..c35e522 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -121,7 +121,7 @@ def __init__( ) # the local_group will always stay in the self Group self._font = font - self._text = text + self._text = " ".join(text.split("\t")) # Create the two-color palette self.palette = displayio.Palette(2) @@ -204,7 +204,7 @@ def _reset_text( text = self._text if self._save_text: # text string will be saved - self._text = text + self._text = " ".join(text.split("\t")) else: self._text = None # save a None value since text string is not saved @@ -239,7 +239,7 @@ def _reset_text( loose_box_y, loose_y_offset, ) = self._text_bounding_box( - text, + self._text, self._font, self._line_spacing, ) # calculate the box size for a tight and loose backgrounds @@ -262,7 +262,7 @@ def _reset_text( # Place the text into the Bitmap self._place_text( self.bitmap, - text, + self._text, self._font, self._line_spacing, self._padding_left - x_offset, @@ -632,6 +632,7 @@ def text(self): @text.setter # Cannot set color or background color with text setter, use separate setter def text(self, new_text): + new_text = " ".join(new_text.split("\t")) self._reset_text(text=new_text, scale=self.scale) @property From 71270ce1cd45612a0cbfe2a52581cb92a78459bf Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 27 Feb 2021 17:34:47 -0500 Subject: [PATCH 7/7] New parameter to include the possibility to define the number a type of character of the tab replacement --- adafruit_display_text/bitmap_label.py | 17 ++++++++++++----- adafruit_display_text/label.py | 10 +++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/adafruit_display_text/bitmap_label.py b/adafruit_display_text/bitmap_label.py index c35e522..f90a56b 100755 --- a/adafruit_display_text/bitmap_label.py +++ b/adafruit_display_text/bitmap_label.py @@ -68,7 +68,9 @@ class Label(displayio.Group): :param bool save_text: Set True to save the text string as a constant in the label structure. Set False to reduce memory use. :param: bool base_alignment: when True allows to align text label to the baseline. - This is helpful when two or more labels need to be aligned to the same baseline""" + This is helpful when two or more labels need to be aligned to the same baseline + :param tuple(int, str): tuple with tab character replace information. When (4, " ") + will indicate a tab replacement of 4 spaces, defaults to 4 spaces by tab character""" # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments # pylint: disable=too-many-branches, no-self-use, too-many-statements @@ -96,6 +98,7 @@ def __init__( save_text=True, # can reduce memory use if save_text = False scale=1, base_alignment=False, + tab_replacement=(4, " "), **kwargs, ): @@ -121,7 +124,8 @@ def __init__( ) # the local_group will always stay in the self Group self._font = font - self._text = " ".join(text.split("\t")) + self.tab_text = tab_replacement[1] * tab_replacement[0] + self._text = self.tab_text.join(text.split("\t")) # Create the two-color palette self.palette = displayio.Palette(2) @@ -150,6 +154,7 @@ def __init__( save_text=save_text, scale=scale, base_alignment=base_alignment, + tab_replacement=tab_replacement, ) def _reset_text( @@ -169,6 +174,7 @@ def _reset_text( save_text=None, scale=None, base_alignment=None, + tab_replacement=None, ): # Store all the instance variables @@ -198,13 +204,14 @@ def _reset_text( self._save_text = save_text if base_alignment is not None: self.base_alignment = base_alignment - + if tab_replacement is not None: + self.tab_replacement = tab_replacement # if text is not provided as a parameter (text is None), use the previous value. if (text is None) and self._save_text: text = self._text if self._save_text: # text string will be saved - self._text = " ".join(text.split("\t")) + self._text = self.tab_text.join(text.split("\t")) else: self._text = None # save a None value since text string is not saved @@ -632,7 +639,7 @@ def text(self): @text.setter # Cannot set color or background color with text setter, use separate setter def text(self, new_text): - new_text = " ".join(new_text.split("\t")) + new_text = self.tab_text.join(new_text.split("\t")) self._reset_text(text=new_text, scale=self.scale) @property diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 559328f..7d449a3 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -61,7 +61,9 @@ class Label(displayio.Group): containing x,y pixel coordinates. :param int scale: Integer value of the pixel scaling :param bool base_alignment: when True allows to align text label to the baseline. - This is helpful when two or more labels need to be aligned to the same baseline""" + This is helpful when two or more labels need to be aligned to the same baseline + :param tuple(int, str): tuple with tab character replace information. When (4, " ") + will indicate a tab replacement of 4 spaces, defaults to 4 spaces by tab character""" # pylint: disable=too-many-instance-attributes, too-many-locals # This has a lot of getters/setters, maybe it needs cleanup. @@ -86,11 +88,13 @@ def __init__( anchored_position=None, scale=1, base_alignment=False, + tab_replacement=(4, " "), **kwargs ): if not max_glyphs and not text: raise RuntimeError("Please provide a max size, or initial text") - text = " ".join(text.split("\t")) + self.tab_text = tab_replacement[1] * tab_replacement[0] + text = self.tab_text.join(text.split("\t")) if not max_glyphs: max_glyphs = len(text) @@ -387,7 +391,7 @@ def text(self): @text.setter def text(self, new_text): - new_text = " ".join(new_text.split("\t")) + new_text = self.tab_text.join(new_text.split("\t")) try: current_anchored_position = self.anchored_position self._update_text(str(new_text))