Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35af6c0

Browse files
efiringtacaswell
authored andcommitted
Merge pull request #8867 from anntzer/eventloop
Remove start_event_loop_default. Let pause() run the event loop for all backends.
1 parent c7107cd commit 35af6c0

File tree

7 files changed

+37
-116
lines changed

7 files changed

+37
-116
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,55 +2414,27 @@ def new_timer(self, *args, **kwargs):
24142414
return TimerBase(*args, **kwargs)
24152415

24162416
def flush_events(self):
2417-
"""
2418-
Flush the GUI events for the figure. Implemented only for
2419-
backends with GUIs.
2420-
"""
2421-
raise NotImplementedError
2417+
"""Flush the GUI events for the figure.
24222418
2423-
def start_event_loop(self, timeout):
2419+
Interactive backends need to reimplement this method.
24242420
"""
2425-
Start an event loop. This is used to start a blocking event
2426-
loop so that interactive functions, such as ginput and
2427-
waitforbuttonpress, can wait for events. This should not be
2428-
confused with the main GUI event loop, which is always running
2429-
and has nothing to do with this.
24302421

2431-
This is implemented only for backends with GUIs.
2432-
"""
2433-
raise NotImplementedError
2422+
def start_event_loop(self, timeout=0):
2423+
"""Start a blocking event loop.
24342424
2435-
def stop_event_loop(self):
2436-
"""
2437-
Stop an event loop. This is used to stop a blocking event
2438-
loop so that interactive functions, such as ginput and
2439-
waitforbuttonpress, can wait for events.
2425+
Such an event loop is used by interactive functions, such as `ginput`
2426+
and `waitforbuttonpress`, to wait for events.
24402427
2441-
This is implemented only for backends with GUIs.
2442-
"""
2443-
raise NotImplementedError
2428+
The event loop blocks until a callback function triggers
2429+
`stop_event_loop`, or *timeout* is reached.
24442430
2445-
def start_event_loop_default(self, timeout=0):
2446-
"""
2447-
Start an event loop. This is used to start a blocking event
2448-
loop so that interactive functions, such as ginput and
2449-
waitforbuttonpress, can wait for events. This should not be
2450-
confused with the main GUI event loop, which is always running
2451-
and has nothing to do with this.
2431+
If *timeout* is negative, never timeout.
24522432
2453-
This function provides default event loop functionality based
2454-
on time.sleep that is meant to be used until event loop
2455-
functions for each of the GUI backends can be written. As
2456-
such, it throws a deprecated warning.
2433+
Only interactive backends need to reimplement this method and it relies
2434+
on `flush_events` being properly implemented.
24572435
2458-
This call blocks until a callback function triggers
2459-
stop_event_loop() or *timeout* is reached. If *timeout* is
2460-
<=0, never timeout.
2436+
Interactive backends should implement this in a more native way.
24612437
"""
2462-
str = "Using default event loop until function specific"
2463-
str += " to this GUI is implemented"
2464-
warnings.warn(str, mplDeprecation)
2465-
24662438
if timeout <= 0:
24672439
timeout = np.inf
24682440
timestep = 0.01
@@ -2473,15 +2445,19 @@ def start_event_loop_default(self, timeout=0):
24732445
time.sleep(timestep)
24742446
counter += 1
24752447

2476-
def stop_event_loop_default(self):
2477-
"""
2478-
Stop an event loop. This is used to stop a blocking event
2479-
loop so that interactive functions, such as ginput and
2480-
waitforbuttonpress, can wait for events.
2448+
def stop_event_loop(self):
2449+
"""Stop the current blocking event loop.
24812450
2451+
Interactive backends need to reimplement this to match
2452+
`start_event_loop`
24822453
"""
24832454
self._looping = False
24842455

2456+
start_event_loop_default = cbook.deprecated(
2457+
"2.1", name="start_event_loop_default")(start_event_loop)
2458+
stop_event_loop_default = cbook.deprecated(
2459+
"2.1", name="stop_event_loop_default")(stop_event_loop)
2460+
24852461

24862462
def key_press_handler(event, canvas, toolbar=None):
24872463
"""

lib/matplotlib/backends/backend_gtk.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,6 @@ def flush_events(self):
480480
gtk.gdk.flush()
481481
gtk.gdk.threads_leave()
482482

483-
def start_event_loop(self,timeout):
484-
FigureCanvasBase.start_event_loop_default(self,timeout)
485-
start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__
486-
487-
def stop_event_loop(self):
488-
FigureCanvasBase.stop_event_loop_default(self)
489-
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
490483

491484

492485
class FigureManagerGTK(FigureManagerBase):

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,6 @@ def flush_events(self):
333333
Gdk.flush()
334334
Gdk.threads_leave()
335335

336-
def start_event_loop(self,timeout):
337-
FigureCanvasBase.start_event_loop_default(self,timeout)
338-
start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__
339-
340-
def stop_event_loop(self):
341-
FigureCanvasBase.stop_event_loop_default(self)
342-
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
343-
344336

345337
class FigureManagerGTK3(FigureManagerBase):
346338
"""

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,6 @@ def new_timer(self, *args, **kwargs):
464464
def flush_events(self):
465465
self._master.update()
466466

467-
def start_event_loop(self,timeout):
468-
FigureCanvasBase.start_event_loop_default(self,timeout)
469-
start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__
470-
471-
def stop_event_loop(self):
472-
FigureCanvasBase.stop_event_loop_default(self)
473-
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
474-
475467

476468
class FigureManagerTkAgg(FigureManagerBase):
477469
"""

lib/matplotlib/backends/backend_webagg.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ def show(self):
5959
def new_timer(self, *args, **kwargs):
6060
return TimerTornado(*args, **kwargs)
6161

62-
def start_event_loop(self, timeout):
63-
backend_bases.FigureCanvasBase.start_event_loop_default(
64-
self, timeout)
65-
start_event_loop.__doc__ = \
66-
backend_bases.FigureCanvasBase.start_event_loop_default.__doc__
67-
68-
def stop_event_loop(self):
69-
backend_bases.FigureCanvasBase.stop_event_loop_default(self)
70-
stop_event_loop.__doc__ = \
71-
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__
72-
7362

7463
class WebAggApplication(tornado.web.Application):
7564
initialized = False

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,6 @@ def handle_set_dpi_ratio(self, event):
359359
def send_event(self, event_type, **kwargs):
360360
self.manager._send_event(event_type, **kwargs)
361361

362-
def start_event_loop(self, timeout):
363-
backend_bases.FigureCanvasBase.start_event_loop_default(
364-
self, timeout)
365-
start_event_loop.__doc__ = \
366-
backend_bases.FigureCanvasBase.start_event_loop_default.__doc__
367-
368-
def stop_event_loop(self):
369-
backend_bases.FigureCanvasBase.stop_event_loop_default(self)
370-
stop_event_loop.__doc__ = \
371-
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__
372-
373362

374363
_JQUERY_ICON_CLASSES = {
375364
'home': 'ui-icon ui-icon-home',

lib/matplotlib/pyplot.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def _backend_selection():
7575
loop, and if not switches to a compatible one.
7676
"""
7777
backend = rcParams['backend']
78-
if not rcParams['backend_fallback'] or \
79-
backend not in _interactive_bk:
78+
if not rcParams['backend_fallback'] or backend not in _interactive_bk:
8079
return
8180
is_agg_backend = rcParams['backend'].endswith('Agg')
8281
if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
@@ -275,33 +274,24 @@ def pause(interval):
275274
"""
276275
Pause for *interval* seconds.
277276
278-
If there is an active figure it will be updated and displayed,
279-
and the GUI event loop will run during the pause.
277+
If there is an active figure, it will be updated and displayed before the
278+
pause, and the GUI event loop (if any) will run during the pause.
280279
281-
If there is no active figure, or if a non-interactive backend
282-
is in use, this executes time.sleep(interval).
283-
284-
This can be used for crude animation. For more complex
285-
animation, see :mod:`matplotlib.animation`.
286-
287-
This function is experimental; its behavior may be changed
288-
or extended in a future release.
280+
This can be used for crude animation. For more complex animation, see
281+
:mod:`matplotlib.animation`.
289282
283+
This function is experimental; its behavior may be changed or extended in a
284+
future release.
290285
"""
291-
backend = rcParams['backend']
292-
if backend in _interactive_bk:
293-
figManager = _pylab_helpers.Gcf.get_active()
294-
if figManager is not None:
295-
canvas = figManager.canvas
296-
if canvas.figure.stale:
297-
canvas.draw_idle()
298-
show(block=False)
299-
canvas.start_event_loop(interval)
300-
return
301-
302-
# No on-screen figure is active, so sleep() is all we need.
303-
import time
304-
time.sleep(interval)
286+
manager = _pylab_helpers.Gcf.get_active()
287+
if manager is not None:
288+
canvas = manager.canvas
289+
if canvas.figure.stale:
290+
canvas.draw_idle()
291+
show(block=False)
292+
canvas.start_event_loop(interval)
293+
else:
294+
time.sleep(interval)
305295

306296

307297
@docstring.copy_dedent(matplotlib.rc)

0 commit comments

Comments
 (0)