@@ -1094,7 +1094,7 @@ def set_sketch_params(self, scale=None, length=None, randomness=None):
10941094
10951095
10961096class TimerBase (object ):
1097- '''
1097+ """
10981098 A base class for providing timer events, useful for things animations.
10991099 Backends need to implement a few specific methods in order to use their
11001100 own timing mechanisms so that the timer events are integrated into their
@@ -1137,8 +1137,7 @@ class TimerBase(object):
11371137 Stores list of (func, args, kwargs) tuples that will be called upon
11381138 timer events. This list can be manipulated directly, or the
11391139 functions `add_callback` and `remove_callback` can be used.
1140-
1141- '''
1140+ """
11421141 def __init__ (self , interval = None , callbacks = None ):
11431142 #Initialize empty callbacks list and setup default settings if necssary
11441143 if callbacks is None :
@@ -1157,22 +1156,25 @@ def __init__(self, interval=None, callbacks=None):
11571156 self ._timer = None
11581157
11591158 def __del__ (self ):
1160- ' Need to stop timer and possibly disconnect timer.'
1159+ """ Need to stop timer and possibly disconnect timer."""
11611160 self ._timer_stop ()
11621161
11631162 def start (self , interval = None ):
1164- '''
1165- Start the timer object. `interval` is optional and will be used
1166- to reset the timer interval first if provided.
1167- '''
1163+ """
1164+ Start the timer object.
1165+
1166+ Parameters
1167+ ----------
1168+ interval : int, optional
1169+ Timer interval in milliseconds; overrides a previously set interval
1170+ if provided.
1171+ """
11681172 if interval is not None :
11691173 self ._set_interval (interval )
11701174 self ._timer_start ()
11711175
11721176 def stop (self ):
1173- '''
1174- Stop the timer.
1175- '''
1177+ """Stop the timer."""
11761178 self ._timer_stop ()
11771179
11781180 def _timer_start (self ):
@@ -1203,19 +1205,33 @@ def single_shot(self, ss):
12031205 self ._timer_set_single_shot ()
12041206
12051207 def add_callback (self , func , * args , ** kwargs ):
1206- '''
1208+ """
12071209 Register *func* to be called by timer when the event fires. Any
12081210 additional arguments provided will be passed to *func*.
1209- '''
1211+
1212+ This function returns *func*, which makes it possible to use it as a
1213+ decorator.
1214+ """
12101215 self .callbacks .append ((func , args , kwargs ))
1216+ return func
12111217
12121218 def remove_callback (self , func , * args , ** kwargs ):
1213- '''
1214- Remove *func* from list of callbacks. *args* and *kwargs* are optional
1215- and used to distinguish between copies of the same function registered
1216- to be called with different arguments.
1217- '''
1219+ """
1220+ Remove *func* from list of callbacks.
1221+
1222+ *args* and *kwargs* are optional and used to distinguish between copies
1223+ of the same function registered to be called with different arguments.
1224+ This behavior is deprecated. In the future, `*args, **kwargs` won't be
1225+ considered anymore; to keep a specific callback removable by itself,
1226+ pass it to `add_callback` as a `functools.partial` object.
1227+ """
12181228 if args or kwargs :
1229+ cbook .warn_deprecated (
1230+ "3.1" , "In a future version, Timer.remove_callback will not "
1231+ "take *args, **kwargs anymore, but remove all callbacks where "
1232+ "the callable matches; to keep a specific callback removable "
1233+ "by itself, pass it to add_callback as a functools.partial "
1234+ "object." )
12191235 self .callbacks .remove ((func , args , kwargs ))
12201236 else :
12211237 funcs = [c [0 ] for c in self .callbacks ]
@@ -1229,11 +1245,11 @@ def _timer_set_single_shot(self):
12291245 """Used to set single shot on underlying timer object."""
12301246
12311247 def _on_timer (self ):
1232- '''
1248+ """
12331249 Runs all function that have been registered as callbacks. Functions
12341250 can return False (or 0) if they should not be called any more. If there
12351251 are no callbacks, the timer is automatically stopped.
1236- '''
1252+ """
12371253 for func , args , kwargs in self .callbacks :
12381254 ret = func (* args , ** kwargs )
12391255 # docstring above explains why we use `if ret == 0` here,
0 commit comments