Skip to content

Commit ea69347

Browse files
committed
code review changes
1 parent 1ac6f67 commit ea69347

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

adafruit_led_animation/animation.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def draw(self):
108108
"""
109109
Animation subclasses must implement draw() to render the animation sequence.
110110
"""
111+
raise NotImplementedError()
111112

112113
def show(self):
113114
"""
@@ -165,12 +166,6 @@ def speed(self, seconds):
165166
def _recompute_color(self, color):
166167
pass
167168

168-
def change_color(self, color):
169-
"""
170-
By default changing color uses the color property.
171-
"""
172-
self.color = color
173-
174169

175170
class ColorCycle(Animation):
176171
"""
@@ -198,11 +193,6 @@ def _color_generator(self):
198193
yield
199194
index = (index + 1) % len(self.colors)
200195

201-
def change_color(self, color):
202-
"""
203-
ColorCycle doesn't support change_color.
204-
"""
205-
206196

207197
class Blink(ColorCycle):
208198
"""
@@ -218,12 +208,6 @@ def __init__(self, pixel_object, speed, color):
218208
def _recompute_color(self, color):
219209
self.colors = [color, BLACK]
220210

221-
def change_color(self, color):
222-
"""
223-
Change the color.
224-
"""
225-
self.colors[0] = color
226-
227211

228212
class Solid(ColorCycle):
229213
"""
@@ -238,12 +222,6 @@ def __init__(self, pixel_object, color):
238222
def _recompute_color(self, color):
239223
self.colors = [color]
240224

241-
def change_color(self, color):
242-
"""
243-
Change the color.
244-
"""
245-
self.colors[0] = color
246-
247225

248226
class Comet(Animation):
249227
"""
@@ -372,7 +350,7 @@ def draw(self):
372350
intensity = self.min_intensity + (
373351
sin(self._radians_per_second * self._cycle_position) * self._intensity_delta)
374352

375-
color = [int(self._color[n] * intensity) for n in range(self._bpp)]
353+
color = [int(self.color[n] * intensity) for n in range(self._bpp)]
376354
self.fill(color)
377355
self.show()
378356

@@ -502,13 +480,17 @@ def current_animation(self):
502480
"""
503481
return self._members[self._current]
504482

505-
def change_color(self, color):
483+
@property
484+
def color(self):
506485
"""
507-
Change the color of all members that support setting the color with ``change_color``.
508-
Ignored by animations that do not support it.
486+
Use this property to change the color of all members of the animation.
509487
"""
488+
return None
489+
490+
@color.setter
491+
def color(self, color):
510492
for item in self._members:
511-
item.change_color(color)
493+
item.color = color
512494

513495
def fill(self, color):
514496
"""
@@ -573,12 +555,17 @@ def _for_all(self, method, *args, **kwargs):
573555
for item in self._members:
574556
getattr(item, method)(*args, **kwargs)
575557

576-
def change_color(self, color):
558+
@property
559+
def color(self):
577560
"""
578-
Change the color of all members that support setting the color with change_color.
579-
Ignored by animations that do not support it.
561+
Use this property to change the color of all members of the animation group.
580562
"""
581-
self._for_all('change_color', color)
563+
return None
564+
565+
@color.setter
566+
def color(self, color):
567+
for item in self._members:
568+
item.color = color
582569

583570
def fill(self, color):
584571
"""

0 commit comments

Comments
 (0)