11# The MIT License (MIT)
22#
33# Copyright (c) 2019 Kattni Rembor for Adafruit Industries
4- # Copyright (c) 2019 Roy Hooper
54#
65# Permission is hereby granted, free of charge, to any person obtaining a copy
76# of this software and associated documentation files (the "Software"), to deal
@@ -117,24 +116,20 @@ def show(self):
117116 """
118117 self .pixel_object .show ()
119118
120- @property
121- def paused (self ):
119+ def freeze (self ):
122120 """
123- Whether the animation is paused .
121+ Stops the animation until resumed .
124122 """
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 )
131125
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
138133
139134 def fill (self , color ):
140135 """
@@ -503,25 +498,28 @@ def fill(self, color):
503498 """
504499 self .current_animation .fill (color )
505500
506- @property
507- def paused (self ):
501+ def freeze (self ):
508502 """
509- Whether the sequence is paused.
503+ Freeze the current animation in the sequence.
504+ Also stops auto_advance.
510505 """
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 ()
512511
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 :
516517 return
517- self ._paused = value
518+ self ._paused = False
518519 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 ()
525523
526524
527525class AnimationGroup :
@@ -553,6 +551,10 @@ def animate(self):
553551
554552 return any ([item .animate () for item in self ._members ])
555553
554+ def _for_all (self , method , * args , ** kwargs ):
555+ for item in self ._members :
556+ getattr (item , method )(* args , ** kwargs )
557+
556558 @property
557559 def color (self ):
558560 """
@@ -569,17 +571,16 @@ def fill(self, color):
569571 """
570572 Fills all pixel objects in the group with a color.
571573 """
572- for member in self ._members :
573- member .fill (color )
574+ self ._for_all ('fill' , color )
574575
575- @property
576- def paused (self ):
576+ def freeze (self ):
577577 """
578- Whether the group is paused .
578+ Freeze all animations in the group .
579579 """
580- return all ([ member . paused for member in self ._members ] )
580+ self ._for_all ( 'freeze' )
581581
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