From fb0cfee6cc99d6bbe0da73d28415a6fbdaad0843 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Wed, 3 Jun 2020 23:48:08 -0500 Subject: [PATCH 01/21] added rectangular bitmap tilegrid as background color --- adafruit_display_text/label.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index ca634fe..29d1d70 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -77,7 +77,7 @@ def __init__( if not max_glyphs and not text: raise RuntimeError("Please provide a max size, or initial text") if not max_glyphs: - max_glyphs = len(text) + max_glyphs = len(text) + 1 # add one for the background bitmap tileGrid super().__init__(max_size=max_glyphs, **kwargs) self.width = max_glyphs self._font = font @@ -188,6 +188,18 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self._text = new_text self._boundingbox = (left, top, left + right, bottom - top) + background_bitmap = displayio.Bitmap( + self._boundingbox[2], self._boundingbox[3], 1 + ) + + tile_grid = displayio.TileGrid( + background_bitmap, pixel_shader=self.palette, x=left, y=top + ) + + self.insert( + 0, tile_grid + ) # add background bitmaps to the bottom layer of the group + @property def bounding_box(self): """An (x, y, w, h) tuple that completely covers all glyphs. The From 30e5a24edd589f075ae467feb91e8157914e6888 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 12:30:06 -0500 Subject: [PATCH 02/21] Fixed insert error that could cause additional bitmap insertions, added options for padding, including *background_tight* Boolean and padding_top/bottom/left/right optional parameters --- adafruit_display_text/label.py | 111 ++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 31 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 29d1d70..ccbf6cf 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -72,6 +72,11 @@ def __init__( color=0xFFFFFF, background_color=None, line_spacing=1.25, + background_tight=False, + padding_top=0, + padding_bottom=0, + padding_left=0, + padding_right=0, **kwargs ): if not max_glyphs and not text: @@ -79,6 +84,7 @@ def __init__( if not max_glyphs: max_glyphs = len(text) + 1 # add one for the background bitmap tileGrid super().__init__(max_size=max_glyphs, **kwargs) + self.width = max_glyphs self._font = font self._text = None @@ -87,28 +93,55 @@ def __init__( self.y = y self.palette = displayio.Palette(2) - if background_color is not None: - self.palette[0] = background_color - self.palette.make_opaque(0) - self._transparent_background = False - else: - self.palette[0] = 0 - self.palette.make_transparent(0) - self._transparent_background = True + # if background_color is not None: + # self.palette[0] = background_color + # self.palette.make_opaque(0) + # self._transparent_background = False + # else: + self.palette[0] = 0 + self.palette.make_transparent(0) + self._transparent_background = True self.palette[1] = color + self._background_color=background_color + bounds = self._font.get_bounding_box() self.height = bounds[1] self._line_spacing = line_spacing self._boundingbox = None + self.background_tight = background_tight # sets padding status for text background + self._background_palette = displayio.Palette(1) + #self._background_present = False + self.append(displayio.TileGrid(displayio.Bitmap(0, 0, 1), pixel_shader=self._background_palette)) # initialize with a blank tilegrid placeholder for background + + self.padding_top = padding_top + self.padding_bottom = padding_bottom + self.padding_left = padding_left + self.padding_right = padding_right + if text is not None: self._update_text(str(text)) + def _update_background_color(self, new_color): + + if new_color == None: + self._background_palette.make_transparent(0) + else: + self._background_palette.make_opaque(0) + self._background_palette[0]=new_color + self._background_color=new_color + + def _update_text(self, new_text): # pylint: disable=too-many-locals + #if self._background_present: + # i=1 + #else: + # i=0 x = 0 y = 0 - i = 0 + #i = 0 + i=1 old_c = 0 y_offset = int( ( @@ -118,17 +151,21 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals / 2 ) left = right = top = bottom = 0 + lines = 1 for character in new_text: if character == "\n": y += int(self.height * self._line_spacing) x = 0 + lines += 1 continue glyph = self._font.get_glyph(ord(character)) if not glyph: continue - right = max(right, x + glyph.width + glyph.shift_x) + #right = max(right, x + glyph.width + glyph.shift_x) + right = max(right, x + glyph.shift_x) # studied the docs! This is the correct spacing if y == 0: # first line, find the Ascender height - top = min(top, -glyph.height + y_offset) + #top = min(top, -glyph.height + y_offset) + top = min(top, - glyph.height - glyph.dy + y_offset) bottom = max(bottom, y - glyph.dy + y_offset) position_y = y - glyph.height - glyph.dy + y_offset position_x = x + glyph.dx @@ -161,6 +198,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals else: self.append(face) elif self._text and character == self._text[old_c]: + try: self[i].position = (position_x, position_y) except AttributeError: @@ -168,7 +206,6 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self[i].y = position_y x += glyph.shift_x - # TODO skip this for control sequences or non-printables. i += 1 old_c += 1 @@ -188,17 +225,38 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self._text = new_text self._boundingbox = (left, top, left + right, bottom - top) - background_bitmap = displayio.Bitmap( - self._boundingbox[2], self._boundingbox[3], 1 - ) + if self.background_tight: # draw a tight bounding box + box_width = self._boundingbox[2] + box_height = self._boundingbox[3] + x_box_offset = 0 + y_box_offset = top + + else: # draw a "loose" bounding box to include any ascenders/descenders. + + # check a few glyphs for maximum ascender and descender height + # Enhancement: it would be preferred to access the font "FONT_ASCENT" and "FONT_DESCENT" in the imported BDF file + glyphs = 'M j\'' # choose glyphs with highest ascender and lowest descender, will depend upon font used + ascender_max = descender_max = 0 + for char in glyphs: + thisGlyph = self._font.get_glyph(ord(char)) + ascender_max = max(ascender_max, thisGlyph.height + thisGlyph.dy) + descender_max = max(descender_max, -thisGlyph.dy) + + box_width = self._boundingbox[2] + self.padding_left + self.padding_right + x_box_offset = -self.padding_left + box_height = (ascender_max + descender_max) + int((lines-1) * self.height * self._line_spacing) + self.padding_top + self.padding_bottom + y_box_offset = -ascender_max + y_offset - self.padding_top + + self._update_background_color(self._background_color) + box_width=max(0, box_width) # remove any negative values + box_height=max(0, box_height) # remove any negative values + + background_bitmap = displayio.Bitmap(box_width, box_height, 1) tile_grid = displayio.TileGrid( - background_bitmap, pixel_shader=self.palette, x=left, y=top + background_bitmap, pixel_shader=self._background_palette, x=left+x_box_offset, y=y_box_offset ) - - self.insert( - 0, tile_grid - ) # add background bitmaps to the bottom layer of the group + self[0]=tile_grid # update the background bitmap in first item of the group @property def bounding_box(self): @@ -228,20 +286,11 @@ def color(self, new_color): @property def background_color(self): """Color of the background as an RGB hex number.""" - if not self._transparent_background: - return self.palette[0] - return None + return self._background_color @background_color.setter def background_color(self, new_color): - if new_color is not None: - self.palette[0] = new_color - self.palette.make_opaque(0) - self._transparent_background = False - else: - self.palette[0] = 0 - self.palette.make_transparent(0) - self._transparent_background = True + self._update_background_color(new_color) @property def text(self): From a51392c7279d896897971ede9e6d49a059bd4cd4 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 12:40:32 -0500 Subject: [PATCH 03/21] added example showing background color padding --- .../display_text_background_color_padding.py | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 examples/display_text_background_color_padding.py diff --git a/examples/display_text_background_color_padding.py b/examples/display_text_background_color_padding.py new file mode 100755 index 0000000..d2c8bc7 --- /dev/null +++ b/examples/display_text_background_color_padding.py @@ -0,0 +1,119 @@ +""" +This examples shows the use color and background_color +""" +import board +import displayio +import time +import terminalio +import fontio +import sys +import busio +#from adafruit_st7789 import ST7789 +from adafruit_ili9341 import ILI9341 +from adafruit_display_text import label + +# Setup the SPI display + +print('Starting the display...') # goes to serial only +displayio.release_displays() + + +spi = board.SPI() +tft_cs = board.D9 # arbitrary, pin not used +tft_dc = board.D10 +tft_backlight = board.D12 +tft_reset=board.D11 + +while not spi.try_lock(): + spi.configure(baudrate=32000000) + pass +spi.unlock() + +display_bus = displayio.FourWire( + spi, + command=tft_dc, + chip_select=tft_cs, + reset=tft_reset, + baudrate=32000000, + polarity=1, + phase=1, +) + +print('spi.frequency: {}'.format(spi.frequency)) + +DISPLAY_WIDTH=320 +DISPLAY_HEIGHT=240 + +#display = ST7789(display_bus, width=240, height=240, rotation=0, rowstart=80, colstart=0) +display = ILI9341(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT, rotation=180, auto_refresh=True) + +display.show(None) + +#font=terminalio.FONT + +from adafruit_bitmap_font import bitmap_font +font= bitmap_font.load_font('fonts/BitstreamVeraSans-Roman-24.bdf') + + +text =[] +text.append('none') # no ascenders or descenders +text.append('pop quops') # only descenders +text.append('MONSTERs are tall') # only ascenders +text.append('MONSTERs ate pop quops') # both ascenders and descenders +text.append('MONSTER quops\nnewline quops') # with newline + +display.auto_refresh=True +myGroup=displayio.Group(max_size=6) +display.show(myGroup) + +text_area=[] +myPadding=4 + +for i, thisText in enumerate(text): + text_area.append ( label.Label( + font, text=thisText, color=0xFFFFFF, background_color=None, + background_tight=False, + padding_top=myPadding, + padding_bottom=myPadding, + padding_left=myPadding, + padding_right=myPadding, + ) ) + + this_x=10 + this_y=10 + i*40 + text_area[i].x = 10 + text_area[i].y = 3 + i*50 + text_area[i].anchor_point = (0,0) + text_area[i].anchored_position = (this_x, this_y) + myGroup.append(text_area[i]) + +print("background color is {}".format(text_area[0].background_color)) + + +while True: + time.sleep(2) + text_area[0].text='text' # change some text in an existing text box (must fit within existing # of characters) + + + for area in text_area: + area.background_color = 0xFF0000 + print("background color is {:06x}".format(text_area[0].background_color)) + time.sleep(2) + for area in text_area: + area.background_color = 0x000088 + print("background color is {:06x}".format(text_area[0].background_color)) + time.sleep(2) + for area in text_area: + area.background_color = 0x00FF00 + print("background color is {:06x}".format(text_area[0].background_color)) + time.sleep(2) + for area in text_area: + area.background_color = 0xFF0000 + print("background color is {:06x}".format(text_area[0].background_color)) + time.sleep(2) + for area in text_area: + area.background_color = None + print("background color is {}".format(text_area[0].background_color)) + + + From c41ca13f0ac0c744039a48afe26c829cfc2760cb Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 12:41:41 -0500 Subject: [PATCH 04/21] ran black --- adafruit_display_text/label.py | 62 +++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index ccbf6cf..8085d33 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -103,17 +103,23 @@ def __init__( self._transparent_background = True self.palette[1] = color - self._background_color=background_color + self._background_color = background_color bounds = self._font.get_bounding_box() self.height = bounds[1] self._line_spacing = line_spacing self._boundingbox = None - self.background_tight = background_tight # sets padding status for text background + self.background_tight = ( + background_tight # sets padding status for text background + ) self._background_palette = displayio.Palette(1) - #self._background_present = False - self.append(displayio.TileGrid(displayio.Bitmap(0, 0, 1), pixel_shader=self._background_palette)) # initialize with a blank tilegrid placeholder for background + # self._background_present = False + self.append( + displayio.TileGrid( + displayio.Bitmap(0, 0, 1), pixel_shader=self._background_palette + ) + ) # initialize with a blank tilegrid placeholder for background self.padding_top = padding_top self.padding_bottom = padding_bottom @@ -129,19 +135,18 @@ def _update_background_color(self, new_color): self._background_palette.make_transparent(0) else: self._background_palette.make_opaque(0) - self._background_palette[0]=new_color - self._background_color=new_color - + self._background_palette[0] = new_color + self._background_color = new_color def _update_text(self, new_text): # pylint: disable=too-many-locals - #if self._background_present: + # if self._background_present: # i=1 - #else: + # else: # i=0 x = 0 y = 0 - #i = 0 - i=1 + # i = 0 + i = 1 old_c = 0 y_offset = int( ( @@ -161,11 +166,13 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals glyph = self._font.get_glyph(ord(character)) if not glyph: continue - #right = max(right, x + glyph.width + glyph.shift_x) - right = max(right, x + glyph.shift_x) # studied the docs! This is the correct spacing + # right = max(right, x + glyph.width + glyph.shift_x) + right = max( + right, x + glyph.shift_x + ) # studied the docs! This is the correct spacing if y == 0: # first line, find the Ascender height - #top = min(top, -glyph.height + y_offset) - top = min(top, - glyph.height - glyph.dy + y_offset) + # top = min(top, -glyph.height + y_offset) + top = min(top, -glyph.height - glyph.dy + y_offset) bottom = max(bottom, y - glyph.dy + y_offset) position_y = y - glyph.height - glyph.dy + y_offset position_x = x + glyph.dx @@ -225,17 +232,17 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self._text = new_text self._boundingbox = (left, top, left + right, bottom - top) - if self.background_tight: # draw a tight bounding box + if self.background_tight: # draw a tight bounding box box_width = self._boundingbox[2] box_height = self._boundingbox[3] x_box_offset = 0 y_box_offset = top - else: # draw a "loose" bounding box to include any ascenders/descenders. + else: # draw a "loose" bounding box to include any ascenders/descenders. # check a few glyphs for maximum ascender and descender height # Enhancement: it would be preferred to access the font "FONT_ASCENT" and "FONT_DESCENT" in the imported BDF file - glyphs = 'M j\'' # choose glyphs with highest ascender and lowest descender, will depend upon font used + glyphs = "M j'" # choose glyphs with highest ascender and lowest descender, will depend upon font used ascender_max = descender_max = 0 for char in glyphs: thisGlyph = self._font.get_glyph(ord(char)) @@ -244,19 +251,26 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals box_width = self._boundingbox[2] + self.padding_left + self.padding_right x_box_offset = -self.padding_left - box_height = (ascender_max + descender_max) + int((lines-1) * self.height * self._line_spacing) + self.padding_top + self.padding_bottom + box_height = ( + (ascender_max + descender_max) + + int((lines - 1) * self.height * self._line_spacing) + + self.padding_top + + self.padding_bottom + ) y_box_offset = -ascender_max + y_offset - self.padding_top - self._update_background_color(self._background_color) - box_width=max(0, box_width) # remove any negative values - box_height=max(0, box_height) # remove any negative values + box_width = max(0, box_width) # remove any negative values + box_height = max(0, box_height) # remove any negative values background_bitmap = displayio.Bitmap(box_width, box_height, 1) tile_grid = displayio.TileGrid( - background_bitmap, pixel_shader=self._background_palette, x=left+x_box_offset, y=y_box_offset + background_bitmap, + pixel_shader=self._background_palette, + x=left + x_box_offset, + y=y_box_offset, ) - self[0]=tile_grid # update the background bitmap in first item of the group + self[0] = tile_grid # update the background bitmap in first item of the group @property def bounding_box(self): From 7464d08d4534acf4d13882b7b5406878da797a91 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 12:42:31 -0500 Subject: [PATCH 05/21] ran black --- .../display_text_background_color_padding.py | 91 +++++++++++-------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/examples/display_text_background_color_padding.py b/examples/display_text_background_color_padding.py index d2c8bc7..b111e35 100755 --- a/examples/display_text_background_color_padding.py +++ b/examples/display_text_background_color_padding.py @@ -8,21 +8,22 @@ import fontio import sys import busio -#from adafruit_st7789 import ST7789 + +# from adafruit_st7789 import ST7789 from adafruit_ili9341 import ILI9341 from adafruit_display_text import label # Setup the SPI display -print('Starting the display...') # goes to serial only +print("Starting the display...") # goes to serial only displayio.release_displays() spi = board.SPI() -tft_cs = board.D9 # arbitrary, pin not used +tft_cs = board.D9 # arbitrary, pin not used tft_dc = board.D10 tft_backlight = board.D12 -tft_reset=board.D11 +tft_reset = board.D11 while not spi.try_lock(): spi.configure(baudrate=32000000) @@ -39,51 +40,63 @@ phase=1, ) -print('spi.frequency: {}'.format(spi.frequency)) +print("spi.frequency: {}".format(spi.frequency)) -DISPLAY_WIDTH=320 -DISPLAY_HEIGHT=240 +DISPLAY_WIDTH = 320 +DISPLAY_HEIGHT = 240 -#display = ST7789(display_bus, width=240, height=240, rotation=0, rowstart=80, colstart=0) -display = ILI9341(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT, rotation=180, auto_refresh=True) +# display = ST7789(display_bus, width=240, height=240, rotation=0, rowstart=80, colstart=0) +display = ILI9341( + display_bus, + width=DISPLAY_WIDTH, + height=DISPLAY_HEIGHT, + rotation=180, + auto_refresh=True, +) display.show(None) -#font=terminalio.FONT +# font=terminalio.FONT from adafruit_bitmap_font import bitmap_font -font= bitmap_font.load_font('fonts/BitstreamVeraSans-Roman-24.bdf') + +font = bitmap_font.load_font("fonts/BitstreamVeraSans-Roman-24.bdf") -text =[] -text.append('none') # no ascenders or descenders -text.append('pop quops') # only descenders -text.append('MONSTERs are tall') # only ascenders -text.append('MONSTERs ate pop quops') # both ascenders and descenders -text.append('MONSTER quops\nnewline quops') # with newline +text = [] +text.append("none") # no ascenders or descenders +text.append("pop quops") # only descenders +text.append("MONSTERs are tall") # only ascenders +text.append("MONSTERs ate pop quops") # both ascenders and descenders +text.append("MONSTER quops\nnewline quops") # with newline -display.auto_refresh=True -myGroup=displayio.Group(max_size=6) +display.auto_refresh = True +myGroup = displayio.Group(max_size=6) display.show(myGroup) -text_area=[] -myPadding=4 +text_area = [] +myPadding = 4 for i, thisText in enumerate(text): - text_area.append ( label.Label( - font, text=thisText, color=0xFFFFFF, background_color=None, - background_tight=False, - padding_top=myPadding, - padding_bottom=myPadding, - padding_left=myPadding, - padding_right=myPadding, - ) ) - - this_x=10 - this_y=10 + i*40 - text_area[i].x = 10 - text_area[i].y = 3 + i*50 - text_area[i].anchor_point = (0,0) + text_area.append( + label.Label( + font, + text=thisText, + color=0xFFFFFF, + background_color=None, + background_tight=False, + padding_top=myPadding, + padding_bottom=myPadding, + padding_left=myPadding, + padding_right=myPadding, + ) + ) + + this_x = 10 + this_y = 10 + i * 40 + text_area[i].x = 10 + text_area[i].y = 3 + i * 50 + text_area[i].anchor_point = (0, 0) text_area[i].anchored_position = (this_x, this_y) myGroup.append(text_area[i]) @@ -92,8 +105,9 @@ while True: time.sleep(2) - text_area[0].text='text' # change some text in an existing text box (must fit within existing # of characters) - + text_area[ + 0 + ].text = "text" # change some text in an existing text box (must fit within existing # of characters) for area in text_area: area.background_color = 0xFF0000 @@ -114,6 +128,3 @@ for area in text_area: area.background_color = None print("background color is {}".format(text_area[0].background_color)) - - - From ee5a5ab4085254128ec7a294b6b57d64d3a79959 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 13:12:11 -0500 Subject: [PATCH 06/21] Deleted unnecessary comments --- adafruit_display_text/label.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 8085d33..d121bdf 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -93,11 +93,6 @@ def __init__( self.y = y self.palette = displayio.Palette(2) - # if background_color is not None: - # self.palette[0] = background_color - # self.palette.make_opaque(0) - # self._transparent_background = False - # else: self.palette[0] = 0 self.palette.make_transparent(0) self._transparent_background = True @@ -114,7 +109,6 @@ def __init__( background_tight # sets padding status for text background ) self._background_palette = displayio.Palette(1) - # self._background_present = False self.append( displayio.TileGrid( displayio.Bitmap(0, 0, 1), pixel_shader=self._background_palette @@ -139,13 +133,8 @@ def _update_background_color(self, new_color): self._background_color = new_color def _update_text(self, new_text): # pylint: disable=too-many-locals - # if self._background_present: - # i=1 - # else: - # i=0 x = 0 y = 0 - # i = 0 i = 1 old_c = 0 y_offset = int( @@ -166,12 +155,10 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals glyph = self._font.get_glyph(ord(character)) if not glyph: continue - # right = max(right, x + glyph.width + glyph.shift_x) right = max( right, x + glyph.shift_x ) # studied the docs! This is the correct spacing if y == 0: # first line, find the Ascender height - # top = min(top, -glyph.height + y_offset) top = min(top, -glyph.height - glyph.dy + y_offset) bottom = max(bottom, y - glyph.dy + y_offset) position_y = y - glyph.height - glyph.dy + y_offset From ae577587e458e42201a2e825580daeac1b129a9c Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 14:06:24 -0500 Subject: [PATCH 07/21] Hid the following variables inside the class (background_tight and padding_*) since there is are getter/setter and update functions --- adafruit_display_text/label.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index d121bdf..f221b7e 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -105,9 +105,8 @@ def __init__( self._line_spacing = line_spacing self._boundingbox = None - self.background_tight = ( - background_tight # sets padding status for text background - ) + self._background_tight = background_tight # sets padding status for text background + self._background_palette = displayio.Palette(1) self.append( displayio.TileGrid( @@ -115,10 +114,10 @@ def __init__( ) ) # initialize with a blank tilegrid placeholder for background - self.padding_top = padding_top - self.padding_bottom = padding_bottom - self.padding_left = padding_left - self.padding_right = padding_right + self._padding_top = padding_top + self._padding_bottom = padding_bottom + self._padding_left = padding_left + self._padding_right = padding_right if text is not None: self._update_text(str(text)) @@ -219,7 +218,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self._text = new_text self._boundingbox = (left, top, left + right, bottom - top) - if self.background_tight: # draw a tight bounding box + if self._background_tight: # draw a tight bounding box box_width = self._boundingbox[2] box_height = self._boundingbox[3] x_box_offset = 0 @@ -236,15 +235,15 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals ascender_max = max(ascender_max, thisGlyph.height + thisGlyph.dy) descender_max = max(descender_max, -thisGlyph.dy) - box_width = self._boundingbox[2] + self.padding_left + self.padding_right - x_box_offset = -self.padding_left + box_width = self._boundingbox[2] + self._padding_left + self._padding_right + x_box_offset = -self._padding_left box_height = ( (ascender_max + descender_max) + int((lines - 1) * self.height * self._line_spacing) - + self.padding_top - + self.padding_bottom + + self._padding_top + + self._padding_bottom ) - y_box_offset = -ascender_max + y_offset - self.padding_top + y_box_offset = -ascender_max + y_offset - self._padding_top self._update_background_color(self._background_color) box_width = max(0, box_width) # remove any negative values From 5c11366c86798effc1d3cf235b6bd124d0c39d18 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 15:41:39 -0500 Subject: [PATCH 08/21] deleted unnecessary variable --- 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 f221b7e..65c8f7c 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -95,7 +95,6 @@ def __init__( self.palette = displayio.Palette(2) self.palette[0] = 0 self.palette.make_transparent(0) - self._transparent_background = True self.palette[1] = color self._background_color = background_color From a90c00e4acc19a0c3bb660644db98e0f9bacbc76 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:04:00 -0500 Subject: [PATCH 09/21] ran black for reformatting --- adafruit_display_text/label.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 65c8f7c..f6a1991 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -104,8 +104,10 @@ def __init__( self._line_spacing = line_spacing self._boundingbox = None - self._background_tight = background_tight # sets padding status for text background - + self._background_tight = ( + background_tight # sets padding status for text background + ) + self._background_palette = displayio.Palette(1) self.append( displayio.TileGrid( From 04ba5b35b3a0f1fe609130c915956a7946dcc378 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:11:42 -0500 Subject: [PATCH 10/21] updated to resolve pylint formatting warmings --- adafruit_display_text/label.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index f6a1991..5bfebb2 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -125,7 +125,7 @@ def __init__( def _update_background_color(self, new_color): - if new_color == None: + if new_color is None: self._background_palette.make_transparent(0) else: self._background_palette.make_opaque(0) @@ -228,13 +228,15 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals else: # draw a "loose" bounding box to include any ascenders/descenders. # check a few glyphs for maximum ascender and descender height - # Enhancement: it would be preferred to access the font "FONT_ASCENT" and "FONT_DESCENT" in the imported BDF file - glyphs = "M j'" # choose glyphs with highest ascender and lowest descender, will depend upon font used + # Enhancement: it would be preferred to access the font "FONT_ASCENT" and + # "FONT_DESCENT" in the imported BDF file + glyphs = "M j'" # choose glyphs with highest ascender and lowest + # descender, will depend upon font used ascender_max = descender_max = 0 for char in glyphs: - thisGlyph = self._font.get_glyph(ord(char)) - ascender_max = max(ascender_max, thisGlyph.height + thisGlyph.dy) - descender_max = max(descender_max, -thisGlyph.dy) + this_glyph = self._font.get_glyph(ord(char)) + ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) + descender_max = max(descender_max, -this_glyph.dy) box_width = self._boundingbox[2] + self._padding_left + self._padding_right x_box_offset = -self._padding_left From c6951dcb69466cc0d59f183cc4898363fe428e8b Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:16:30 -0500 Subject: [PATCH 11/21] ran black again after pylint changes --- adafruit_display_text/label.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 5bfebb2..3872179 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -228,10 +228,10 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals else: # draw a "loose" bounding box to include any ascenders/descenders. # check a few glyphs for maximum ascender and descender height - # Enhancement: it would be preferred to access the font "FONT_ASCENT" and + # Enhancement: it would be preferred to access the font "FONT_ASCENT" and # "FONT_DESCENT" in the imported BDF file - glyphs = "M j'" # choose glyphs with highest ascender and lowest - # descender, will depend upon font used + glyphs = "M j'" # choose glyphs with highest ascender and lowest + # descender, will depend upon font used ascender_max = descender_max = 0 for char in glyphs: this_glyph = self._font.get_glyph(ord(char)) From a52eede6464c386b378c30de8583fe1404fd79e2 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:32:32 -0500 Subject: [PATCH 12/21] broke out a separate function for _create_background_box --- adafruit_display_text/label.py | 129 ++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 41 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 3872179..11b1ab6 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -123,6 +123,51 @@ def __init__( if text is not None: self._update_text(str(text)) + def _create_background_box(self, lines, left, y_offset): + + if self._background_tight: # draw a tight bounding box + box_width = self._boundingbox[2] + box_height = self._boundingbox[3] + x_box_offset = 0 + y_box_offset = top + + else: # draw a "loose" bounding box to include any ascenders/descenders. + + # check a few glyphs for maximum ascender and descender height + # Enhancement: it would be preferred to access the font "FONT_ASCENT" and + # "FONT_DESCENT" in the imported BDF file + glyphs = "M j'" # choose glyphs with highest ascender and lowest + # descender, will depend upon font used + ascender_max = descender_max = 0 + for char in glyphs: + this_glyph = self._font.get_glyph(ord(char)) + ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) + descender_max = max(descender_max, -this_glyph.dy) + + box_width = self._boundingbox[2] + self._padding_left + self._padding_right + x_box_offset = -self._padding_left + box_height = ( + (ascender_max + descender_max) + + int((lines - 1) * self.height * self._line_spacing) + + self._padding_top + + self._padding_bottom + ) + y_box_offset = -ascender_max + y_offset - self._padding_top + + self._update_background_color(self._background_color) + box_width = max(0, box_width) # remove any negative values + box_height = max(0, box_height) # remove any negative values + + background_bitmap = displayio.Bitmap(box_width, box_height, 1) + tile_grid = displayio.TileGrid( + background_bitmap, + pixel_shader=self._background_palette, + x=left + x_box_offset, + y=y_box_offset, + ) + + return tile_grid + def _update_background_color(self, new_color): if new_color is None: @@ -219,47 +264,49 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self._text = new_text self._boundingbox = (left, top, left + right, bottom - top) - if self._background_tight: # draw a tight bounding box - box_width = self._boundingbox[2] - box_height = self._boundingbox[3] - x_box_offset = 0 - y_box_offset = top - - else: # draw a "loose" bounding box to include any ascenders/descenders. - - # check a few glyphs for maximum ascender and descender height - # Enhancement: it would be preferred to access the font "FONT_ASCENT" and - # "FONT_DESCENT" in the imported BDF file - glyphs = "M j'" # choose glyphs with highest ascender and lowest - # descender, will depend upon font used - ascender_max = descender_max = 0 - for char in glyphs: - this_glyph = self._font.get_glyph(ord(char)) - ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) - descender_max = max(descender_max, -this_glyph.dy) - - box_width = self._boundingbox[2] + self._padding_left + self._padding_right - x_box_offset = -self._padding_left - box_height = ( - (ascender_max + descender_max) - + int((lines - 1) * self.height * self._line_spacing) - + self._padding_top - + self._padding_bottom - ) - y_box_offset = -ascender_max + y_offset - self._padding_top - - self._update_background_color(self._background_color) - box_width = max(0, box_width) # remove any negative values - box_height = max(0, box_height) # remove any negative values - - background_bitmap = displayio.Bitmap(box_width, box_height, 1) - tile_grid = displayio.TileGrid( - background_bitmap, - pixel_shader=self._background_palette, - x=left + x_box_offset, - y=y_box_offset, - ) - self[0] = tile_grid # update the background bitmap in first item of the group + # if self._background_tight: # draw a tight bounding box + # box_width = self._boundingbox[2] + # box_height = self._boundingbox[3] + # x_box_offset = 0 + # y_box_offset = top + + # else: # draw a "loose" bounding box to include any ascenders/descenders. + + # # check a few glyphs for maximum ascender and descender height + # # Enhancement: it would be preferred to access the font "FONT_ASCENT" and + # # "FONT_DESCENT" in the imported BDF file + # glyphs = "M j'" # choose glyphs with highest ascender and lowest + # # descender, will depend upon font used + # ascender_max = descender_max = 0 + # for char in glyphs: + # this_glyph = self._font.get_glyph(ord(char)) + # ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) + # descender_max = max(descender_max, -this_glyph.dy) + + # box_width = self._boundingbox[2] + self._padding_left + self._padding_right + # x_box_offset = -self._padding_left + # box_height = ( + # (ascender_max + descender_max) + # + int((lines - 1) * self.height * self._line_spacing) + # + self._padding_top + # + self._padding_bottom + # ) + # y_box_offset = -ascender_max + y_offset - self._padding_top + + # self._update_background_color(self._background_color) + # box_width = max(0, box_width) # remove any negative values + # box_height = max(0, box_height) # remove any negative values + + # background_bitmap = displayio.Bitmap(box_width, box_height, 1) + # tile_grid = displayio.TileGrid( + # background_bitmap, + # pixel_shader=self._background_palette, + # x=left + x_box_offset, + # y=y_box_offset, + # ) + # self[0] = tile_grid # update the background bitmap in first item of the group + + self[0] = self._create_background_box(lines, left, y_offset) @property def bounding_box(self): From 9f4c2df9b2537b8ce8a0f2a56a2163fc98696995 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:36:52 -0500 Subject: [PATCH 13/21] updated missing variable to reference back to self instance variables --- adafruit_display_text/label.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 11b1ab6..f8c8445 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -123,13 +123,14 @@ def __init__( if text is not None: self._update_text(str(text)) - def _create_background_box(self, lines, left, y_offset): + def _create_background_box(self, lines, y_offset): if self._background_tight: # draw a tight bounding box box_width = self._boundingbox[2] box_height = self._boundingbox[3] x_box_offset = 0 - y_box_offset = top + y_box_offset = self._bounding_box[1] + left = self._bounding_box[0] else: # draw a "loose" bounding box to include any ascenders/descenders. @@ -306,7 +307,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals # ) # self[0] = tile_grid # update the background bitmap in first item of the group - self[0] = self._create_background_box(lines, left, y_offset) + self[0] = self._create_background_box(lines, y_offset) @property def bounding_box(self): From a1714217d20b431c30b4e03a7a7ebe2b84dcb5ce Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:45:11 -0500 Subject: [PATCH 14/21] reduced quantity of class instance variables: put padding into a tuple --- adafruit_display_text/label.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index f8c8445..c1b8fa9 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -115,22 +115,24 @@ def __init__( ) ) # initialize with a blank tilegrid placeholder for background - self._padding_top = padding_top - self._padding_bottom = padding_bottom - self._padding_left = padding_left - self._padding_right = padding_right + self._padding = (padding_left, padding_top, padding_right, padding_bottom) + # self._padding_top = padding_top + # self._padding_bottom = padding_bottom + # self._padding_left = padding_left + # self._padding_right = padding_right if text is not None: self._update_text(str(text)) def _create_background_box(self, lines, y_offset): + left = self._boundingbox[0] + if self._background_tight: # draw a tight bounding box box_width = self._boundingbox[2] box_height = self._boundingbox[3] x_box_offset = 0 - y_box_offset = self._bounding_box[1] - left = self._bounding_box[0] + y_box_offset = self._boundingbox[1] else: # draw a "loose" bounding box to include any ascenders/descenders. @@ -145,15 +147,17 @@ def _create_background_box(self, lines, y_offset): ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) descender_max = max(descender_max, -this_glyph.dy) - box_width = self._boundingbox[2] + self._padding_left + self._padding_right - x_box_offset = -self._padding_left + box_width = ( + self._boundingbox[2] + self._padding[0] + self._padding[3] + ) # left + right padding + x_box_offset = -self._padding[0] # left padding box_height = ( (ascender_max + descender_max) + int((lines - 1) * self.height * self._line_spacing) - + self._padding_top - + self._padding_bottom + + self._padding[1] # top padding + + self._padding[2] # bottom padding ) - y_box_offset = -ascender_max + y_offset - self._padding_top + y_box_offset = -ascender_max + y_offset - self._padding[1] # top padding self._update_background_color(self._background_color) box_width = max(0, box_width) # remove any negative values From b49ec93f37894019fa2db658e023b3f2a6b1f5b5 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:53:54 -0500 Subject: [PATCH 15/21] checking the impact of variables on pylint error --- adafruit_display_text/label.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index c1b8fa9..cd739d1 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -116,10 +116,10 @@ def __init__( ) # initialize with a blank tilegrid placeholder for background self._padding = (padding_left, padding_top, padding_right, padding_bottom) - # self._padding_top = padding_top - # self._padding_bottom = padding_bottom - # self._padding_left = padding_left - # self._padding_right = padding_right + self._padding_top = padding_top + self._padding_bottom = padding_bottom + self._padding_left = padding_left + self._padding_right = padding_right if text is not None: self._update_text(str(text)) From dcd466207c85ca0ebd63cd973b3e1f8f7f4fb3e7 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 18:59:39 -0500 Subject: [PATCH 16/21] eliminated a local variable 'bounds' --- adafruit_display_text/label.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index cd739d1..f0fe6d7 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -99,8 +99,8 @@ def __init__( self._background_color = background_color - bounds = self._font.get_bounding_box() - self.height = bounds[1] + #bounds = self._font.get_bounding_box() + self.height = self._font.get_bounding_box()[1] self._line_spacing = line_spacing self._boundingbox = None @@ -115,7 +115,6 @@ def __init__( ) ) # initialize with a blank tilegrid placeholder for background - self._padding = (padding_left, padding_top, padding_right, padding_bottom) self._padding_top = padding_top self._padding_bottom = padding_bottom self._padding_left = padding_left @@ -148,16 +147,16 @@ def _create_background_box(self, lines, y_offset): descender_max = max(descender_max, -this_glyph.dy) box_width = ( - self._boundingbox[2] + self._padding[0] + self._padding[3] + self._boundingbox[2] + self._padding_left + self._padding_right ) # left + right padding - x_box_offset = -self._padding[0] # left padding + x_box_offset = -self._padding_left box_height = ( (ascender_max + descender_max) + int((lines - 1) * self.height * self._line_spacing) - + self._padding[1] # top padding - + self._padding[2] # bottom padding + + self._padding_top + + self._padding_bottom ) - y_box_offset = -ascender_max + y_offset - self._padding[1] # top padding + y_box_offset = -ascender_max + y_offset - self._padding_top self._update_background_color(self._background_color) box_width = max(0, box_width) # remove any negative values @@ -369,8 +368,8 @@ def font(self, new_font): current_anchored_position = self.anchored_position self._text = "" self._font = new_font - bounds = self._font.get_bounding_box() - self.height = bounds[1] + #bounds = self._font.get_bounding_box() + self.height = self._font.get_bounding_box()[1] self._update_text(str(old_text)) self.anchored_position = current_anchored_position From f8c69dbe6b6cbdf40ad894d0ea79c9a098f2ff5f Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 19:06:09 -0500 Subject: [PATCH 17/21] ran black for formatting --- adafruit_display_text/label.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index f0fe6d7..0c0a1de 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -99,7 +99,7 @@ def __init__( self._background_color = background_color - #bounds = self._font.get_bounding_box() + # bounds = self._font.get_bounding_box() self.height = self._font.get_bounding_box()[1] self._line_spacing = line_spacing self._boundingbox = None @@ -149,11 +149,11 @@ def _create_background_box(self, lines, y_offset): box_width = ( self._boundingbox[2] + self._padding_left + self._padding_right ) # left + right padding - x_box_offset = -self._padding_left + x_box_offset = -self._padding_left box_height = ( (ascender_max + descender_max) + int((lines - 1) * self.height * self._line_spacing) - + self._padding_top + + self._padding_top + self._padding_bottom ) y_box_offset = -ascender_max + y_offset - self._padding_top @@ -368,7 +368,7 @@ def font(self, new_font): current_anchored_position = self.anchored_position self._text = "" self._font = new_font - #bounds = self._font.get_bounding_box() + # bounds = self._font.get_bounding_box() self.height = self._font.get_bounding_box()[1] self._update_text(str(old_text)) self.anchored_position = current_anchored_position From 2efbd77eddedcc1ae27f721088f31825b71a882c Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 20:24:03 -0500 Subject: [PATCH 18/21] removed comments and re-ran black --- adafruit_display_text/label.py | 57 +++------------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/adafruit_display_text/label.py b/adafruit_display_text/label.py index 0c0a1de..0fa4861 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -97,17 +97,15 @@ def __init__( self.palette.make_transparent(0) self.palette[1] = color - self._background_color = background_color - - # bounds = self._font.get_bounding_box() self.height = self._font.get_bounding_box()[1] self._line_spacing = line_spacing self._boundingbox = None self._background_tight = ( - background_tight # sets padding status for text background + background_tight # sets padding status for text background box ) + self._background_color = background_color self._background_palette = displayio.Palette(1) self.append( displayio.TileGrid( @@ -146,9 +144,7 @@ def _create_background_box(self, lines, y_offset): ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) descender_max = max(descender_max, -this_glyph.dy) - box_width = ( - self._boundingbox[2] + self._padding_left + self._padding_right - ) # left + right padding + box_width = self._boundingbox[2] + self._padding_left + self._padding_right x_box_offset = -self._padding_left box_height = ( (ascender_max + descender_max) @@ -204,9 +200,7 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals glyph = self._font.get_glyph(ord(character)) if not glyph: continue - right = max( - right, x + glyph.shift_x - ) # studied the docs! This is the correct spacing + right = max(right, x + glyph.shift_x) if y == 0: # first line, find the Ascender height top = min(top, -glyph.height - glyph.dy + y_offset) bottom = max(bottom, y - glyph.dy + y_offset) @@ -267,49 +261,6 @@ def _update_text(self, new_text): # pylint: disable=too-many-locals self.pop() self._text = new_text self._boundingbox = (left, top, left + right, bottom - top) - - # if self._background_tight: # draw a tight bounding box - # box_width = self._boundingbox[2] - # box_height = self._boundingbox[3] - # x_box_offset = 0 - # y_box_offset = top - - # else: # draw a "loose" bounding box to include any ascenders/descenders. - - # # check a few glyphs for maximum ascender and descender height - # # Enhancement: it would be preferred to access the font "FONT_ASCENT" and - # # "FONT_DESCENT" in the imported BDF file - # glyphs = "M j'" # choose glyphs with highest ascender and lowest - # # descender, will depend upon font used - # ascender_max = descender_max = 0 - # for char in glyphs: - # this_glyph = self._font.get_glyph(ord(char)) - # ascender_max = max(ascender_max, this_glyph.height + this_glyph.dy) - # descender_max = max(descender_max, -this_glyph.dy) - - # box_width = self._boundingbox[2] + self._padding_left + self._padding_right - # x_box_offset = -self._padding_left - # box_height = ( - # (ascender_max + descender_max) - # + int((lines - 1) * self.height * self._line_spacing) - # + self._padding_top - # + self._padding_bottom - # ) - # y_box_offset = -ascender_max + y_offset - self._padding_top - - # self._update_background_color(self._background_color) - # box_width = max(0, box_width) # remove any negative values - # box_height = max(0, box_height) # remove any negative values - - # background_bitmap = displayio.Bitmap(box_width, box_height, 1) - # tile_grid = displayio.TileGrid( - # background_bitmap, - # pixel_shader=self._background_palette, - # x=left + x_box_offset, - # y=y_box_offset, - # ) - # self[0] = tile_grid # update the background bitmap in first item of the group - self[0] = self._create_background_box(lines, y_offset) @property From 1be4aa34732b53c6cb696c6dbfff7979d964f973 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 20:58:40 -0500 Subject: [PATCH 19/21] Updated _padding example to meet pylint requirements --- .../display_text_background_color_padding.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/display_text_background_color_padding.py b/examples/display_text_background_color_padding.py index b111e35..3644e30 100755 --- a/examples/display_text_background_color_padding.py +++ b/examples/display_text_background_color_padding.py @@ -4,14 +4,11 @@ import board import displayio import time -import terminalio -import fontio -import sys -import busio # from adafruit_st7789 import ST7789 from adafruit_ili9341 import ILI9341 from adafruit_display_text import label +from adafruit_bitmap_font import bitmap_font # Setup the SPI display @@ -27,7 +24,6 @@ while not spi.try_lock(): spi.configure(baudrate=32000000) - pass spi.unlock() display_bus = displayio.FourWire( @@ -56,9 +52,7 @@ display.show(None) -# font=terminalio.FONT - -from adafruit_bitmap_font import bitmap_font +# font=terminalio.FONT # this is the Builtin fixed dimension font font = bitmap_font.load_font("fonts/BitstreamVeraSans-Roman-24.bdf") @@ -105,9 +99,9 @@ while True: time.sleep(2) - text_area[ - 0 - ].text = "text" # change some text in an existing text box (must fit within existing # of characters) + text_area[0].text = "text" # change some text in an existing text box + # Note: changed text must fit within existing number of characters + # when the Label was created for area in text_area: area.background_color = 0xFF0000 From 93130c4da3cb8ffee09f16f346d1a61c373ba9ca Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 21:01:57 -0500 Subject: [PATCH 20/21] Updated sequence of import statements to meet pyline requirement --- examples/display_text_background_color_padding.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/display_text_background_color_padding.py b/examples/display_text_background_color_padding.py index 3644e30..91b694b 100755 --- a/examples/display_text_background_color_padding.py +++ b/examples/display_text_background_color_padding.py @@ -1,9 +1,10 @@ """ This examples shows the use color and background_color """ +import time import board import displayio -import time + # from adafruit_st7789 import ST7789 from adafruit_ili9341 import ILI9341 From 05bd0ad84223f13464b719e532dbe3a6efc41a2b Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 5 Jun 2020 23:18:18 -0500 Subject: [PATCH 21/21] deleted unnecessary comment --- 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 0fa4861..4546e49 100755 --- a/adafruit_display_text/label.py +++ b/adafruit_display_text/label.py @@ -319,7 +319,6 @@ def font(self, new_font): current_anchored_position = self.anchored_position self._text = "" self._font = new_font - # bounds = self._font.get_bounding_box() self.height = self._font.get_bounding_box()[1] self._update_text(str(old_text)) self.anchored_position = current_anchored_position