@@ -210,16 +210,19 @@ def callback(dt):
210210
211211 async def anim_with_et (self , * , step = 0 ) -> AsyncIterator [TimeUnit ]:
212212 '''
213- Same as :meth:`anim_with_dt` except this one generates the total elapsed time of the loop instead of the elapsed
214- time between frames.
215-
216213 .. code-block::
217214
218- timeout = ...
219215 async for et in clock.anim_with_et():
220- ...
221- if et > timeout:
222- break
216+ print(et)
217+
218+ The code above is equivalent to the below.
219+
220+ .. code-block::
221+
222+ et = 0
223+ async for dt in clock.anim_with_dt():
224+ et += dt
225+ print(et)
223226 '''
224227 et = 0
225228 async with _repeat_sleeping (self , step ) as sleep :
@@ -243,54 +246,62 @@ async def anim_with_dt_et(self, *, step=0) -> AsyncIterator[tuple[TimeUnit, Time
243246 et += dt
244247 yield dt , et
245248
246- async def anim_with_ratio (self , * , duration , step = 0 ) -> AsyncIterator [float ]:
249+ async def anim_with_ratio (self , * , base , step = 0 ) -> AsyncIterator [float ]:
247250 '''
248- Same as :meth:`anim_with_et` except this one generates the total progression ratio of the loop.
249-
250251 .. code-block::
251252
252- async for p in self .anim_with_ratio(duration=... ):
253+ async for p in clock .anim_with_ratio(base=100 ):
253254 print(p * 100, "%")
254255
256+ The code above is equivalent to the below.
257+
258+ .. code-block::
259+
260+ base = 100
261+ async for et in clock.anim_with_et():
262+ print(et / base * 100, "%")
263+
255264 If you want to progress at a non-consistant rate, you may find the
256265 `source code <https://github.com/kivy/kivy/blob/master/kivy/animation.py>`__
257266 of the :class:`kivy.animation.AnimationTransition` helpful.
258267
259268 .. code-block::
260269
261- async for p in clock.anim_with_ratio(duration =...):
270+ async for p in clock.anim_with_ratio(base =...):
262271 p = p * p # quadratic
263272 print(p * 100, "%")
273+
274+ .. versionchanged:: 0.5.0
275+
276+ The ``duration`` parameter was replaced with the ``base`` parameter.
277+ The loop no longer stops when the progression reaches 1.0.
264278 '''
265- if not duration :
266- await self .sleep (step )
267- yield 1.0
268- return
269279 et = 0
270280 async with _repeat_sleeping (self , step ) as sleep :
271- while et < duration :
281+ while True :
272282 et += await sleep ()
273- yield et / duration
283+ yield et / base
274284
275- async def anim_with_dt_et_ratio (self , * , duration , step = 0 ) -> AsyncIterator [tuple [TimeUnit , TimeUnit , float ]]:
285+ async def anim_with_dt_et_ratio (self , * , base , step = 0 ) -> AsyncIterator [tuple [TimeUnit , TimeUnit , float ]]:
276286 '''
277287 :meth:`anim_with_dt`, :meth:`anim_with_et` and :meth:`anim_with_ratio` combined.
278288
279289 .. code-block::
280290
281291 async for dt, et, p in clock.anim_with_dt_et_ratio(...):
282292 ...
293+
294+ .. versionchanged:: 0.5.0
295+
296+ The ``duration`` parameter was replaced with the ``base`` parameter.
297+ The loop no longer stops when the progression reaches 1.0.
283298 '''
284299 async with _repeat_sleeping (self , step ) as sleep :
285- if not duration :
286- dt = await sleep ()
287- yield dt , dt , 1.0
288- return
289300 et = 0.
290- while et < duration :
301+ while True :
291302 dt = await sleep ()
292303 et += dt
293- yield dt , et , et / duration
304+ yield dt , et , et / base
294305
295306 def _linear (p ):
296307 return p
@@ -316,10 +327,13 @@ async def interpolate_scalar(self, start, end, *, duration, step=0, transition=_
316327 '''
317328 slope = end - start
318329 yield transition (0. ) * slope + start
319- async for p in self .anim_with_ratio (step = step , duration = duration ):
320- if p >= 1.0 :
321- break
322- yield transition (p ) * slope + start
330+ if duration :
331+ async for p in self .anim_with_ratio (step = step , base = duration ):
332+ if p >= 1.0 :
333+ break
334+ yield transition (p ) * slope + start
335+ else :
336+ await self .sleep (0 )
323337 yield transition (1. ) * slope + start
324338
325339 async def interpolate_sequence (self , start , end , * , duration , step = 0 , transition = _linear , output_type = tuple ) -> AsyncIterator :
@@ -347,11 +361,14 @@ async def interpolate_sequence(self, start, end, *, duration, step=0, transition
347361 p = transition (0. )
348362 yield output_type (p * slope_elem + start_elem for slope_elem , start_elem in zip_ (slope , start ))
349363
350- async for p in self .anim_with_ratio (step = step , duration = duration ):
351- if p >= 1.0 :
352- break
353- p = transition (p )
354- yield output_type (p * slope_elem + start_elem for slope_elem , start_elem in zip_ (slope , start ))
364+ if duration :
365+ async for p in self .anim_with_ratio (step = step , base = duration ):
366+ if p >= 1.0 :
367+ break
368+ p = transition (p )
369+ yield output_type (p * slope_elem + start_elem for slope_elem , start_elem in zip_ (slope , start ))
370+ else :
371+ await self .sleep (0 )
355372
356373 p = transition (1. )
357374 yield output_type (p * slope_elem + start_elem for slope_elem , start_elem in zip_ (slope , start ))
0 commit comments