Skip to content

Commit 27e9c2b

Browse files
committed
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).
1 parent 5211ed8 commit 27e9c2b

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
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
@@ -48,3 +48,6 @@ The following rcParams are deprecated:
4848
The following keyword arguments are deprecated:
4949
- passing ``verts`` to ``Axes.scatter`` (use ``marker`` instead),
5050
- passing ``obj_type`` to ``cbook.deprecated``,
51+
52+
The following call signatures are deprecated:
53+
- 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
@@ -118,19 +118,15 @@ class TimerWx(TimerBase):
118118
119119
'''
120120

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

135131
def _timer_start(self):
136132
self._timer.Start(self._interval, self._single)
@@ -144,9 +140,6 @@ def _timer_set_interval(self):
144140
def _timer_set_single_shot(self):
145141
self._timer.Start()
146142

147-
def _on_timer(self, *args):
148-
TimerBase._on_timer(self)
149-
150143

151144
class RendererWx(RendererBase):
152145
"""
@@ -704,7 +697,7 @@ def new_timer(self, *args, **kwargs):
704697
will be executed by the timer every *interval*.
705698
706699
"""
707-
return TimerWx(self, *args, **kwargs)
700+
return TimerWx(*args, **kwargs)
708701

709702
def flush_events(self):
710703
wx.Yield()

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ def _get_testable_interactive_backends():
2222
(["PyQt5"], "qt5agg"),
2323
(["cairocffi", "PyQt5"], "qt5cairo"),
2424
(["tkinter"], "tkagg"),
25-
(["wx"], "wx"),
2625
(["wx"], "wxagg")]:
2726
reason = None
2827
if not os.environ.get("DISPLAY"):
2928
reason = "No $DISPLAY"
3029
elif any(importlib.util.find_spec(dep) is None for dep in deps):
3130
reason = "Missing dependency"
32-
elif "wx" in deps and sys.platform == "darwin":
33-
reason = "wx backends known not to work on OSX"
3431
backends.append(pytest.mark.skip(reason=reason)(backend) if reason
3532
else backend)
3633
return backends

0 commit comments

Comments
 (0)