Skip to content

Commit 96c4bc8

Browse files
committed
Update example for changes in 462c203, 91bd5fa, 014ff35 and 466e8db
1 parent 462c203 commit 96c4bc8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

examples/animated_sender.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,16 @@ def update_tallies(self, tallies: Iterable[Tally]) -> List[int]:
4949

5050
class AnimatedSender(UmdSender):
5151
tally_groups: Dict[TallyType, TallyTypeGroup]
52-
def __init__(self, clients=None, num_tallies=8, update_interval=.5, screen=1):
52+
def __init__(self, clients=None, num_tallies=8, update_interval=.5, screen=1, all_off_on_close=False):
5353
self.num_tallies = num_tallies
5454
self.update_interval = update_interval
55-
super().__init__(clients)
55+
super().__init__(clients, all_off_on_close)
5656
self.screen = self.get_or_create_screen(screen)
5757
for i in range(self.num_tallies):
5858
self.screen.add_tally(i, text=string.ascii_uppercase[i])
5959

6060
self.tally_groups = {}
61-
for tally_type in TallyType:
62-
if tally_type == TallyType.no_tally:
63-
continue
61+
for tally_type in TallyType.all():
6462
tg = TallyTypeGroup(tally_type, self.num_tallies)
6563
self.tally_groups[tally_type] = tg
6664

@@ -124,7 +122,7 @@ def animate_vertical(self):
124122
self.cur_index = start_ix
125123

126124
def animate_horizontal(self):
127-
tally_types = [t for t in TallyType]
125+
tally_types = [t for t in TallyType if t != TallyType.all_tally]
128126
while tally_types[0] != self.cur_group:
129127
t = tally_types.pop(0)
130128
tally_types.append(t)
@@ -139,7 +137,13 @@ def animate_horizontal(self):
139137
color = TallyColor.OFF
140138
tg.tally_colors[self.cur_index] = color
141139
try:
142-
t = TallyType(self.cur_group.value+1)
140+
if self.cur_group.value == 0:
141+
v = 1
142+
else:
143+
v = self.cur_group.value * 2
144+
if v > TallyType.all_tally.value:
145+
raise ValueError()
146+
t = TallyType(v)
143147
self.cur_group = t
144148
except ValueError:
145149
self.cur_index += 1
@@ -154,7 +158,7 @@ async def update_loop(self):
154158
def update_tallies():
155159
changed = set()
156160
for tg in self.tally_groups.values():
157-
_changed = tg.update_tallies(self.tallies.values())
161+
_changed = tg.update_tallies(self.screen.tallies.values())
158162
changed |= set(_changed)
159163
return changed
160164

@@ -178,6 +182,9 @@ def main():
178182
p.add_argument(
179183
'-n', '--num-tallies', dest='num_tallies', type=int, default=8,
180184
)
185+
p.add_argument(
186+
'-a', '--all-of-on-close', dest='all_off_on_close', action='store_true',
187+
)
181188
p.add_argument(
182189
'-i', '--interval', dest='update_interval', type=float, default=.5,
183190
)

0 commit comments

Comments
 (0)