Skip to content

Correctly go through property setter when init'ing Timer interval. #17160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/api_changes_3.3/behaviour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,8 @@ explicitly pass a "%1.2f" as the *valfmt* parameter to `.Slider`.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All the functionality of ``CustomCell`` has been moved to its base class
`~.table.Cell`.

wx Timer interval
~~~~~~~~~~~~~~~~~
Setting the timer interval on a not-yet-started ``TimerWx`` won't start it
anymore.
7 changes: 3 additions & 4 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,9 @@ def __init__(self, interval=None, callbacks=None):
`remove_callback` can be used.
"""
self.callbacks = [] if callbacks is None else callbacks.copy()
self._interval = 1000 if interval is None else interval
self._single = False
# Default attribute for holding the GUI-specific timer object
self._timer = None
# Set .interval and not ._interval to go through the property setter.
self.interval = 1000 if interval is None else interval
self.single_shot = False

def __del__(self):
"""Need to stop timer and possibly disconnect timer."""
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class TimerTk(TimerBase):
"""Subclass of `backend_bases.TimerBase` using Tk timer events."""

def __init__(self, parent, *args, **kwargs):
self._timer = None
TimerBase.__init__(self, *args, **kwargs)
self.parent = parent
self._timer = None

def _timer_start(self):
self._timer_stop()
Expand All @@ -97,7 +97,6 @@ def _timer_stop(self):

def _on_timer(self):
TimerBase._on_timer(self)

# Tk after() is only a single shot, so we need to add code here to
# reset the timer if we're not operating in single shot mode. However,
# if _timer is None, this means that _timer_stop has been called; so
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
class TimerGTK3(TimerBase):
"""Subclass of `.TimerBase` using GTK3 timer events."""

def __init__(self, *args, **kwargs):
self._timer = None
TimerBase.__init__(self, *args, **kwargs)

def _timer_start(self):
# Need to stop it, otherwise we potentially leak a timer id that will
# never be stopped.
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ class TimerQT(TimerBase):
"""Subclass of `.TimerBase` using QTimer events."""

def __init__(self, *args, **kwargs):
TimerBase.__init__(self, *args, **kwargs)
# Create a new timer and connect the timeout() signal to the
# _on_timer method.
self._timer = QtCore.QTimer()
self._timer.timeout.connect(self._on_timer)
self._timer_set_interval()
TimerBase.__init__(self, *args, **kwargs)

def __del__(self):
# The check for deletedness is needed to avoid an error at animation
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ def _send_event(self, event_type, **kwargs):


class TimerTornado(backend_bases.TimerBase):
def __init__(self, *args, **kwargs):
self._timer = None
super().__init__(*args, **kwargs)

def _timer_start(self):
self._timer_stop()
if self._single:
Expand All @@ -510,7 +514,6 @@ def _timer_stop(self):
ioloop.remove_timeout(self._timer)
else:
self._timer.stop()

self._timer = None

def _timer_set_interval(self):
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class TimerWx(TimerBase):
"""Subclass of `.TimerBase` using wx.Timer events."""

def __init__(self, *args, **kwargs):
TimerBase.__init__(self, *args, **kwargs)
self._timer = wx.Timer()
self._timer.Notify = self._on_timer
TimerBase.__init__(self, *args, **kwargs)

def _timer_start(self):
self._timer.Start(self._interval, self._single)
Expand All @@ -81,7 +81,8 @@ def _timer_stop(self):
self._timer.Stop()

def _timer_set_interval(self):
self._timer_start()
if self._timer.IsRunning():
self._timer_start() # Restart with new interval.

def _timer_set_single_shot(self):
self._timer.Start()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def check_alt_backend(alt_backend):

ax.plot([0, 1], [2, 3])

timer = fig.canvas.new_timer(1)
timer = fig.canvas.new_timer(1.) # Test that floats are cast to int as needed.
timer.add_callback(FigureCanvasBase.key_press_event, fig.canvas, "q")
# Trigger quitting upon draw.
fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
Expand Down