21
21
https://github.com/adafruit/circuitpython/releases
22
22
23
23
"""
24
-
24
+ from typing import Tuple
25
25
import displayio
26
26
27
27
__version__ = "0.0.0-auto.0"
@@ -70,24 +70,24 @@ def __init__(
70
70
self ,
71
71
font ,
72
72
* ,
73
- x = 0 ,
74
- y = 0 ,
75
- text = "" ,
76
- max_glyphs = None ,
77
- color = 0xFFFFFF ,
78
- background_color = None ,
79
- line_spacing = 1.25 ,
80
- background_tight = False ,
81
- padding_top = 0 ,
82
- padding_bottom = 0 ,
83
- padding_left = 0 ,
84
- padding_right = 0 ,
85
- anchor_point = None ,
86
- anchored_position = None ,
87
- scale = 1 ,
88
- base_alignment = False ,
73
+ x : int = 0 ,
74
+ y : int = 0 ,
75
+ text : str = "" ,
76
+ max_glyphs : int = None ,
77
+ color : int = 0xFFFFFF ,
78
+ background_color : int = None ,
79
+ line_spacing : float = 1.25 ,
80
+ background_tight : bool = False ,
81
+ padding_top : int = 0 ,
82
+ padding_bottom : int = 0 ,
83
+ padding_left : int = 0 ,
84
+ padding_right : int = 0 ,
85
+ anchor_point : Tuple [ float , float ] = None ,
86
+ anchored_position : Tuple [ int , int ] = None ,
87
+ scale : int = 1 ,
88
+ base_alignment : bool = False ,
89
89
** kwargs
90
- ):
90
+ ) -> None :
91
91
if not max_glyphs and not text :
92
92
raise RuntimeError ("Please provide a max size, or initial text" )
93
93
text = " " .join (text .split ("\t " ))
@@ -140,7 +140,7 @@ def __init__(
140
140
if (anchored_position is not None ) and (anchor_point is not None ):
141
141
self .anchored_position = anchored_position
142
142
143
- def _create_background_box (self , lines , y_offset ):
143
+ def _create_background_box (self , lines : int , y_offset : int ):
144
144
"""Private Class function to create a background_box
145
145
:param lines: int number of lines
146
146
:param y_offset: int y pixel bottom coordinate for the background_box"""
@@ -182,7 +182,7 @@ def _create_background_box(self, lines, y_offset):
182
182
183
183
return tile_grid
184
184
185
- def _get_ascent_descent (self ):
185
+ def _get_ascent_descent (self ) -> Tuple [ int , int ] :
186
186
""" Private function to calculate ascent and descent font values """
187
187
if hasattr (self .font , "ascent" ):
188
188
return self .font .ascent , self .font .descent
@@ -203,10 +203,10 @@ def _get_ascent_descent(self):
203
203
descender_max = max (descender_max , - this_glyph .dy )
204
204
return ascender_max , descender_max
205
205
206
- def _get_ascent (self ):
206
+ def _get_ascent (self ) -> int :
207
207
return self ._get_ascent_descent ()[0 ]
208
208
209
- def _update_background_color (self , new_color ) :
209
+ def _update_background_color (self , new_color : int ) -> None :
210
210
"""Private class function that allows updating the font box background color
211
211
:param new_color: int color as an RGB hex number."""
212
212
@@ -261,9 +261,8 @@ def _update_background_color(self, new_color):
261
261
self .local_group .pop (0 )
262
262
self ._added_background_tilegrid = False
263
263
264
- def _update_text (
265
- self , new_text
266
- ): # pylint: disable=too-many-locals ,too-many-branches, too-many-statements
264
+ def _update_text (self , new_text : str ) -> None :
265
+ # pylint: disable=too-many-locals ,too-many-branches, too-many-statements
267
266
x = 0
268
267
y = 0
269
268
if self ._added_background_tilegrid :
@@ -340,19 +339,19 @@ def _update_text(
340
339
self ._update_background_color (self ._background_color )
341
340
342
341
@property
343
- def bounding_box (self ):
342
+ def bounding_box (self ) -> Tuple [ int , int , int , int ] :
344
343
"""An (x, y, w, h) tuple that completely covers all glyphs. The
345
344
first two numbers are offset from the x, y origin of this group"""
346
345
return tuple (self ._boundingbox )
347
346
348
347
@property
349
- def line_spacing (self ):
348
+ def line_spacing (self ) -> float :
350
349
"""The amount of space between lines of text, in multiples of the font's
351
350
bounding-box height. (E.g. 1.0 is the bounding-box height)"""
352
351
return self ._line_spacing
353
352
354
353
@line_spacing .setter
355
- def line_spacing (self , spacing ) :
354
+ def line_spacing (self , spacing : float ) -> None :
356
355
self ._line_spacing = spacing
357
356
self .text = self ._text # redraw the box
358
357
@@ -362,7 +361,7 @@ def color(self):
362
361
return self .palette [1 ]
363
362
364
363
@color .setter
365
- def color (self , new_color ) :
364
+ def color (self , new_color : int ) -> None :
366
365
self ._color = new_color
367
366
if new_color is not None :
368
367
self .palette [1 ] = new_color
@@ -372,21 +371,21 @@ def color(self, new_color):
372
371
self .palette .make_transparent (1 )
373
372
374
373
@property
375
- def background_color (self ):
374
+ def background_color (self ) -> int :
376
375
"""Color of the background as an RGB hex number."""
377
376
return self ._background_color
378
377
379
378
@background_color .setter
380
- def background_color (self , new_color ) :
379
+ def background_color (self , new_color : int ) -> None :
381
380
self ._update_background_color (new_color )
382
381
383
382
@property
384
- def text (self ):
383
+ def text (self ) -> str :
385
384
"""Text to display."""
386
385
return self ._text
387
386
388
387
@text .setter
389
- def text (self , new_text ) :
388
+ def text (self , new_text : str ) -> None :
390
389
new_text = " " .join (new_text .split ("\t " ))
391
390
try :
392
391
current_anchored_position = self .anchored_position
@@ -396,12 +395,12 @@ def text(self, new_text):
396
395
raise RuntimeError ("Text length exceeds max_glyphs" ) from run_error
397
396
398
397
@property
399
- def scale (self ):
398
+ def scale (self ) -> int :
400
399
"""Set the scaling of the label, in integer values"""
401
400
return self .local_group .scale
402
401
403
402
@scale .setter
404
- def scale (self , new_scale ) :
403
+ def scale (self , new_scale : int ) -> None :
405
404
current_anchored_position = self .anchored_position
406
405
self .local_group .scale = new_scale
407
406
self .anchored_position = current_anchored_position
@@ -412,7 +411,7 @@ def font(self):
412
411
return self ._font
413
412
414
413
@font .setter
415
- def font (self , new_font ):
414
+ def font (self , new_font ) -> None :
416
415
old_text = self ._text
417
416
current_anchored_position = self .anchored_position
418
417
self ._text = ""
@@ -422,14 +421,14 @@ def font(self, new_font):
422
421
self .anchored_position = current_anchored_position
423
422
424
423
@property
425
- def anchor_point (self ):
424
+ def anchor_point (self ) -> Tuple [ float , float ] :
426
425
"""Point that anchored_position moves relative to.
427
426
Tuple with decimal percentage of width and height.
428
427
(E.g. (0,0) is top left, (1.0, 0.5): is middle right.)"""
429
428
return self ._anchor_point
430
429
431
430
@anchor_point .setter
432
- def anchor_point (self , new_anchor_point ) :
431
+ def anchor_point (self , new_anchor_point : Tuple [ float , float ]) -> None :
433
432
if self ._anchor_point is not None :
434
433
current_anchored_position = self .anchored_position
435
434
self ._anchor_point = new_anchor_point
@@ -438,7 +437,7 @@ def anchor_point(self, new_anchor_point):
438
437
self ._anchor_point = new_anchor_point
439
438
440
439
@property
441
- def anchored_position (self ):
440
+ def anchored_position (self ) -> Tuple [ int , int ] :
442
441
"""Position relative to the anchor_point. Tuple containing x,y
443
442
pixel coordinates."""
444
443
if self ._anchor_point is None :
@@ -457,7 +456,7 @@ def anchored_position(self):
457
456
)
458
457
459
458
@anchored_position .setter
460
- def anchored_position (self , new_position ) :
459
+ def anchored_position (self , new_position : Tuple [ int , int ]) -> Tuple [ int , int ] :
461
460
if (self ._anchor_point is None ) or (new_position is None ):
462
461
return # Note: anchor_point must be set before setting anchored_position
463
462
self .x = int (
0 commit comments