Skip to content

Commit

Permalink
Merge pull request #10188 from tacaswell/doc_timer_docs
Browse files Browse the repository at this point in the history
Doc timer docs
  • Loading branch information
anntzer committed Jan 11, 2018
2 parents 9944014 + 1151391 commit ad27247
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,10 +1268,10 @@ class TimerBase(object):
Boolean flag indicating whether this timer should operate as single
shot (run once and then stop). Defaults to `False`.
callbacks : list
Stores list of (func, args) tuples that will be called upon timer
events. This list can be manipulated directly, or the functions
`add_callback` and `remove_callback` can be used.
callbacks : List[Tuple[callable, Tuple, Dict]]
Stores list of (func, args, kwargs) tuples that will be called upon
timer events. This list can be manipulated directly, or the
functions `add_callback` and `remove_callback` can be used.
'''
def __init__(self, interval=None, callbacks=None):
Expand Down Expand Up @@ -1371,9 +1371,12 @@ def _on_timer(self):
'''
for func, args, kwargs in self.callbacks:
ret = func(*args, **kwargs)
# docstring above explains why we use `if ret == False` here,
# docstring above explains why we use `if ret == 0` here,
# instead of `if not ret`.
if ret == False:
# This will also catch `ret == False` as `False == 0`
# but does not annoy the linters
# https://docs.python.org/3/library/stdtypes.html#boolean-values
if ret == 0:
self.callbacks.remove((func, args, kwargs))

if len(self.callbacks) == 0:
Expand Down Expand Up @@ -2407,10 +2410,19 @@ def new_timer(self, *args, **kwargs):
----------------
interval : scalar
Timer interval in milliseconds
callbacks : list
callbacks : List[Tuple[callable, Tuple, Dict]]
Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
will be executed by the timer every *interval*.
callbacks which return ``False`` or ``0`` will be removed from the
timer.
Examples
--------
>>> timer = fig.canvas.new_timer(callbacks=[(f1, (1, ), {'a': 3}),])
"""
return TimerBase(*args, **kwargs)

Expand Down

0 comments on commit ad27247

Please sign in to comment.