|
22 | 22 | https://github.com/adafruit/circuitpython/releases |
23 | 23 |
|
24 | 24 | """ |
25 | | - |
| 25 | +try: |
| 26 | + from typing import Tuple |
| 27 | +except: |
| 28 | + pass |
26 | 29 | import displayio |
27 | 30 |
|
28 | 31 | __version__ = "0.0.0-auto.0" |
@@ -80,7 +83,7 @@ class Label(LabelBase): |
80 | 83 | # Note: max_glyphs parameter is unnecessary, this is used for direct |
81 | 84 | # compatibility with label.py |
82 | 85 |
|
83 | | - def __init__(self, font, **kwargs): |
| 86 | + def __init__(self, font, **kwargs) -> None: |
84 | 87 |
|
85 | 88 | super().__init__(font, **kwargs) |
86 | 89 |
|
@@ -126,22 +129,22 @@ def __init__(self, font, **kwargs): |
126 | 129 | def _reset_text( |
127 | 130 | self, |
128 | 131 | 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: |
145 | 148 |
|
146 | 149 | # Store all the instance variables |
147 | 150 | if font is not None: |
@@ -288,12 +291,14 @@ def _reset_text( |
288 | 291 | # x,y positions of the label |
289 | 292 |
|
290 | 293 | @staticmethod |
291 | | - def _line_spacing_ypixels(font, line_spacing): |
| 294 | + def _line_spacing_ypixels(font, line_spacing: float) -> int: |
292 | 295 | # Note: Scaling is provided at the Group level |
293 | 296 | return_value = int(line_spacing * font.get_bounding_box()[1]) |
294 | 297 | return return_value |
295 | 298 |
|
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]: |
297 | 302 | ascender_max, descender_max = self._get_ascent_descent() |
298 | 303 |
|
299 | 304 | lines = 1 |
@@ -371,17 +376,17 @@ def _text_bounding_box(self, text, font, line_spacing): |
371 | 376 | def _place_text( |
372 | 377 | self, |
373 | 378 | bitmap, |
374 | | - text, |
| 379 | + text: str, |
375 | 380 | 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 |
382 | 387 | # when copying glyph bitmaps (this is important for slanted text |
383 | 388 | # where rectangulary glyph boxes overlap) |
384 | | - ): |
| 389 | + ) -> Tuple[int, int, int, int]: |
385 | 390 | # placeText - Writes text into a bitmap at the specified location. |
386 | 391 | # |
387 | 392 | # Note: scale is pushed up to Group level |
@@ -469,16 +474,16 @@ def _place_text( |
469 | 474 | def _blit( |
470 | 475 | self, |
471 | 476 | 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 |
474 | 479 | 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 |
480 | 485 | # (for example: the background color of a glyph) |
481 | | - ): |
| 486 | + ) -> None: |
482 | 487 |
|
483 | 488 | if hasattr(bitmap, "blit"): # if bitmap has a built-in blit function, call it |
484 | 489 | # this function should perform its own input checks |
@@ -538,19 +543,19 @@ def _blit( |
538 | 543 | elif y_placement > bitmap.height: |
539 | 544 | break |
540 | 545 |
|
541 | | - def _set_line_spacing(self, new_line_spacing): |
| 546 | + def _set_line_spacing(self, new_line_spacing: float) -> None: |
542 | 547 | if self._save_text: |
543 | 548 | self._reset_text(line_spacing=new_line_spacing, scale=self.scale) |
544 | 549 | else: |
545 | 550 | raise RuntimeError("line_spacing is immutable when save_text is False") |
546 | 551 |
|
547 | | - def _set_font(self, new_font): |
| 552 | + def _set_font(self, new_font) -> None: |
548 | 553 | self._font = new_font |
549 | 554 | if self._save_text: |
550 | 555 | self._reset_text(font=new_font, scale=self.scale) |
551 | 556 | else: |
552 | 557 | raise RuntimeError("font is immutable when save_text is False") |
553 | 558 |
|
554 | | - def _set_text(self, new_text, scale): |
| 559 | + def _set_text(self, new_text: str, scale: int) -> None: |
555 | 560 | new_text = self._tab_text.join(new_text.split("\t")) |
556 | 561 | self._reset_text(text=new_text, scale=self.scale) |
0 commit comments