From 4270fd09e3376322eb36e12fea8331e0d0df1b63 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 6 Jul 2018 23:34:34 +0200 Subject: [PATCH] Don't associate Wx timers with the parent frame. This is consistent with the behavior on Qt and GTK, and avoids a segfault due to lack of disconnection of the timer after the parent widget is destroyed (otherwise, we'd need to keep track of timers associated with each widget and tear them down when the widget is destroyed). --- .../2018-02-15-AL-deprecations.rst | 3 +++ lib/matplotlib/backends/backend_wx.py | 25 +++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/doc/api/next_api_changes/2018-02-15-AL-deprecations.rst b/doc/api/next_api_changes/2018-02-15-AL-deprecations.rst index a34615e18dee..0fcf8fb909b7 100644 --- a/doc/api/next_api_changes/2018-02-15-AL-deprecations.rst +++ b/doc/api/next_api_changes/2018-02-15-AL-deprecations.rst @@ -48,3 +48,6 @@ The following rcParams are deprecated: The following keyword arguments are deprecated: - passing ``verts`` to ``Axes.scatter`` (use ``marker`` instead), - passing ``obj_type`` to ``cbook.deprecated``, + +The following call signatures are deprecated: +- passing a ``wx.EvtHandler`` as first argument to ``backend_wx.TimerWx``, diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 657e543f45c3..986b40806b0a 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -118,19 +118,15 @@ class TimerWx(TimerBase): ''' - def __init__(self, parent, *args, **kwargs): + def __init__(self, *args, **kwargs): + if isinstance(args[0], wx.EvtHandler): + cbook.warn_deprecated( + "3.0", "Passing a wx.EvtHandler as first argument to the " + "TimerWx constructor is deprecated since %(version)s.") + args = args[1:] TimerBase.__init__(self, *args, **kwargs) - - # Create a new timer and connect the timer event to our handler. - # For WX, the events have to use a widget for binding. - self.parent = parent - self._timer = wx.Timer(self.parent, wx.NewId()) - self.parent.Bind(wx.EVT_TIMER, self._on_timer, self._timer) - - # Unbinding causes Wx to stop for some reason. Disabling for now. -# def __del__(self): -# TimerBase.__del__(self) -# self.parent.Bind(wx.EVT_TIMER, None, self._timer) + self._timer = wx.Timer() + self._timer.Notify = self._on_timer def _timer_start(self): self._timer.Start(self._interval, self._single) @@ -144,9 +140,6 @@ def _timer_set_interval(self): def _timer_set_single_shot(self): self._timer.Start() - def _on_timer(self, *args): - TimerBase._on_timer(self) - class RendererWx(RendererBase): """ @@ -704,7 +697,7 @@ def new_timer(self, *args, **kwargs): will be executed by the timer every *interval*. """ - return TimerWx(self, *args, **kwargs) + return TimerWx(*args, **kwargs) def flush_events(self): wx.Yield()