Skip to content

Remove start_event_loop_default. Let pause() run the event loop for all backends. #8867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 21 additions & 45 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2426,55 +2426,27 @@ def new_timer(self, *args, **kwargs):
return TimerBase(*args, **kwargs)

def flush_events(self):
"""
Flush the GUI events for the figure. Implemented only for
backends with GUIs.
"""
raise NotImplementedError
"""Flush the GUI events for the figure.

def start_event_loop(self, timeout):
Interactive backends need to reimplement this method.
"""
Start an event loop. This is used to start a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events. This should not be
confused with the main GUI event loop, which is always running
and has nothing to do with this.

This is implemented only for backends with GUIs.
"""
raise NotImplementedError
def start_event_loop(self, timeout=0):
"""Start a blocking event loop.

def stop_event_loop(self):
"""
Stop an event loop. This is used to stop a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events.
Such an event loop is used by interactive functions, such as `ginput`
and `waitforbuttonpress`, to wait for events.

This is implemented only for backends with GUIs.
"""
raise NotImplementedError
The event loop blocks until a callback function triggers
`stop_event_loop`, or *timeout* is reached.

def start_event_loop_default(self, timeout=0):
"""
Start an event loop. This is used to start a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events. This should not be
confused with the main GUI event loop, which is always running
and has nothing to do with this.
If *timeout* is negative, never timeout.

This function provides default event loop functionality based
on time.sleep that is meant to be used until event loop
functions for each of the GUI backends can be written. As
such, it throws a deprecated warning.
Only interactive backends need to reimplement this method and it relies
on `flush_events` being properly implemented.

This call blocks until a callback function triggers
stop_event_loop() or *timeout* is reached. If *timeout* is
<=0, never timeout.
Interactive backends should implement this in a more native way.
"""
str = "Using default event loop until function specific"
str += " to this GUI is implemented"
warnings.warn(str, mplDeprecation)

if timeout <= 0:
timeout = np.inf
timestep = 0.01
Expand All @@ -2485,15 +2457,19 @@ def start_event_loop_default(self, timeout=0):
time.sleep(timestep)
counter += 1

def stop_event_loop_default(self):
"""
Stop an event loop. This is used to stop a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events.
def stop_event_loop(self):
"""Stop the current blocking event loop.

Interactive backends need to reimplement this to match
`start_event_loop`
"""
self._looping = False

start_event_loop_default = cbook.deprecated(
"2.1", name="start_event_loop_default")(start_event_loop)
stop_event_loop_default = cbook.deprecated(
"2.1", name="stop_event_loop_default")(stop_event_loop)


def key_press_handler(event, canvas, toolbar=None):
"""
Expand Down
7 changes: 0 additions & 7 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,6 @@ def flush_events(self):
gtk.gdk.flush()
gtk.gdk.threads_leave()

def start_event_loop(self,timeout):
FigureCanvasBase.start_event_loop_default(self,timeout)
start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__


class FigureManagerGTK(FigureManagerBase):
Expand Down
8 changes: 0 additions & 8 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,6 @@ def flush_events(self):
Gdk.flush()
Gdk.threads_leave()

def start_event_loop(self,timeout):
FigureCanvasBase.start_event_loop_default(self,timeout)
start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__


class FigureManagerGTK3(FigureManagerBase):
"""
Expand Down
8 changes: 0 additions & 8 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,6 @@ def new_timer(self, *args, **kwargs):
def flush_events(self):
self._master.update()

def start_event_loop(self,timeout):
FigureCanvasBase.start_event_loop_default(self,timeout)
start_event_loop.__doc__=FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__


class FigureManagerTkAgg(FigureManagerBase):
"""
Expand Down
11 changes: 0 additions & 11 deletions lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ def show(self):
def new_timer(self, *args, **kwargs):
return TimerTornado(*args, **kwargs)

def start_event_loop(self, timeout):
backend_bases.FigureCanvasBase.start_event_loop_default(
self, timeout)
start_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
backend_bases.FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__


class WebAggApplication(tornado.web.Application):
initialized = False
Expand Down
11 changes: 0 additions & 11 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,6 @@ def handle_set_dpi_ratio(self, event):
def send_event(self, event_type, **kwargs):
self.manager._send_event(event_type, **kwargs)

def start_event_loop(self, timeout):
backend_bases.FigureCanvasBase.start_event_loop_default(
self, timeout)
start_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.start_event_loop_default.__doc__

def stop_event_loop(self):
backend_bases.FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__ = \
backend_bases.FigureCanvasBase.stop_event_loop_default.__doc__


_JQUERY_ICON_CLASSES = {
'home': 'ui-icon ui-icon-home',
Expand Down
42 changes: 16 additions & 26 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def _backend_selection():
loop, and if not switches to a compatible one.
"""
backend = rcParams['backend']
if not rcParams['backend_fallback'] or \
backend not in _interactive_bk:
if not rcParams['backend_fallback'] or backend not in _interactive_bk:
return
is_agg_backend = rcParams['backend'].endswith('Agg')
if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
Expand Down Expand Up @@ -275,33 +274,24 @@ def pause(interval):
"""
Pause for *interval* seconds.

If there is an active figure it will be updated and displayed,
and the GUI event loop will run during the pause.
If there is an active figure, it will be updated and displayed before the
pause, and the GUI event loop (if any) will run during the pause.

If there is no active figure, or if a non-interactive backend
is in use, this executes time.sleep(interval).

This can be used for crude animation. For more complex
animation, see :mod:`matplotlib.animation`.

This function is experimental; its behavior may be changed
or extended in a future release.
This can be used for crude animation. For more complex animation, see
:mod:`matplotlib.animation`.

This function is experimental; its behavior may be changed or extended in a
future release.
"""
backend = rcParams['backend']
if backend in _interactive_bk:
figManager = _pylab_helpers.Gcf.get_active()
if figManager is not None:
canvas = figManager.canvas
if canvas.figure.stale:
canvas.draw_idle()
show(block=False)
canvas.start_event_loop(interval)
return

# No on-screen figure is active, so sleep() is all we need.
import time
time.sleep(interval)
manager = _pylab_helpers.Gcf.get_active()
if manager is not None:
canvas = manager.canvas
if canvas.figure.stale:
canvas.draw_idle()
show(block=False)
canvas.start_event_loop(interval)
else:
time.sleep(interval)


@docstring.copy_dedent(matplotlib.rc)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy