Skip to content

Commit bdceacf

Browse files
committed
pylint and pre-commit
1 parent 90e517b commit bdceacf

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

adafruit_display_text/__init__.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,59 @@
77
"""
88

99

10-
def wrap_text_to_pixels(text, max_width, font=None, indent0="", indent1=""):
10+
def wrap_text_to_pixels(string, max_width, font=None, indent0="", indent1=""):
11+
"""wrap_text_to_pixels function
12+
A helper that will return a list of lines with word-break wrapping
13+
14+
:param str string: The text to be wrapped.
15+
:param int max_width: The maximum number of pixels on a line before wrapping.
16+
:param Font font: The font to use for measuring the text.
17+
:param str indent0: Additional character(s) to add to the first line.
18+
:param str indent1: Additional character(s) to add to all other lines.
19+
20+
21+
:return str lines: A string with newlines inserted appropriately to wrap
22+
the input string at the given max_width in pixels
23+
24+
"""
25+
# pylint: disable=too-many-locals too-many-branches
1126
if font is None:
12-
def measure(s):
13-
return len(s)
27+
28+
def measure(string):
29+
return len(string)
30+
1431
else:
15-
if hasattr(font, 'load_glyphs'):
16-
font.load_glyphs(text)
32+
if hasattr(font, "load_glyphs"):
33+
font.load_glyphs(string)
1734

18-
def measure(s):
19-
return sum(font.get_glyph(ord(c)).shift_x for c in s)
35+
def measure(string):
36+
return sum(font.get_glyph(ord(c)).shift_x for c in string)
2037

2138
lines = []
2239
partial = [indent0]
2340
width = measure(indent0)
24-
swidth = measure(' ')
41+
swidth = measure(" ")
2542
firstword = True
26-
for word in text.split():
43+
for word in string.split():
2744
# TODO: split words that are larger than max_width
2845
wwidth = measure(word)
2946
print("{} - {}".format(word, wwidth))
30-
part_width = 0
3147
word_parts = []
3248
cur_part = ""
3349
if wwidth > max_width:
3450
if partial:
3551
lines.append("".join(partial))
3652
partial = []
3753
for char in word:
38-
#print(measure(cur_part) + measure(char) + measure("-"))
54+
# print(measure(cur_part) + measure(char) + measure("-"))
3955
if measure(cur_part) + measure(char) + measure("-") > max_width:
4056
word_parts.append(cur_part + "-")
4157
cur_part = char
4258
else:
4359
cur_part += char
4460
if cur_part:
4561
word_parts.append(cur_part)
46-
#print(word_parts)
62+
# print(word_parts)
4763
for line in word_parts[:-1]:
4864
lines.append(line)
4965
partial.append(word_parts[-1])
@@ -71,6 +87,7 @@ def measure(s):
7187
lines.append("".join(partial))
7288
return "\n".join(lines)
7389

90+
7491
def wrap_text_to_lines(string, max_chars):
7592
"""wrap_text_to_lines function
7693
A helper that will return a list of lines with word-break wrapping

0 commit comments

Comments
 (0)