From 2791451b752abf4df7f965b2d43ccc01ed5853e5 Mon Sep 17 00:00:00 2001 From: Allan Haldane Date: Wed, 17 Jun 2015 13:58:01 -0400 Subject: [PATCH 1/2] MNT: Deprecate idle_event and remove it from all but wx backends This commit removes code related to `idle_event` in the gtk backend, where it caused spurious warnings, and adds a deprecation warning on any use of idle_event. Idle event still works in wx for now. Fixes #4534. --- doc/api/api_changes/2015-06-21_idle_event.rst | 9 +++++++++ examples/event_handling/idle_and_timeout.py | 2 ++ lib/matplotlib/backend_bases.py | 4 ++++ lib/matplotlib/backends/backend_gtk.py | 3 --- lib/matplotlib/backends/backend_gtk3.py | 4 ---- lib/matplotlib/backends/backend_qt4.py | 2 -- lib/matplotlib/backends/backend_qt5.py | 6 ------ 7 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 doc/api/api_changes/2015-06-21_idle_event.rst diff --git a/doc/api/api_changes/2015-06-21_idle_event.rst b/doc/api/api_changes/2015-06-21_idle_event.rst new file mode 100644 index 000000000000..1defdb4faa3f --- /dev/null +++ b/doc/api/api_changes/2015-06-21_idle_event.rst @@ -0,0 +1,9 @@ +deprecated idle_event +````````````````````` + +The `idle_event` was broken or missing in most backends and causes spurious +warnings in some cases, and its use in creating animations is now obsolete due +to the animations module. Therefore code involving it has been removed from all +but the wx backend (where it partially works), and its use is deprecated. The +animations module may be used instead to create animations. + diff --git a/examples/event_handling/idle_and_timeout.py b/examples/event_handling/idle_and_timeout.py index 4c22d02596c4..e89d0b696141 100644 --- a/examples/event_handling/idle_and_timeout.py +++ b/examples/event_handling/idle_and_timeout.py @@ -2,6 +2,8 @@ """ Demonstrate/test the idle and timeout API +WARNING: idle_event is deprecated. Use the animations module instead. + This is only tested on gtk so far and is a prototype implementation """ import numpy as np diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 513e1fdde487..4e927d53b7b0 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2331,6 +2331,10 @@ def on_press(event): cid = canvas.mpl_connect('button_press_event', on_press) """ + if s == 'idle_event': + warnings.warn("idle_event is only implemented for the wx backend, " + "and will be removed in matplotlib 2.1. Use the " + "animations module instead.", mplDeprecation) return self.callbacks.connect(s, func) diff --git a/lib/matplotlib/backends/backend_gtk.py b/lib/matplotlib/backends/backend_gtk.py index 1a6ee313f546..bca5a1300c77 100644 --- a/lib/matplotlib/backends/backend_gtk.py +++ b/lib/matplotlib/backends/backend_gtk.py @@ -243,14 +243,11 @@ def __init__(self, figure): self.set_flags(gtk.CAN_FOCUS) self._renderer_init() - self._idle_event_id = gobject.idle_add(self.idle_event) - self.last_downclick = {} def destroy(self): #gtk.DrawingArea.destroy(self) self.close_event() - gobject.source_remove(self._idle_event_id) if self._idle_draw_id != 0: gobject.source_remove(self._idle_draw_id) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 32d15fb4fbcc..6629ca61282b 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -210,15 +210,11 @@ def __init__(self, figure): self.set_double_buffered(True) self.set_can_focus(True) self._renderer_init() - self._idle_event_id = GLib.idle_add(self.idle_event) default_context = GLib.main_context_get_thread_default() or GLib.main_context_default() - self._idle_event_source = default_context.find_source_by_id(self._idle_event_id) def destroy(self): #Gtk.DrawingArea.destroy(self) self.close_event() - if not self._idle_event_source.is_destroyed(): - GLib.source_remove(self._idle_event_id) if self._idle_draw_id != 0: GLib.source_remove(self._idle_draw_id) diff --git a/lib/matplotlib/backends/backend_qt4.py b/lib/matplotlib/backends/backend_qt4.py index 8298ae368d98..d0facc419b56 100644 --- a/lib/matplotlib/backends/backend_qt4.py +++ b/lib/matplotlib/backends/backend_qt4.py @@ -73,8 +73,6 @@ def __init__(self, figure): self.figure = figure self.setMouseTracking(True) self._idle = True - # hide until we can test and fix - # self.startTimer(backend_IdleEvent.milliseconds) w, h = self.get_width_height() self.resize(w, h) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index e3e0624552fc..77646ef3496b 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -240,15 +240,9 @@ def __init__(self, figure): self.figure = figure self.setMouseTracking(True) self._idle = True - # hide until we can test and fix - # self.startTimer(backend_IdleEvent.milliseconds) w, h = self.get_width_height() self.resize(w, h) - def __timerEvent(self, event): - # hide until we can test and fix - self.mpl_idle_event(event) - def enterEvent(self, event): FigureCanvasBase.enter_notify_event(self, guiEvent=event) From d631dc17c8d4037fb359deefd8e607d2c0651f44 Mon Sep 17 00:00:00 2001 From: Allan Haldane Date: Tue, 23 Jun 2015 11:57:22 -0400 Subject: [PATCH 2/2] use warn_deprecated --- lib/matplotlib/backend_bases.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 4e927d53b7b0..440cb0bf68fb 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -60,7 +60,7 @@ import matplotlib.tight_bbox as tight_bbox import matplotlib.textpath as textpath from matplotlib.path import Path -from matplotlib.cbook import mplDeprecation +from matplotlib.cbook import mplDeprecation, warn_deprecated import matplotlib.backend_tools as tools try: @@ -2332,9 +2332,10 @@ def on_press(event): """ if s == 'idle_event': - warnings.warn("idle_event is only implemented for the wx backend, " - "and will be removed in matplotlib 2.1. Use the " - "animations module instead.", mplDeprecation) + warn_deprecated(1.5, + "idle_event is only implemented for the wx backend, and will " + "be removed in matplotlib 2.1. Use the animations module " + "instead.") return self.callbacks.connect(s, func)