4747 print ("Warning: adafruit_bitmap_font not found. No support for custom fonts." )
4848 CUSTOM_FONTS = False
4949
50+ try :
51+ from typing import Optional
52+ from pwmio import PWMOut
53+ except ImportError :
54+ pass
55+
5056__version__ = "0.0.0-auto.0"
5157__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
5258
@@ -100,6 +106,8 @@ class SlideShow:
100106 """
101107 Class for displaying a slideshow of .bmp images on displays.
102108
109+ :param displayio.Display display: The display to use
110+ :param PWMOut backlight_pwm: The PWMOut object used for the backlight
103111 :param str folder: Specify the folder containing the image files, in quotes. Default is
104112 the root directory, ``"/"``.
105113
@@ -179,20 +187,20 @@ class SlideShow:
179187
180188 def __init__ (
181189 self ,
182- display ,
183- backlight_pwm = None ,
190+ display : displayio . Display ,
191+ backlight_pwm : Optional [ PWMOut ] = None ,
184192 * ,
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 :
196204 if TEXT_SLIDES_ENABLED :
197205 if file .endswith (".json" ):
198206 with open (file ) as _file_obj :
@@ -264,31 +272,31 @@ def _check_json_file(file):
264272 self .advance ()
265273
266274 @property
267- def current_slide_name (self ):
275+ def current_slide_name (self ) -> str :
268276 """Returns the current image name."""
269277 return self ._file_list [self ._current_slide_index ]
270278
271279 @property
272- def order (self ):
280+ def order (self ) -> int :
273281 """Specifies the order in which the images are displayed. Options are random (``RANDOM``) or
274282 alphabetical (``ALPHABETICAL``). Default is ``RANDOM``."""
275283 return self ._order
276284
277285 @order .setter
278- def order (self , order ) :
286+ def order (self , order : int ) -> None :
279287 if order not in [PlayBackOrder .ALPHABETICAL , PlayBackOrder .RANDOM ]:
280288 raise ValueError ("Order must be either 'RANDOM' or 'ALPHABETICAL'" )
281289
282290 self ._order = order
283291 self ._reorder_slides ()
284292
285- def _reorder_slides (self ):
293+ def _reorder_slides (self ) -> None :
286294 if self .order == PlayBackOrder .ALPHABETICAL :
287295 self ._file_list = sorted (self ._file_list )
288296 elif self .order == PlayBackOrder .RANDOM :
289297 self ._file_list = sorted (self ._file_list , key = lambda x : random .random ())
290298
291- def _set_backlight (self , brightness ) :
299+ def _set_backlight (self , brightness : float ) -> None :
292300 if self ._backlight_pwm :
293301 full_brightness = 2 ** 16 - 1
294302 self ._backlight_pwm .duty_cycle = int (full_brightness * brightness )
@@ -299,20 +307,20 @@ def _set_backlight(self, brightness):
299307 pass
300308
301309 @property
302- def brightness (self ):
310+ def brightness (self ) -> float :
303311 """Brightness of the backlight when an image is displaying. Clamps to 0 to 1.0"""
304312 return self ._brightness
305313
306314 @brightness .setter
307- def brightness (self , brightness ) :
315+ def brightness (self , brightness : float ) -> None :
308316 if brightness < 0 :
309317 brightness = 0
310318 elif brightness > 1.0 :
311319 brightness = 1.0
312320 self ._brightness = brightness
313321 self ._set_backlight (brightness )
314322
315- def _fade_up (self ):
323+ def _fade_up (self ) -> None :
316324 if not self .fade_effect :
317325 self ._set_backlight (self .brightness )
318326 return
@@ -321,7 +329,7 @@ def _fade_up(self):
321329 self ._set_backlight (self .brightness * i / steps )
322330 time .sleep (0.01 )
323331
324- def _fade_down (self ):
332+ def _fade_down (self ) -> None :
325333 if not self .fade_effect :
326334 self ._set_backlight (self .brightness )
327335 return
@@ -330,7 +338,7 @@ def _fade_down(self):
330338 self ._set_backlight (self .brightness * i / steps )
331339 time .sleep (0.01 )
332340
333- def _create_label (self , file_name ) :
341+ def _create_label (self , file_name : str ) -> bitmap_label . Label :
334342 # pylint: disable=too-many-branches
335343 """Creates and returns a label from a file object that contains
336344 valid valid json describing the text to use.
@@ -389,15 +397,15 @@ def _create_label(self, file_name):
389397 label .anchored_position = (x_anchored_position , y_anchored_position )
390398 return label
391399
392- def update (self ):
400+ def update (self ) -> bool :
393401 """Updates the slideshow to the next image."""
394402 now = time .monotonic ()
395403 if not self .auto_advance or now - self ._img_start < self .dwell :
396404 return True
397405 return self .advance ()
398406
399407 # pylint: disable=too-many-branches, too-many-statements
400- def advance (self ):
408+ def advance (self ) -> bool :
401409 """Displays the next image. Returns True when a new image was displayed, False otherwise."""
402410 if self ._file_name :
403411 self ._fade_down ()
@@ -472,12 +480,12 @@ def advance(self):
472480 # pylint: enable=too-many-branches
473481
474482 @property
475- def h_align (self ):
483+ def h_align (self ) -> int :
476484 """Get or Set the Horizontal Alignment"""
477485 return self ._h_align
478486
479487 @h_align .setter
480- def h_align (self , val ) :
488+ def h_align (self , val : int ) -> None :
481489 if val not in (
482490 HorizontalAlignment .LEFT ,
483491 HorizontalAlignment .CENTER ,
@@ -487,12 +495,12 @@ def h_align(self, val):
487495 self ._h_align = val
488496
489497 @property
490- def v_align (self ):
498+ def v_align (self ) -> int :
491499 """Get or Set the Vertical Alignment"""
492500 return self ._v_align
493501
494502 @v_align .setter
495- def v_align (self , val ) :
503+ def v_align (self , val : int ) -> None :
496504 if val not in (
497505 VerticalAlignment .TOP ,
498506 VerticalAlignment .CENTER ,
0 commit comments