Skip to content

Commit 8655012

Browse files
committed
Type Annotations changes
1 parent 33bffb8 commit 8655012

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

adafruit_display_text/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"""
66
Display Text module helper functions
77
"""
8-
from displayio import Group, Palette
98
try:
109
from typing import Tuple
1110
except:
1211
pass
12+
from displayio import Group, Palette
13+
1314

1415
def wrap_text_to_pixels(string, max_width, font=None, indent0="", indent1=""):
1516
"""wrap_text_to_pixels function
@@ -201,7 +202,7 @@ def __init__(
201202
anchor_point: Tuple[float, float] = None,
202203
anchored_position: Tuple[int, int] = None,
203204
save_text: bool = True, # can reduce memory use if save_text = False
204-
scale:int = 1,
205+
scale: int = 1,
205206
base_alignment: bool = False,
206207
tab_replacement: Tuple[int, str] = (4, " "),
207208
**kwargs,

adafruit_display_text/bitmap_label.py

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
https://github.com/adafruit/circuitpython/releases
2323
2424
"""
25-
25+
try:
26+
from typing import Tuple
27+
except:
28+
pass
2629
import displayio
2730

2831
__version__ = "0.0.0-auto.0"
@@ -80,7 +83,7 @@ class Label(LabelBase):
8083
# Note: max_glyphs parameter is unnecessary, this is used for direct
8184
# compatibility with label.py
8285

83-
def __init__(self, font, **kwargs):
86+
def __init__(self, font, **kwargs) -> None:
8487

8588
super().__init__(font, **kwargs)
8689

@@ -126,22 +129,22 @@ def __init__(self, font, **kwargs):
126129
def _reset_text(
127130
self,
128131
font=None,
129-
x=None,
130-
y=None,
131-
text=None,
132-
line_spacing=None,
133-
background_tight=None,
134-
padding_top=None,
135-
padding_bottom=None,
136-
padding_left=None,
137-
padding_right=None,
138-
anchor_point=None,
139-
anchored_position=None,
140-
save_text=None,
141-
scale=None,
142-
base_alignment=None,
143-
tab_replacement=None,
144-
):
132+
x: int = None,
133+
y: int = None,
134+
text: str = None,
135+
line_spacing: float = None,
136+
background_tight: bool = None,
137+
padding_top: int = None,
138+
padding_bottom: int = None,
139+
padding_left: int = None,
140+
padding_right: int = None,
141+
anchor_point: Tuple[float, float] = None,
142+
anchored_position: Tuple[int, int] = None,
143+
save_text: bool = None,
144+
scale: int = None,
145+
base_alignment: bool = None,
146+
tab_replacement: Tuple[int, str] = None,
147+
) -> None:
145148

146149
# Store all the instance variables
147150
if font is not None:
@@ -288,12 +291,14 @@ def _reset_text(
288291
# x,y positions of the label
289292

290293
@staticmethod
291-
def _line_spacing_ypixels(font, line_spacing):
294+
def _line_spacing_ypixels(font, line_spacing: float) -> int:
292295
# Note: Scaling is provided at the Group level
293296
return_value = int(line_spacing * font.get_bounding_box()[1])
294297
return return_value
295298

296-
def _text_bounding_box(self, text, font, line_spacing):
299+
def _text_bounding_box(
300+
self, text: str, font, line_spacing: float
301+
) -> Tuple[int, int, int, int, int, int]:
297302
ascender_max, descender_max = self._get_ascent_descent()
298303

299304
lines = 1
@@ -371,17 +376,17 @@ def _text_bounding_box(self, text, font, line_spacing):
371376
def _place_text(
372377
self,
373378
bitmap,
374-
text,
379+
text: str,
375380
font,
376-
line_spacing,
377-
xposition,
378-
yposition,
379-
text_palette_index=1,
380-
background_palette_index=0,
381-
skip_index=0, # set to None to write all pixels, other wise skip this palette index
381+
line_spacing: float,
382+
xposition: int,
383+
yposition: int,
384+
text_palette_index: int = 1,
385+
background_palette_index: int = 0,
386+
skip_index: int = 0, # set to None to write all pixels, other wise skip this palette index
382387
# when copying glyph bitmaps (this is important for slanted text
383388
# where rectangulary glyph boxes overlap)
384-
):
389+
) -> Tuple[int, int, int, int]:
385390
# placeText - Writes text into a bitmap at the specified location.
386391
#
387392
# Note: scale is pushed up to Group level
@@ -469,16 +474,16 @@ def _place_text(
469474
def _blit(
470475
self,
471476
bitmap, # target bitmap
472-
x, # target x upper left corner
473-
y, # target y upper left corner
477+
x: int, # target x upper left corner
478+
y: int, # target y upper left corner
474479
source_bitmap, # source bitmap
475-
x_1=0, # source x start
476-
y_1=0, # source y start
477-
x_2=None, # source x end
478-
y_2=None, # source y end
479-
skip_index=None, # palette index that will not be copied
480+
x_1: int = 0, # source x start
481+
y_1: int = 0, # source y start
482+
x_2: int = None, # source x end
483+
y_2: int = None, # source y end
484+
skip_index: int = None, # palette index that will not be copied
480485
# (for example: the background color of a glyph)
481-
):
486+
) -> None:
482487

483488
if hasattr(bitmap, "blit"): # if bitmap has a built-in blit function, call it
484489
# this function should perform its own input checks
@@ -538,19 +543,19 @@ def _blit(
538543
elif y_placement > bitmap.height:
539544
break
540545

541-
def _set_line_spacing(self, new_line_spacing):
546+
def _set_line_spacing(self, new_line_spacing: float) -> None:
542547
if self._save_text:
543548
self._reset_text(line_spacing=new_line_spacing, scale=self.scale)
544549
else:
545550
raise RuntimeError("line_spacing is immutable when save_text is False")
546551

547-
def _set_font(self, new_font):
552+
def _set_font(self, new_font) -> None:
548553
self._font = new_font
549554
if self._save_text:
550555
self._reset_text(font=new_font, scale=self.scale)
551556
else:
552557
raise RuntimeError("font is immutable when save_text is False")
553558

554-
def _set_text(self, new_text, scale):
559+
def _set_text(self, new_text: str, scale: int) -> None:
555560
new_text = self._tab_text.join(new_text.split("\t"))
556561
self._reset_text(text=new_text, scale=self.scale)

adafruit_display_text/label.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
"""
2424

2525
import displayio
26-
try:
27-
from typing import Tuple
28-
except:
29-
pass
3026

3127
__version__ = "0.0.0-auto.0"
3228
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

0 commit comments

Comments
 (0)