1
1
# The MIT License (MIT)
2
2
#
3
3
# Copyright (c) 2019 Kattni Rembor for Adafruit Industries
4
- # Copyright (c) 2019 Roy Hooper
5
4
#
6
5
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
6
# of this software and associated documentation files (the "Software"), to deal
@@ -117,24 +116,20 @@ def show(self):
117
116
"""
118
117
self .pixel_object .show ()
119
118
120
- @property
121
- def paused (self ):
119
+ def freeze (self ):
122
120
"""
123
- Whether the animation is paused .
121
+ Stops the animation until resumed .
124
122
"""
125
- return self ._paused
126
-
127
- @paused .setter
128
- def paused (self , value ):
129
- if self ._paused == value :
130
- return
123
+ self ._paused = True
124
+ self ._time_left_at_pause = max (0 , monotonic_ns () - self ._next_update )
131
125
132
- self ._paused = value
133
- if value :
134
- self ._time_left_at_pause = max (0 , monotonic_ns () - self ._next_update )
135
- else :
136
- self ._next_update = monotonic_ns () + self ._time_left_at_pause
137
- self ._time_left_at_pause = 0
126
+ def resume (self ):
127
+ """
128
+ Resumes the animation.
129
+ """
130
+ self ._next_update = monotonic_ns () + self ._time_left_at_pause
131
+ self ._time_left_at_pause = 0
132
+ self ._paused = False
138
133
139
134
def fill (self , color ):
140
135
"""
@@ -503,25 +498,28 @@ def fill(self, color):
503
498
"""
504
499
self .current_animation .fill (color )
505
500
506
- @property
507
- def paused (self ):
501
+ def freeze (self ):
508
502
"""
509
- Whether the sequence is paused.
503
+ Freeze the current animation in the sequence.
504
+ Also stops auto_advance.
510
505
"""
511
- return self ._paused
506
+ if self ._paused :
507
+ return
508
+ self ._paused = True
509
+ self ._paused_at = monotonic_ns ()
510
+ self .current_animation .freeze ()
512
511
513
- @paused .setter
514
- def paused (self , value ):
515
- if self ._paused == value :
512
+ def resume (self ):
513
+ """
514
+ Resume the current animation in the sequence, and resumes auto advance if enabled.
515
+ """
516
+ if not self ._paused :
516
517
return
517
- self ._paused = value
518
+ self ._paused = False
518
519
now = monotonic_ns ()
519
- if value :
520
- self ._paused_at = now
521
- else :
522
- self ._last_advance += now - self ._paused_at
523
- self ._paused_at = 0
524
- self .current_animation .paused = value
520
+ self ._last_advance += now - self ._paused_at
521
+ self ._paused_at = 0
522
+ self .current_animation .resume ()
525
523
526
524
527
525
class AnimationGroup :
@@ -553,6 +551,10 @@ def animate(self):
553
551
554
552
return any ([item .animate () for item in self ._members ])
555
553
554
+ def _for_all (self , method , * args , ** kwargs ):
555
+ for item in self ._members :
556
+ getattr (item , method )(* args , ** kwargs )
557
+
556
558
@property
557
559
def color (self ):
558
560
"""
@@ -569,17 +571,16 @@ def fill(self, color):
569
571
"""
570
572
Fills all pixel objects in the group with a color.
571
573
"""
572
- for member in self ._members :
573
- member .fill (color )
574
+ self ._for_all ('fill' , color )
574
575
575
- @property
576
- def paused (self ):
576
+ def freeze (self ):
577
577
"""
578
- Whether the group is paused .
578
+ Freeze all animations in the group .
579
579
"""
580
- return all ([ member . paused for member in self ._members ] )
580
+ self ._for_all ( 'freeze' )
581
581
582
- @paused .setter
583
- def paused (self , value ):
584
- for member in self ._members :
585
- member .paused = value
582
+ def resume (self ):
583
+ """
584
+ Resume all animations in the group.
585
+ """
586
+ self ._for_all ('resume' )
0 commit comments