2525====================================================
2626CircuitPython helper library for displaying a slideshow of images on a display.
2727
28- * Author(s): Kattni Rembor, Carter Nelson, Roy Hooper
28+ * Author(s): Kattni Rembor, Carter Nelson, Roy Hooper, Melissa LeBlanc-Williams
2929
3030Implementation Notes
3131--------------------
4949__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
5050
5151
52+ class HorizontalAlignment :
53+ """Defines possible horizontal alignment orders."""
54+
55+ # pylint: disable=too-few-public-methods
56+ LEFT = 1
57+ CENTER = 2
58+ RIGHT = 3
59+ # pylint: enable=too-few-public-methods
60+
61+
62+ class VerticalAlignment :
63+ """Defines possible vertical alignment orders."""
64+
65+ # pylint: disable=too-few-public-methods
66+ TOP = 1
67+ CENTER = 2
68+ BOTTOM = 3
69+ # pylint: enable=too-few-public-methods
70+
71+
5272class PlayBackOrder :
5373 """Defines possible slideshow playback orders."""
5474
@@ -102,6 +122,10 @@ class SlideShow:
102122
103123 :param PlayBackDirection direction: The playback direction.
104124
125+ :param HorizonalAlignment h_align: The Horizontal alignment of smaller/larger images
126+
127+ :param VerticalAlignment v_align: The Vertical alignment of smaller/larger images
128+
105129 Example code for Hallowing Express. With this example, the slideshow will play through once
106130 in alphabetical order:
107131
@@ -162,7 +186,9 @@ def __init__(
162186 dwell = 3 ,
163187 fade_effect = True ,
164188 auto_advance = True ,
165- direction = PlayBackDirection .FORWARD
189+ direction = PlayBackDirection .FORWARD ,
190+ h_align = HorizontalAlignment .LEFT ,
191+ v_align = VerticalAlignment .TOP ,
166192 ):
167193 self .loop = loop
168194 """Specifies whether to loop through the images continuously or play through the list once.
@@ -196,6 +222,10 @@ def __init__(
196222 """The order in which the images display. You can choose random (``RANDOM``) or
197223 alphabetical (``ALPHA``)."""
198224
225+ # Default positioning
226+ self ._h_align = h_align
227+ self ._v_align = v_align
228+
199229 self ._current_image = - 1
200230 self ._image_file = None
201231 self ._brightness = 0.5
@@ -289,9 +319,9 @@ def update(self):
289319
290320 return self .advance ()
291321
322+ # pylint: disable=too-many-branches
292323 def advance (self ):
293- """Displays the next image. Returns True when a new image was displayed, False otherwise.
294- """
324+ """Displays the next image. Returns True when a new image was displayed, False otherwise."""
295325 if self ._image_file :
296326 self ._fade_down ()
297327 self ._group .pop ()
@@ -328,6 +358,20 @@ def advance(self):
328358 if not odb :
329359 raise RuntimeError ("No valid images" )
330360
361+ if self ._h_align == HorizontalAlignment .RIGHT :
362+ self ._group .x = self ._display .width - odb .width
363+ elif self ._h_align == HorizontalAlignment .CENTER :
364+ self ._group .x = round (self ._display .width / 2 - odb .width / 2 )
365+ else :
366+ self ._group .x = 0
367+
368+ if self ._v_align == VerticalAlignment .BOTTOM :
369+ self ._group .y = self ._display .height - odb .height
370+ elif self ._v_align == VerticalAlignment .CENTER :
371+ self ._group .y = round (self ._display .height / 2 - odb .height / 2 )
372+ else :
373+ self ._group .y = 0
374+
331375 try :
332376 sprite = self ._sprite_class (odb , pixel_shader = displayio .ColorConverter ())
333377 except TypeError :
@@ -340,3 +384,35 @@ def advance(self):
340384 self ._img_start = time .monotonic ()
341385
342386 return True
387+
388+ # pylint: enable=too-many-branches
389+
390+ @property
391+ def h_align (self ):
392+ """Get or Set the Horizontal Alignment"""
393+ return self ._h_align
394+
395+ @h_align .setter
396+ def h_align (self , val ):
397+ if val not in (
398+ HorizontalAlignment .LEFT ,
399+ HorizontalAlignment .CENTER ,
400+ HorizontalAlignment .RIGHT ,
401+ ):
402+ raise ValueError ("Alignment must be LEFT, RIGHT, or CENTER" )
403+ self ._h_align = val
404+
405+ @property
406+ def v_align (self ):
407+ """Get or Set the Vertical Alignment"""
408+ return self ._v_align
409+
410+ @v_align .setter
411+ def v_align (self , val ):
412+ if val not in (
413+ VerticalAlignment .TOP ,
414+ VerticalAlignment .CENTER ,
415+ VerticalAlignment .BOTTOM ,
416+ ):
417+ raise ValueError ("Alignment must be TOP, BOTTOM, or CENTER" )
418+ self ._v_align = val
0 commit comments