@@ -210,16 +210,19 @@ def callback(dt):
210
210
211
211
async def anim_with_et (self , * , step = 0 ) -> AsyncIterator [TimeUnit ]:
212
212
'''
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
-
216
213
.. code-block::
217
214
218
- timeout = ...
219
215
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)
223
226
'''
224
227
et = 0
225
228
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
243
246
et += dt
244
247
yield dt , et
245
248
246
- async def anim_with_ratio (self , * , duration , step = 0 ) -> AsyncIterator [float ]:
249
+ async def anim_with_ratio (self , * , base , step = 0 ) -> AsyncIterator [float ]:
247
250
'''
248
- Same as :meth:`anim_with_et` except this one generates the total progression ratio of the loop.
249
-
250
251
.. code-block::
251
252
252
- async for p in self .anim_with_ratio(duration=... ):
253
+ async for p in clock .anim_with_ratio(base=100 ):
253
254
print(p * 100, "%")
254
255
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
+
255
264
If you want to progress at a non-consistant rate, you may find the
256
265
`source code <https://github.com/kivy/kivy/blob/master/kivy/animation.py>`__
257
266
of the :class:`kivy.animation.AnimationTransition` helpful.
258
267
259
268
.. code-block::
260
269
261
- async for p in clock.anim_with_ratio(duration =...):
270
+ async for p in clock.anim_with_ratio(base =...):
262
271
p = p * p # quadratic
263
272
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.
264
278
'''
265
- if not duration :
266
- await self .sleep (step )
267
- yield 1.0
268
- return
269
279
et = 0
270
280
async with _repeat_sleeping (self , step ) as sleep :
271
- while et < duration :
281
+ while True :
272
282
et += await sleep ()
273
- yield et / duration
283
+ yield et / base
274
284
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 ]]:
276
286
'''
277
287
:meth:`anim_with_dt`, :meth:`anim_with_et` and :meth:`anim_with_ratio` combined.
278
288
279
289
.. code-block::
280
290
281
291
async for dt, et, p in clock.anim_with_dt_et_ratio(...):
282
292
...
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.
283
298
'''
284
299
async with _repeat_sleeping (self , step ) as sleep :
285
- if not duration :
286
- dt = await sleep ()
287
- yield dt , dt , 1.0
288
- return
289
300
et = 0.
290
- while et < duration :
301
+ while True :
291
302
dt = await sleep ()
292
303
et += dt
293
- yield dt , et , et / duration
304
+ yield dt , et , et / base
294
305
295
306
def _linear (p ):
296
307
return p
@@ -316,10 +327,13 @@ async def interpolate_scalar(self, start, end, *, duration, step=0, transition=_
316
327
'''
317
328
slope = end - start
318
329
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 )
323
337
yield transition (1. ) * slope + start
324
338
325
339
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
347
361
p = transition (0. )
348
362
yield output_type (p * slope_elem + start_elem for slope_elem , start_elem in zip_ (slope , start ))
349
363
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 )
355
372
356
373
p = transition (1. )
357
374
yield output_type (p * slope_elem + start_elem for slope_elem , start_elem in zip_ (slope , start ))
0 commit comments