Skip to content

Commit 6f144bb

Browse files
committed
Restore support for assigning a list to strip[:]
This functionality was lost in commit: f80276b Signed-off-by: David Greaves <[email protected]>
1 parent f12afe0 commit 6f144bb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

library/rpi_ws281x/rpi_ws281x.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,19 @@ def __getitem__(self, pos):
106106

107107
def __setitem__(self, pos, value):
108108
"""Set the 24-bit RGB color value at the provided position or slice of
109-
positions.
109+
positions. If value is a slice it is zip()'ed with pos to set as many
110+
leds as there are values.
110111
"""
111112
# Handle if a slice of positions are passed in by setting the appropriate
112113
# LED data values to the provided value.
113114
# Cast to int() as value may be a numpy non-int value.
114115
if isinstance(pos, slice):
115-
for n in range(*pos.indices(self.size)):
116-
ws.ws2811_led_set(self._channel, n, int(value))
116+
try:
117+
for n, c in zip(range(*pos.indices(self.size)), value):
118+
ws.ws2811_led_set(self._channel, n, int(c))
119+
except TypeError:
120+
for n in range(*pos.indices(self.size)):
121+
ws.ws2811_led_set(self._channel, n, int(value))
117122
# Else assume the passed in value is a number to the position.
118123
else:
119124
return ws.ws2811_led_set(self._channel, pos, int(value))

0 commit comments

Comments
 (0)