@@ -1268,10 +1268,10 @@ class TimerBase(object):
1268
1268
Boolean flag indicating whether this timer should operate as single
1269
1269
shot (run once and then stop). Defaults to `False`.
1270
1270
1271
- callbacks : list
1272
- Stores list of (func, args) tuples that will be called upon timer
1273
- events. This list can be manipulated directly, or the functions
1274
- `add_callback` and `remove_callback` can be used.
1271
+ callbacks : List[Tuple[callable, Tuple, Dict]]
1272
+ Stores list of (func, args, kwargs ) tuples that will be called upon
1273
+ timer events. This list can be manipulated directly, or the
1274
+ functions `add_callback` and `remove_callback` can be used.
1275
1275
1276
1276
'''
1277
1277
def __init__ (self , interval = None , callbacks = None ):
@@ -1371,9 +1371,12 @@ def _on_timer(self):
1371
1371
'''
1372
1372
for func , args , kwargs in self .callbacks :
1373
1373
ret = func (* args , ** kwargs )
1374
- # docstring above explains why we use `if ret == False ` here,
1374
+ # docstring above explains why we use `if ret == 0 ` here,
1375
1375
# instead of `if not ret`.
1376
- if ret == False :
1376
+ # This will also catch `ret == False` as `False == 0`
1377
+ # but does not annoy the linters
1378
+ # https://docs.python.org/3/library/stdtypes.html#boolean-values
1379
+ if ret == 0 :
1377
1380
self .callbacks .remove ((func , args , kwargs ))
1378
1381
1379
1382
if len (self .callbacks ) == 0 :
@@ -2407,10 +2410,19 @@ def new_timer(self, *args, **kwargs):
2407
2410
----------------
2408
2411
interval : scalar
2409
2412
Timer interval in milliseconds
2410
- callbacks : list
2413
+
2414
+ callbacks : List[Tuple[callable, Tuple, Dict]]
2411
2415
Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
2412
2416
will be executed by the timer every *interval*.
2413
2417
2418
+ callbacks which return ``False`` or ``0`` will be removed from the
2419
+ timer.
2420
+
2421
+ Examples
2422
+ --------
2423
+
2424
+ >>> timer = fig.canvas.new_timer(callbacks=[(f1, (1, ), {'a': 3}),])
2425
+
2414
2426
"""
2415
2427
return TimerBase (* args , ** kwargs )
2416
2428
0 commit comments