@@ -98,8 +98,8 @@ def __init__(
9898 x = 0 ,
9999 y = 0 ,
100100 text = "" ,
101- max_glyphs = None , # This input parameter is ignored, only present for compatibility
102- # with label.py
101+ max_glyphs = None , # This input parameter is ignored, only present for compatibility
102+ # with label.py
103103 color = 0xFFFFFF ,
104104 background_color = None ,
105105 line_spacing = 1.25 ,
@@ -114,22 +114,31 @@ def __init__(
114114 ** kwargs
115115 ):
116116
117-
118117 # Scale will be passed to Group using kwargs.
119118 if "scale" in kwargs .keys ():
120119 scale = kwargs ["scale" ]
121- kwargs .pop ("scale" ) # Do not change scale of self Group, use this value to set scale of local_group
120+ kwargs .pop (
121+ "scale"
122+ ) # Do not change scale of self Group, use this value to set scale of
123+ # local_group
122124
123125 # instance the Group
124- # self Group will contain a single local_group which contains one TileGrid which contains the text bitmap
126+ # self Group will contain a single local_group which contains one TileGrid which contains
127+ # the text bitmap
125128 super ().__init__ (
126129 max_size = 1 , x = x , y = y , ** kwargs
127130 ) # this will include any arguments, including scale
128131
129- self .local_group = displayio .Group (max_size = 1 , ** kwargs ) # local_group holds the tileGrid and sets the scaling
130- self .append (self .local_group ) # the local_group will always stay in the self Group
132+ self .local_group = displayio .Group (
133+ max_size = 1 , ** kwargs
134+ ) # local_group holds the tileGrid and
135+ # sets the scaling
136+ self .append (
137+ self .local_group
138+ ) # the local_group will always stay in the self Group
131139
132140 self ._font = font
141+ self ._text = text
133142
134143 # Create the two-color palette
135144 self .palette = displayio .Palette (2 )
@@ -140,23 +149,23 @@ def __init__(
140149 self ._anchored_position = anchored_position
141150
142151 # call the text updater with all the arguments.
143- self ._reset_text (font = font ,
144- x = x ,
145- y = y ,
146- text = text ,
147- line_spacing = line_spacing ,
148- background_tight = background_tight ,
149- padding_top = padding_top ,
150- padding_bottom = padding_bottom ,
151- padding_left = padding_left ,
152- padding_right = padding_right ,
153- anchor_point = anchor_point ,
154- anchored_position = anchored_position ,
155- save_text = save_text ,
156- scale = scale ,
157- ** kwargs ,
158- )
159-
152+ self ._reset_text (
153+ font = font ,
154+ x = x ,
155+ y = y ,
156+ text = text ,
157+ line_spacing = line_spacing ,
158+ background_tight = background_tight ,
159+ padding_top = padding_top ,
160+ padding_bottom = padding_bottom ,
161+ padding_left = padding_left ,
162+ padding_right = padding_right ,
163+ anchor_point = anchor_point ,
164+ anchored_position = anchored_position ,
165+ save_text = save_text ,
166+ scale = scale ,
167+ ** kwargs ,
168+ )
160169
161170 def _reset_text (
162171 self ,
@@ -175,7 +184,7 @@ def _reset_text(
175184 save_text = None ,
176185 scale = None ,
177186 ** kwargs
178- ):
187+ ):
179188
180189 # Store all the instance variables
181190 if font is not None :
@@ -202,8 +211,10 @@ def _reset_text(
202211 self ._anchored_position = anchored_position
203212 if save_text is not None :
204213 self ._save_text = save_text
205- if scale is not None : # Scale will be defined in local_group (Note: self should have scale=1)
206- self .scale = scale # call the setter
214+ if (
215+ scale is not None
216+ ): # Scale will be defined in local_group (Note: self should have scale=1)
217+ self .scale = scale # call the setter
207218
208219 # if text is not provided as a parameter (text is None), use the previous value.
209220 if (text is None ) and self ._save_text :
@@ -214,22 +225,23 @@ def _reset_text(
214225 else :
215226 self ._text = None # save a None value since text string is not saved
216227
217-
218228 # Check for empty string
219- if (text == "" ) or (text is None ): # If empty string, just create a zero-sized bounding box and that's it.
229+ if (text == "" ) or (
230+ text is None
231+ ): # If empty string, just create a zero-sized bounding box and that's it.
220232
221233 self ._bounding_box = (
222- 0 ,
223- 0 ,
224- 0 , # zero width with text == ""
225- 0 , # zero height with text == ""
226- )
234+ 0 ,
235+ 0 ,
236+ 0 , # zero width with text == ""
237+ 0 , # zero height with text == ""
238+ )
227239 # Clear out any items in the self Group, in case this is an update to the bitmap_label
228- for item in self :
240+ for _ in self :
229241 self .pop (0 )
230242
231- else : # The text string is not empty, so create the Bitmap and TileGrid and append to the self Group
232-
243+ else : # The text string is not empty, so create the Bitmap and TileGrid and
244+ # append to the self Group
233245
234246 # Calculate the text bounding box
235247
@@ -241,19 +253,19 @@ def _reset_text(
241253 x_offset ,
242254 tight_y_offset ,
243255 loose_box_y ,
244- loose_y_offset
256+ loose_y_offset ,
245257 ) = self ._text_bounding_box (
246258 text , self ._font , self ._line_spacing ,
247- ) # calculate the box size for a tight and loose backgrounds
259+ ) # calculate the box size for a tight and loose backgrounds
248260
249- if self ._background_tight :
261+ if self ._background_tight :
250262 box_y = tight_box_y
251263 y_offset = tight_y_offset
252264
253- else : # calculate the box size for a loose background
265+ else : # calculate the box size for a loose background
254266 box_y = loose_box_y
255267 y_offset = loose_y_offset
256-
268+
257269 # Calculate the background size including padding
258270 box_x = box_x + self ._padding_left + self ._padding_right
259271 box_y = box_y + self ._padding_top + self ._padding_bottom
@@ -287,10 +299,13 @@ def _reset_text(
287299 y = label_position_yoffset - y_offset - self ._padding_top ,
288300 )
289301
290- # Clear out any items in the local_group Group, in case this is an update to the bitmap_label
291- for item in self .local_group :
302+ # Clear out any items in the local_group Group, in case this is an update to
303+ # the bitmap_label
304+ for _ in self .local_group :
292305 self .local_group .pop (0 )
293- self .local_group .append (self .tilegrid ) # add the bitmap's tilegrid to the group
306+ self .local_group .append (
307+ self .tilegrid
308+ ) # add the bitmap's tilegrid to the group
294309
295310 # Update bounding_box values. Note: To be consistent with label.py,
296311 # this is the bounding box for the text only, not including the background.
@@ -303,7 +318,8 @@ def _reset_text(
303318
304319 self .anchored_position = (
305320 self ._anchored_position
306- ) # set the anchored_position with setter after bitmap is created, sets the x,y positions of the label
321+ ) # set the anchored_position with setter after bitmap is created, sets the
322+ # x,y positions of the label
307323
308324 @staticmethod
309325 def _line_spacing_ypixels (font , line_spacing ):
@@ -383,18 +399,24 @@ def _text_bounding_box(self, text, font, line_spacing):
383399
384400 final_box_width = right - left
385401
386-
387402 final_box_height_tight = bottom - top
388403 final_y_offset_tight = - top + y_offset_tight
389404
390405 final_box_height_loose = (lines - 1 ) * self ._line_spacing_ypixels (
391- font , line_spacing
392- ) + (ascender_max + descender_max )
406+ font , line_spacing
407+ ) + (ascender_max + descender_max )
393408 final_y_offset_loose = ascender_max
394409
395410 # return (final_box_width, final_box_height, left, final_y_offset)
396411
397- return (final_box_width , final_box_height_tight , left , final_y_offset_tight , final_box_height_loose , final_y_offset_loose )
412+ return (
413+ final_box_width ,
414+ final_box_height_tight ,
415+ left ,
416+ final_y_offset_tight ,
417+ final_box_height_loose ,
418+ final_y_offset_loose ,
419+ )
398420
399421 # pylint: disable=too-many-nested-blocks
400422 def _place_text (
@@ -459,7 +481,7 @@ def _place_text(
459481 glyph_offset_x = (
460482 my_glyph .tile_index * my_glyph .width
461483 ) # for type BuiltinFont, this creates the x-offset in the glyph bitmap.
462- # for BDF loaded fonts, this should equal 0
484+ # for BDF loaded fonts, this should equal 0
463485
464486 try :
465487 bitmap .blit (
@@ -470,14 +492,16 @@ def _place_text(
470492 y1 = 0 ,
471493 x2 = glyph_offset_x + my_glyph .width ,
472494 y2 = 0 + my_glyph .height ,
473- skip_index = 0 , # do not copy over any 0 background pixels
495+ skip_index = 0 , # do not copy over any 0 background pixels
474496 )
475497
476498 except :
477499 for y in range (my_glyph .height ):
478500 for x in range (my_glyph .width ):
479501 x_placement = x + xposition + my_glyph .dx
480- y_placement = y + yposition - my_glyph .height - my_glyph .dy
502+ y_placement = (
503+ y + yposition - my_glyph .height - my_glyph .dy
504+ )
481505
482506 if (bitmap_width > x_placement >= 0 ) and (
483507 bitmap_height > y_placement >= 0
@@ -492,7 +516,9 @@ def _place_text(
492516
493517 this_pixel_color = palette_indexes [
494518 my_glyph .bitmap [
495- y * my_glyph .bitmap .width + x + glyph_offset_x
519+ y * my_glyph .bitmap .width
520+ + x
521+ + glyph_offset_x
496522 ]
497523 ]
498524
@@ -519,12 +545,12 @@ def bounding_box(self):
519545 def scale (self ):
520546 """Set the scaling of the label"""
521547 return self ._scale
522-
548+
523549 @scale .setter
524550 def scale (self , new_scale ):
525- self .local_group .scale = new_scale
526- self ._scale = new_scale
527- self .anchored_position = self ._anchored_position # update the anchored_position
551+ self .local_group .scale = new_scale
552+ self ._scale = new_scale
553+ self .anchored_position = self ._anchored_position # update the anchored_position
528554
529555 @property
530556 def line_spacing (self ):
@@ -539,7 +565,6 @@ def line_spacing(self, new_line_spacing):
539565 else :
540566 raise RuntimeError ("line_spacing is immutable when save_text is False" )
541567
542-
543568 @property
544569 def color (self ):
545570 """Color of the text as an RGB hex number."""
@@ -575,17 +600,18 @@ def text(self):
575600 """Text to displayed."""
576601 return self ._text
577602
578- @text .setter # Cannot set color or background color with text setter, use separate setter
603+ @text .setter # Cannot set color or background color with text setter, use separate setter
579604 def text (self , new_text ):
580605 self ._reset_text (text = new_text )
581606
582607 @property
583608 def font (self ):
584609 """Font to use for text display."""
585- return self .font
610+ return self ._font
586611
587612 @font .setter
588613 def font (self , new_font ):
614+ self ._font = new_font
589615 if self ._save_text :
590616 self ._reset_text (font = new_font )
591617 else :
0 commit comments