@@ -1268,10 +1268,10 @@ class TimerBase(object):
12681268 Boolean flag indicating whether this timer should operate as single
12691269 shot (run once and then stop). Defaults to `False`.
12701270
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.
12751275
12761276 '''
12771277 def __init__ (self , interval = None , callbacks = None ):
@@ -1371,9 +1371,12 @@ def _on_timer(self):
13711371 '''
13721372 for func , args , kwargs in self .callbacks :
13731373 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,
13751375 # 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 :
13771380 self .callbacks .remove ((func , args , kwargs ))
13781381
13791382 if len (self .callbacks ) == 0 :
@@ -2407,10 +2410,19 @@ def new_timer(self, *args, **kwargs):
24072410 ----------------
24082411 interval : scalar
24092412 Timer interval in milliseconds
2410- callbacks : list
2413+
2414+ callbacks : List[Tuple[callable, Tuple, Dict]]
24112415 Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
24122416 will be executed by the timer every *interval*.
24132417
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+
24142426 """
24152427 return TimerBase (* args , ** kwargs )
24162428
0 commit comments