25
25
====================================================
26
26
CircuitPython helper library for displaying a slideshow of images on a display.
27
27
28
- * Author(s): Kattni Rembor, Carter Nelson, Roy Hooper
28
+ * Author(s): Kattni Rembor, Carter Nelson, Roy Hooper, Melissa LeBlanc-Williams
29
29
30
30
Implementation Notes
31
31
--------------------
45
45
import random
46
46
import displayio
47
47
48
- __version__ = "0.0.0-auto.0 "
48
+ __version__ = "1.2.2 "
49
49
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Slideshow.git"
50
50
51
51
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
+
52
72
class PlayBackOrder :
53
73
"""Defines possible slideshow playback orders."""
54
74
@@ -102,6 +122,10 @@ class SlideShow:
102
122
103
123
:param PlayBackDirection direction: The playback direction.
104
124
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
+
105
129
Example code for Hallowing Express. With this example, the slideshow will play through once
106
130
in alphabetical order:
107
131
@@ -162,7 +186,9 @@ def __init__(
162
186
dwell = 3 ,
163
187
fade_effect = True ,
164
188
auto_advance = True ,
165
- direction = PlayBackDirection .FORWARD
189
+ direction = PlayBackDirection .FORWARD ,
190
+ h_align = HorizontalAlignment .LEFT ,
191
+ v_align = VerticalAlignment .TOP ,
166
192
):
167
193
self .loop = loop
168
194
"""Specifies whether to loop through the images continuously or play through the list once.
@@ -196,6 +222,10 @@ def __init__(
196
222
"""The order in which the images display. You can choose random (``RANDOM``) or
197
223
alphabetical (``ALPHA``)."""
198
224
225
+ # Default positioning
226
+ self ._h_align = h_align
227
+ self ._v_align = v_align
228
+
199
229
self ._current_image = - 1
200
230
self ._image_file = None
201
231
self ._brightness = 0.5
@@ -289,9 +319,9 @@ def update(self):
289
319
290
320
return self .advance ()
291
321
322
+ # pylint: disable=too-many-branches
292
323
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."""
295
325
if self ._image_file :
296
326
self ._fade_down ()
297
327
self ._group .pop ()
@@ -328,6 +358,20 @@ def advance(self):
328
358
if not odb :
329
359
raise RuntimeError ("No valid images" )
330
360
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
+
331
375
try :
332
376
sprite = self ._sprite_class (odb , pixel_shader = displayio .ColorConverter ())
333
377
except TypeError :
@@ -340,3 +384,35 @@ def advance(self):
340
384
self ._img_start = time .monotonic ()
341
385
342
386
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