8000 Dedupe timer attribute docs. · matplotlib/matplotlib@ddfe754 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddfe754

Browse files
committed
Dedupe timer attribute docs.
Instead of repeating them in each subclass they can be listed in the `__init__` docstring and in property docstrings (both inherited).
1 parent abfdecf commit ddfe754

File tree

6 files changed

+21
-101
lines changed

6 files changed

+21
-101
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,34 +1044,24 @@ class itself will store the flag and the ``_on_timer`` method should be
10441044
10451045
- ``_on_timer``: The internal function that any timer object should call,
10461046
which will handle the task of running all callbacks that have been set.
1047-
1048-
Attributes
1049-
----------
1050-
interval : int, default: 1000ms
1051-
The time between timer events in milliseconds.
1052-
single_shot : bool, default: False
1053-
Whether this timer should operate as single shot (run once and then
1054-
stop).
1055-
callbacks : List[Tuple[callable, Tuple, Dict]]
1056-
Stores list of (func, args, kwargs) tuples that will be called upon
1057-
timer events. This list can be manipulated directly, or the
1058-
functions `add_callback` and `remove_callback` can be used.
10591047
"""
10601048

10611049
def __init__(self, interval=None, callbacks=None):
1062-
#Initialize empty callbacks list and setup default settings if necssary
1063-
if callbacks is None:
1064-
self.callbacks = []
1065-
else:
1066-
self.callbacks = callbacks.copy()
1067-
1068-
if interval is None:
1069-
self._interval = 1000
1070-
else:
1071-
self._interval = interval
1072-
1050+
"""
1051+
Parameters
1052+
----------
1053+
interval : int, default: 1000ms
1054+
The time between timer events in milliseconds. Will be stored as
1055+
``timer.interval``.
1056+
callbacks : List[Tuple[callable, Tuple, Dict]]
1057+
List of (func, args, kwargs) tuples that will be called upon
1058+
timer events. This list is accessible as ``timer.callbacks`` and
1059+
can be manipulated directly, or the functions `add_callback` and
1060+
`remove_callback` can be used.
1061+
"""
1062+
self.callbacks = [] if callbacks is None else callbacks.copy()
1063+
self._interval = 1000 if interval is None else interval
10731064
self._single = False
1074-
10751065
# Default attribute for holding the GUI-specific timer object
10761066
self._timer = None
10771067

@@ -1105,6 +1095,7 @@ def _timer_stop(self):
11051095

11061096
@property
11071097
def interval(self):
1098+
"""The time between timer events, in milliseconds."""
11081099
return self._interval
11091100

11101101
@interval.setter
@@ -1117,6 +1108,7 @@ def interval(self, interval):
11171108

11181109
@property
11191110
def single_shot(self):
1111+
"""Whether this timer should stop after a single run."""
11201112
return self._single
11211113

11221114
@single_shot.setter

lib/matplotlib/backends/_backend_tk.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,8 @@ def blit(photoimage, aggimage, offsets, bbox=None):
8080

8181

8282
class TimerTk(TimerBase):
83-
"""
84-
Subclass of :class:`backend_bases.TimerBase` that uses Tk's timer events.
83+
"""Subclass of `backend_bases.TimerBase` using Tk timer events."""
8584

86-
Attributes
87-
----------
88-
interval : int, default: 1000ms
89-
The time between timer events in milliseconds.
90-
single_shot : bool, default: False
91-
Whether this timer should operate as single shot (run once and then
92-
stop).
93-
callbacks : list
94-
Stores list of (func, args) tuples that will be called upon timer
95-
events. This list can be manipulated directly, or the functions
96-
`add_callback` and `remove_callback` can be used.
97-
98-
"""
9985
def __init__(self, parent, *args, **kwargs):
10086
TimerBase.__init__(self, *args, **kwargs)
10187
self.parent = parent

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,7 @@
5151

5252

5353
class TimerGTK3(TimerBase):
54-
"""
55-
Subclass of `.TimerBase` using GTK3 for timer events.
56-
57-
Attributes
58-
----------
59-
interval : int, default: 1000ms
60-
The time between timer events in milliseconds.
61-
single_shot : bool, default: False
62-
Whether this timer should operate as single shot (run once and then
63-
stop).
64-
callbacks : list
65-
Stores list of (func, args) tuples that will be called upon timer
66-
events. This list can be manipulated directly, or the functions
67-
`add_callback` and `remove_callback` can be used.
68-
"""
54+
"""Subclass of `.TimerBase` using GTK3 timer events."""
6955

7056
def _timer_start(self):
7157
# Need to stop it, otherwise we potentially leak a timer id that will

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,7 @@
1919

2020

2121
class TimerMac(_macosx.Timer, TimerBase):
22-
"""
23-
Subclass of `.TimerBase` that uses CoreFoundation run loops for timer
24-
events.
25-
26-
Attributes
27-
----------
28-
interval : int, default: 1000ms
29-
The time between timer events in milliseconds.
30-
single_shot : bool, default: False
31-
Whether this timer should operate as single shot (run once and then
32-
stop).
33-
callbacks : list
34-
Stores list of (func, args) tuples that will be called upon timer
35-
events. This list can be manipulated directly, or the functions
36-
`add_callback` and `remove_callback` can be used.
37-
"""
22+
"""Subclass of `.TimerBase` using CFRunLoop timer events."""
3823
# completely implemented at the C-level (in _macosx.Timer)
3924

4025

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,10 @@ def wrapper(self, *args, **kwargs):
175175

176176

177177
class TimerQT(TimerBase):
178-
"""
179-
Subclass of `.TimerBase` that uses Qt timer events.
180-
181-
Attributes
182-
----------
183-
interval : int, default: 1000ms
184-
The time between timer events in milliseconds.
185-
single_shot : bool, default: False
186-
Whether this timer should operate as single shot (run once and then
187-
stop).
188-
callbacks : list
189-
Stores list of (func, args) tuples that will be called upon timer
190-
events. This list can be manipulated directly, or the functions
191-
`add_callback` and `remove_callback` can be used.
192-
"""
178+
"""Subclass of `.TimerBase` using QTimer events."""
193179

194180
def __init__(self, *args, **kwargs):
195181
TimerBase.__init__(self, *args, **kwargs)
196-
197182
# Create a new timer and connect the timeout() signal to the
198183
# _on_timer method.
199184
self._timer = QtCore.QTimer()

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,7 @@ def error_msg_wx(msg, parent=None):
6969

7070

7171
class TimerWx(TimerBase):
72-
"""
73-
Subclass of `.TimerBase` that uses WxTimer events.
74-
75-
Attributes
76-
----------
77-
interval : int, default: 1000ms
78-
The time between timer events in milliseconds.
79-
single_shot : bool, default: False
80-
Whether this timer should operate as single shot (run once and then
81-
stop).
82-
callbacks : list
83-
Stores list of (func, args) tuples that will be called upon timer
84-
events. This list can be manipulated directly, or the functions
85-
`add_callback` and `remove_callback` can be used.
86-
"""
72+
"""Subclass of `.TimerBase` using wx.Timer events."""
8773

8874
def __init__(self, *args, **kwargs):
8975
TimerBase.__init__(self, *args, **kwargs)

0 commit comments

Comments
 (0)
0