Skip to content

Commit c4aebac

Browse files
Merge pull request #11590 from anntzer/parentlesswxtimers
Don't associate Wx timers with the parent frame.
2 parents 60e3180 + 4270fd0 commit c4aebac

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ The following rcParams are deprecated:
4949
The following keyword arguments are deprecated:
5050
- passing ``verts`` to ``Axes.scatter`` (use ``marker`` instead),
5151
- passing ``obj_type`` to ``cbook.deprecated``,
52+
53+
The following call signatures are deprecated:
54+
- passing a ``wx.EvtHandler`` as first argument to ``backend_wx.TimerWx``,

lib/matplotlib/backends/backend_wx.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,15 @@ class TimerWx(TimerBase):
120120
121121
'''
122122

123-
def __init__(self, parent, *args, **kwargs):
123+
def __init__(self, *args, **kwargs):
124+
if isinstance(args[0], wx.EvtHandler):
125+
cbook.warn_deprecated(
126+
"3.0", "Passing a wx.EvtHandler as first argument to the "
127+
"TimerWx constructor is deprecated since %(version)s.")
128+
args = args[1:]
124129
TimerBase.__init__(self, *args, **kwargs)
125-
126-
# Create a new timer and connect the timer event to our handler.
127-
# For WX, the events have to use a widget for binding.
128-
self.parent = parent
129-
self._timer = wx.Timer(self.parent, wx.NewId())
130-
self.parent.Bind(wx.EVT_TIMER, self._on_timer, self._timer)
131-
132-
# Unbinding causes Wx to stop for some reason. Disabling for now.
133-
# def __del__(self):
134-
# TimerBase.__del__(self)
135-
# self.parent.Bind(wx.EVT_TIMER, None, self._timer)
130+
self._timer = wx.Timer()
131+
self._timer.Notify = self._on_timer
136132

137133
def _timer_start(self):
138134
self._timer.Start(self._interval, self._single)
@@ -146,9 +142,6 @@ def _timer_set_interval(self):
146142
def _timer_set_single_shot(self):
147143
self._timer.Start()
148144

149-
def _on_timer(self, *args):
150-
TimerBase._on_timer(self)
151-
152145

153146
class RendererWx(RendererBase):
154147
"""
@@ -706,7 +699,7 @@ def new_timer(self, *args, **kwargs):
706699
will be executed by the timer every *interval*.
707700
708701
"""
709-
return TimerWx(self, *args, **kwargs)
702+
return TimerWx(*args, **kwargs)
710703

711704
def flush_events(self):
712705
wx.Yield()

0 commit comments

Comments
 (0)