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