47
47
print ("Warning: adafruit_bitmap_font not found. No support for custom fonts." )
48
48
CUSTOM_FONTS = False
49
49
50
+ try :
51
+ from typing import Optional
52
+ from pwmio import PWMOut
53
+ except ImportError :
54
+ pass
55
+
50
56
__version__ = "0.0.0-auto.0"
51
57
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
52
58
@@ -100,6 +106,8 @@ class SlideShow:
100
106
"""
101
107
Class for displaying a slideshow of .bmp images on displays.
102
108
109
+ :param displayio.Display display: The display to use
110
+ :param PWMOut backlight_pwm: The PWMOut object used for the backlight
103
111
:param str folder: Specify the folder containing the image files, in quotes. Default is
104
112
the root directory, ``"/"``.
105
113
@@ -179,20 +187,20 @@ class SlideShow:
179
187
180
188
def __init__ (
181
189
self ,
182
- display ,
183
- backlight_pwm = None ,
190
+ display : displayio . Display ,
191
+ backlight_pwm : Optional [ PWMOut ] = None ,
184
192
* ,
185
- folder = "/" ,
186
- order = PlayBackOrder .ALPHABETICAL ,
187
- loop = True ,
188
- dwell = 3 ,
189
- fade_effect = True ,
190
- auto_advance = True ,
191
- direction = PlayBackDirection .FORWARD ,
192
- h_align = HorizontalAlignment .LEFT ,
193
- v_align = VerticalAlignment .TOP ,
194
- ):
195
- def _check_json_file (file ) :
193
+ folder : str = "/" ,
194
+ order : int = PlayBackOrder .ALPHABETICAL ,
195
+ loop : bool = True ,
196
+ dwell : int = 3 ,
197
+ fade_effect : bool = True ,
198
+ auto_advance : bool = True ,
199
+ direction : int = PlayBackDirection .FORWARD ,
200
+ h_align : int = HorizontalAlignment .LEFT ,
201
+ v_align : int = VerticalAlignment .TOP ,
202
+ ) -> None :
203
+ def _check_json_file (file : str ) -> bool :
196
204
if TEXT_SLIDES_ENABLED :
197
205
if file .endswith (".json" ):
198
206
with open (file ) as _file_obj :
@@ -264,31 +272,31 @@ def _check_json_file(file):
264
272
self .advance ()
265
273
266
274
@property
267
- def current_slide_name (self ):
275
+ def current_slide_name (self ) -> str :
268
276
"""Returns the current image name."""
269
277
return self ._file_list [self ._current_slide_index ]
270
278
271
279
@property
272
- def order (self ):
280
+ def order (self ) -> int :
273
281
"""Specifies the order in which the images are displayed. Options are random (``RANDOM``) or
274
282
alphabetical (``ALPHABETICAL``). Default is ``RANDOM``."""
275
283
return self ._order
276
284
277
285
@order .setter
278
- def order (self , order ) :
286
+ def order (self , order : int ) -> None :
279
287
if order not in [PlayBackOrder .ALPHABETICAL , PlayBackOrder .RANDOM ]:
280
288
raise ValueError ("Order must be either 'RANDOM' or 'ALPHABETICAL'" )
281
289
282
290
self ._order = order
283
291
self ._reorder_slides ()
284
292
285
- def _reorder_slides (self ):
293
+ def _reorder_slides (self ) -> None :
286
294
if self .order == PlayBackOrder .ALPHABETICAL :
287
295
self ._file_list = sorted (self ._file_list )
288
296
elif self .order == PlayBackOrder .RANDOM :
289
297
self ._file_list = sorted (self ._file_list , key = lambda x : random .random ())
290
298
291
- def _set_backlight (self , brightness ) :
299
+ def _set_backlight (self , brightness : float ) -> None :
292
300
if self ._backlight_pwm :
293
301
full_brightness = 2 ** 16 - 1
294
302
self ._backlight_pwm .duty_cycle = int (full_brightness * brightness )
@@ -299,20 +307,20 @@ def _set_backlight(self, brightness):
299
307
pass
300
308
301
309
@property
302
- def brightness (self ):
310
+ def brightness (self ) -> float :
303
311
"""Brightness of the backlight when an image is displaying. Clamps to 0 to 1.0"""
304
312
return self ._brightness
305
313
306
314
@brightness .setter
307
- def brightness (self , brightness ) :
315
+ def brightness (self , brightness : float ) -> None :
308
316
if brightness < 0 :
309
317
brightness = 0
310
318
elif brightness > 1.0 :
311
319
brightness = 1.0
312
320
self ._brightness = brightness
313
321
self ._set_backlight (brightness )
314
322
315
- def _fade_up (self ):
323
+ def _fade_up (self ) -> None :
316
324
if not self .fade_effect :
317
325
self ._set_backlight (self .brightness )
318
326
return
@@ -321,7 +329,7 @@ def _fade_up(self):
321
329
self ._set_backlight (self .brightness * i / steps )
322
330
time .sleep (0.01 )
323
331
324
- def _fade_down (self ):
332
+ def _fade_down (self ) -> None :
325
333
if not self .fade_effect :
326
334
self ._set_backlight (self .brightness )
327
335
return
@@ -330,7 +338,7 @@ def _fade_down(self):
330
338
self ._set_backlight (self .brightness * i / steps )
331
339
time .sleep (0.01 )
332
340
333
- def _create_label (self , file_name ) :
341
+ def _create_label (self , file_name : str ) -> bitmap_label . Label :
334
342
# pylint: disable=too-many-branches
335
343
"""Creates and returns a label from a file object that contains
336
344
valid valid json describing the text to use.
@@ -389,15 +397,15 @@ def _create_label(self, file_name):
389
397
label .anchored_position = (x_anchored_position , y_anchored_position )
390
398
return label
391
399
392
- def update (self ):
400
+ def update (self ) -> bool :
393
401
"""Updates the slideshow to the next image."""
394
402
now = time .monotonic ()
395
403
if not self .auto_advance or now - self ._img_start < self .dwell :
396
404
return True
397
405
return self .advance ()
398
406
399
407
# pylint: disable=too-many-branches, too-many-statements
400
- def advance (self ):
408
+ def advance (self ) -> bool :
401
409
"""Displays the next image. Returns True when a new image was displayed, False otherwise."""
402
410
if self ._file_name :
403
411
self ._fade_down ()
@@ -472,12 +480,12 @@ def advance(self):
472
480
# pylint: enable=too-many-branches
473
481
474
482
@property
475
- def h_align (self ):
483
+ def h_align (self ) -> int :
476
484
"""Get or Set the Horizontal Alignment"""
477
485
return self ._h_align
478
486
479
487
@h_align .setter
480
- def h_align (self , val ) :
488
+ def h_align (self , val : int ) -> None :
481
489
if val not in (
482
490
HorizontalAlignment .LEFT ,
483
491
HorizontalAlignment .CENTER ,
@@ -487,12 +495,12 @@ def h_align(self, val):
487
495
self ._h_align = val
488
496
489
497
@property
490
- def v_align (self ):
498
+ def v_align (self ) -> int :
491
499
"""Get or Set the Vertical Alignment"""
492
500
return self ._v_align
493
501
494
502
@v_align .setter
495
- def v_align (self , val ) :
503
+ def v_align (self , val : int ) -> None :
496
504
if val not in (
497
505
VerticalAlignment .TOP ,
498
506
VerticalAlignment .CENTER ,
0 commit comments