Skip to content

Commit 2791451

Browse files
committed
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 matplotlib#4534.
1 parent 32a3292 commit 2791451

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
deprecated idle_event
2+
`````````````````````
3+
4+
The `idle_event` was broken or missing in most backends and causes spurious
5+
warnings in some cases, and its use in creating animations is now obsolete due
6+
to the animations module. Therefore code involving it has been removed from all
7+
but the wx backend (where it partially works), and its use is deprecated. The
8+
animations module may be used instead to create animations.
9+

examples/event_handling/idle_and_timeout.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"""
33
Demonstrate/test the idle and timeout API
44
5+
WARNING: idle_event is deprecated. Use the animations module instead.
6+
57
This is only tested on gtk so far and is a prototype implementation
68
"""
79
import numpy as np

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,10 @@ def on_press(event):
23312331
cid = canvas.mpl_connect('button_press_event', on_press)
23322332
23332333
"""
2334+
if s == 'idle_event':
2335+
warnings.warn("idle_event is only implemented for the wx backend, "
2336+
"and will be removed in matplotlib 2.1. Use the "
2337+
"animations module instead.", mplDeprecation)
23342338

23352339
return self.callbacks.connect(s, func)
23362340

lib/matplotlib/backends/backend_gtk.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,11 @@ def __init__(self, figure):
243243
self.set_flags(gtk.CAN_FOCUS)
244244
self._renderer_init()
245245

246-
self._idle_event_id = gobject.idle_add(self.idle_event)
247-
248246
self.last_downclick = {}
249247

250248
def destroy(self):
251249
#gtk.DrawingArea.destroy(self)
252250
self.close_event()
253-
gobject.source_remove(self._idle_event_id)
254251
if self._idle_draw_id != 0:
255252
gobject.source_remove(self._idle_draw_id)
256253

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,11 @@ def __init__(self, figure):
210210
self.set_double_buffered(True)
211211
self.set_can_focus(True)
212212
self._renderer_init()
213-
self._idle_event_id = GLib.idle_add(self.idle_event)
214213
default_context = GLib.main_context_get_thread_default() or GLib.main_context_default()
215-
self._idle_event_source = default_context.find_source_by_id(self._idle_event_id)
216214

217215
def destroy(self):
218216
#Gtk.DrawingArea.destroy(self)
219217
self.close_event()
220-
if not self._idle_event_source.is_destroyed():
221-
GLib.source_remove(self._idle_event_id)
222218
if self._idle_draw_id != 0:
223219
GLib.source_remove(self._idle_draw_id)
224220

lib/matplotlib/backends/backend_qt4.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ def __init__(self, figure):
7373
self.figure = figure
7474
self.setMouseTracking(True)
7575
self._idle = True
76-
# hide until we can test and fix
77-
# self.startTimer(backend_IdleEvent.milliseconds)
7876
w, h = self.get_width_height()
7977
self.resize(w, h)
8078

lib/matplotlib/backends/backend_qt5.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,9 @@ def __init__(self, figure):
240240
self.figure = figure
241241
self.setMouseTracking(True)
242242
self._idle = True
243-
# hide until we can test and fix
244-
# self.startTimer(backend_IdleEvent.milliseconds)
245243
w, h = self.get_width_height()
246244
self.resize(w, h)
247245

248-
def __timerEvent(self, event):
249-
# hide until we can test and fix
250-
self.mpl_idle_event(event)
251-
252246
def enterEvent(self, event):
253247
FigureCanvasBase.enter_notify_event(self, guiEvent=event)
254248

0 commit comments

Comments
 (0)