Skip to content

Deprecate FigureCanvasMac.invalidate in favor of draw_idle. #14108

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 1 commit into from
May 3, 2019
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2019-05-01-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Deprecations
````````````

``FigureCanvasMac.invalidate`` is deprecated in favor of its synonym,
``FigureCanvasMac.draw_idle``.
21 changes: 9 additions & 12 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TimerBase)

from matplotlib.figure import Figure
from matplotlib import rcParams
from matplotlib import cbook, rcParams

from matplotlib.widgets import SubplotTool

Expand Down Expand Up @@ -83,15 +83,17 @@ def _draw(self):

def draw(self):
# docstring inherited
self.invalidate()
self.draw_idle()
self.flush_events()

def draw_idle(self, *args, **kwargs):
# docstring inherited
self.invalidate()
# draw_idle is provided by _macosx.FigureCanvas

@cbook.deprecated("3.2", alternative="draw_idle()")
def invalidate(self):
return self.draw_idle()

def blit(self, bbox=None):
self.invalidate()
self.draw_idle()

def resize(self, width, height):
dpi = self.figure.dpi
Expand Down Expand Up @@ -182,12 +184,7 @@ class _BackendMac(_Backend):

@staticmethod
def trigger_manager_draw(manager):
# For performance reasons, we don't want to redraw the figure after
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is true, but is not specific to the osx backend -- all interactive backends do the same.

# each draw command. Instead, we mark the figure as invalid, so that it
# will be redrawn as soon as the event loop resumes via PyOS_InputHook.
# This function should be called after each draw event, even if
# matplotlib is not running interactively.
manager.canvas.invalidate()
manager.canvas.draw_idle()

@staticmethod
def mainloop():
Expand Down
10 changes: 5 additions & 5 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static CGFloat _get_device_scale(CGContextRef cr)
}

static PyObject*
FigureCanvas_invalidate(FigureCanvas* self)
FigureCanvas_draw_idle(FigureCanvas* self)
{
View* view = self->view;
if(!view)
Expand Down Expand Up @@ -596,12 +596,12 @@ static CGFloat _get_device_scale(CGContextRef cr)
{"draw",
(PyCFunction)FigureCanvas_draw,
METH_NOARGS,
"Draws the canvas."
NULL, // docstring inherited.
},
{"invalidate",
(PyCFunction)FigureCanvas_invalidate,
{"draw_idle",
(PyCFunction)FigureCanvas_draw_idle,
METH_NOARGS,
"Invalidates the canvas."
NULL, // docstring inherited.
},
{"flush_events",
(PyCFunction)FigureCanvas_flush_events,
Expand Down