Skip to content

Commit 9640d00

Browse files
author
Margaret Matocha
committed
Removed unnecessary comments and ran black
1 parent 8a16497 commit 9640d00

File tree

1 file changed

+37
-58
lines changed

1 file changed

+37
-58
lines changed

adafruit_display_text/bitmap_label.py

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,32 @@ def text_bounding_box(
7878
font_height = ascender_max + descender_max
7979
font_yoffset = ascender_max
8080

81-
8281
lines = 1
8382

8483
font_height = font.get_glyph(ord("M")).height
8584

86-
8785
xposition = x_start = 0 # starting x position (left margin)
8886
yposition = y_start = 0
8987

9088
left = right = x_start
9189
top = bottom = y_start
9290

93-
94-
y_offset_tight = int(( font.get_glyph(ord("M")).height - text.count("\n") *line_spacing_ypixels(font, line_spacing)
91+
y_offset_tight = int(
92+
(
93+
font.get_glyph(ord("M")).height
94+
- text.count("\n") * line_spacing_ypixels(font, line_spacing)
95+
)
96+
/ 2
9597
)
96-
/ 2)
97-
# this needs to be reviewed (also in label.py), since it doesn't respond
98+
# this needs to be reviewed (also in label.py), since it doesn't respond
9899
# properly to the number of newlines.
99100

100-
newline=False
101+
newline = False
101102

102103
for char in text:
103104

104105
if char == "\n": # newline
105-
newline=True
106+
newline = True
106107

107108
else:
108109

@@ -112,49 +113,43 @@ def text_bounding_box(
112113
print("Glyph not found: {}".format(repr(char)))
113114
else:
114115
if newline:
115-
newline=False
116+
newline = False
116117
xposition = x_start # reset to left column
117118
yposition = yposition + line_spacing_ypixels(
118-
font, line_spacing
119-
) # Add a newline
119+
font, line_spacing
120+
) # Add a newline
120121
lines += 1
121122
xposition += my_glyph.shift_x
122123
right = max(right, xposition)
123124

124125
if yposition == y_start: # first line, find the Ascender height
125-
top = min(top, - my_glyph.height - my_glyph.dy + y_offset_tight)
126+
top = min(top, -my_glyph.height - my_glyph.dy + y_offset_tight)
126127
bottom = max(bottom, yposition - my_glyph.dy + y_offset_tight)
127128

128-
# width = my_glyph.width
129-
# height = my_glyph.height
130-
# dx = my_glyph.dx
131-
# dy = my_glyph.dy
132-
# shift_x = my_glyph.shift_x
133-
# shift_y = my_glyph.shift_x
134-
135-
136-
loose_height= (lines - 1) * line_spacing_ypixels(font, line_spacing) + (ascender_max + descender_max)
137-
138-
139-
140-
label_calibration_offset=int(( font.get_glyph(ord("M")).height - text.count("\n") *line_spacing_ypixels(font, line_spacing)
129+
loose_height = (lines - 1) * line_spacing_ypixels(font, line_spacing) + (
130+
ascender_max + descender_max
141131
)
142-
/ 2)
143-
144-
y_offset_tight = -top +label_calibration_offset #
145132

133+
label_calibration_offset = int(
134+
(
135+
font.get_glyph(ord("M")).height
136+
- text.count("\n") * line_spacing_ypixels(font, line_spacing)
137+
)
138+
/ 2
139+
)
146140

141+
y_offset_tight = -top + label_calibration_offset
147142

148-
final_box_width=right-left
143+
final_box_width = right - left
149144
if background_tight:
150-
final_box_height=bottom-top
151-
final_y_offset=y_offset_tight
152-
145+
final_box_height = bottom - top
146+
final_y_offset = y_offset_tight
147+
153148
else:
154-
final_box_height=loose_height
155-
final_y_offset=ascender_max
149+
final_box_height = loose_height
150+
final_y_offset = ascender_max
156151

157-
return (final_box_width, final_box_height, 0, final_y_offset) # -x1_min is the x_offset
152+
return (final_box_width, final_box_height, 0, final_y_offset)
158153

159154

160155
def place_text(
@@ -256,13 +251,13 @@ def place_text(
256251

257252
xposition = xposition + shift_x
258253

259-
return (left, top, right-left, bottom - top) # bounding_box
254+
return (left, top, right - left, bottom - top) # bounding_box
260255

261256

262257
class Label(displayio.Group):
263258
# Class variable
264259
# To save memory, set Label._memory_saver=True and avoid storing the text string in the class.
265-
# If set to False, the class saves the text string for future reference. *** use getter
260+
# If set to False, the class saves the text string for future reference.
266261
_memory_saver = True
267262

268263
def __init__(
@@ -302,7 +297,7 @@ def __init__(
302297
else:
303298
self._text = text # text to be displayed
304299

305-
# limit padding to >= 0 *** raise an error if negative padding is requested
300+
# limit padding to >= 0
306301
padding_top = max(0, padding_top)
307302
padding_bottom = max(0, padding_bottom)
308303
padding_left = max(0, padding_left)
@@ -367,7 +362,7 @@ def __init__(
367362
tile_height=box_y,
368363
default_tile=0,
369364
x=-padding_left,
370-
y= label_position_yoffset - y_offset - padding_top,
365+
y=label_position_yoffset - y_offset - padding_top,
371366
)
372367

373368
# instance the Group with super... super().__init__(
@@ -377,32 +372,16 @@ def __init__(
377372
) # this will include any arguments, including scale
378373
self.append(self.tilegrid) # add the bitmap's tilegrid to the group
379374

380-
####### *******
381-
# Set the tileGrid position in the parent based upon anchor_point and anchor_position
382-
# **** Should scale affect the placement of anchor_position?
375+
# Update bounding_box values. Note: To be consistent with label.py,
376+
# this is the bounding box for the text only, not including the background.
383377

384378
self.bounding_box = (
385379
self.tilegrid.x,
386-
#self.tilegrid.y + (y_offset - tight_y_offset),
387-
self.tilegrid.y, #+ (y_offset - tight_y_offset),
380+
self.tilegrid.y,
388381
tight_box_x,
389382
tight_box_y,
390383
)
391384

392-
# self.bounding_box = (
393-
# self.tilegrid.x,
394-
# self.tilegrid.y + (y_offset),
395-
# tight_box_x,
396-
# tight_box_y,
397-
# )
398-
399-
400-
401-
# Update bounding_box values. Note: To be consistent with label.py,
402-
# this is the bounding box for the text only, not including the background.
403-
# ******** Need repair
404-
# Create the TileGrid to hold the single Bitmap (self.bitmap)
405-
406385
self._anchored_position = anchored_position
407386
self.anchor_point = anchor_point
408387
self.anchored_position = (

0 commit comments

Comments
 (0)