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

Skip to content

Mnt direct call draw idle [WIP] #4849

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

Closed
Closed
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
12 changes: 11 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def _stale_figure_callback(self, val):
self.figure.stale = val


def _stale_canvas_callback(self, val):
if rcParams['interactive'] and self.canvas is not None and val:
self.canvas.draw_idle()


class AxesStack(Stack):
"""
Specialization of the Stack to handle all tracking of Axes in a Figure.
Expand Down Expand Up @@ -352,6 +357,11 @@ def __init__(self,
self._axstack = AxesStack() # track all figure axes and current axes
self.clf()
self._cachedRenderer = None
self.stale_callback = Figure._stale_callback

def _stale_callback(self, val):
if val and self.canvas is not None:
self.canvas.stale = val

# TODO: I'd like to dynamically add the _repr_html_ method
# to the figure in the right context, but then IPython doesn't
Expand Down Expand Up @@ -560,7 +570,7 @@ def set_canvas(self, canvas):
ACCEPTS: a FigureCanvas instance
"""
self.canvas = canvas
self.stale = True
self.stale_callback = _stale_canvas_callback

def hold(self, b=None):
"""
Expand Down
97 changes: 0 additions & 97 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,84 +108,6 @@ def _backend_selection():
from matplotlib.backends import pylab_setup
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()

_IP_REGISTERED = None
_INSTALL_FIG_OBSERVER = False

def install_repl_displayhook():
"""
Install a repl display hook so that any stale figure are automatically
redrawn when control is returned to the repl.

This works with both IPython terminals and vanilla python shells.
"""
global _IP_REGISTERED
global _INSTALL_FIG_OBSERVER

class _NotIPython(Exception):
pass

# see if we have IPython hooks around, if use them

try:
from IPython import get_ipython
ip = get_ipython()
if ip is None:
raise _NotIPython()

if _IP_REGISTERED:
return

def post_execute():
if matplotlib.is_interactive():
draw_all()

# IPython >= 2
try:
ip.events.register('post_execute', post_execute)
except AttributeError:
# IPython 1.x
ip.register_post_execute(post_execute)

_IP_REGISTERED = post_execute
_INSTALL_FIG_OBSERVER = False

# import failed or ipython is not running
except (ImportError, _NotIPython):
_INSTALL_FIG_OBSERVER = True


def uninstall_repl_displayhook():
"""
Uninstalls the matplotlib display hook.

.. warning

Need IPython >= 2 for this to work. For IPython < 2 will raise a
``NotImplementedError``

.. warning

If you are using vanilla python and have installed another
display hook this will reset ``sys.displayhook`` to what ever
function was there when matplotlib installed it's displayhook,
possibly discarding your changes.
"""
global _IP_REGISTERED
global _INSTALL_FIG_OBSERVER
if _IP_REGISTERED:
from IPython import get_ipython
ip = get_ipython()
try:
ip.events.unregister('post_execute', _IP_REGISTERED)
except AttributeError:
raise NotImplementedError("Can not unregister events "
"in IPython < 2.0")
_IP_REGISTERED = None

if _INSTALL_FIG_OBSERVER:
_INSTALL_FIG_OBSERVER = False


draw_all = _pylab_helpers.Gcf.draw_all


Expand Down Expand Up @@ -245,13 +167,11 @@ def isinteractive():
def ioff():
'Turn interactive mode off.'
matplotlib.interactive(False)
uninstall_repl_displayhook()


def ion():
'Turn interactive mode on.'
matplotlib.interactive(True)
install_repl_displayhook()


def pause(interval):
Expand Down Expand Up @@ -532,16 +452,6 @@ def make_active(event):
fig = figManager.canvas.figure
fig.number = num

# make sure backends (inline) that we don't ship that expect this
# to be called in plotting commands to make the figure call show
# still work. There is probably a better way to do this in the
# FigureManager base class.
if matplotlib.is_interactive():
draw_if_interactive()

if _INSTALL_FIG_OBSERVER:
fig.stale_callback = _auto_draw_if_interactive

return figManager.canvas.figure


Expand Down Expand Up @@ -2494,13 +2404,6 @@ def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', hold=None,
sci(ret)
return ret

# just to be safe. Interactive mode can be turned on without
# calling `plt.ion()` so register it again here.
# This is safe because multiple calls to `install_repl_displayhook`
# are no-ops and the registered function respect `mpl.is_interactive()`
# to determine if they should trigger a draw.
install_repl_displayhook()

################# REMAINING CONTENT GENERATED BY boilerplate.py ##############


Expand Down