MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / install_repl_displayhook

Function install_repl_displayhook

site-packages/matplotlib/pyplot.py:82–132  ·  view source on GitHub ↗

Install a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl. This works both with IPython and with vanilla python shells.

()

Source from the content-addressed store, hash-verified

80
81
82def install_repl_displayhook():
83 """
84 Install a repl display hook so that any stale figure are automatically
85 redrawn when control is returned to the repl.
86
87 This works both with IPython and with vanilla python shells.
88 """
89 global _IP_REGISTERED
90 global _INSTALL_FIG_OBSERVER
91
92 class _NotIPython(Exception):
93 pass
94
95 # see if we have IPython hooks around, if use them
96
97 try:
98 if 'IPython' in sys.modules:
99 from IPython import get_ipython
100 ip = get_ipython()
101 if ip is None:
102 raise _NotIPython()
103
104 if _IP_REGISTERED:
105 return
106
107 def post_execute():
108 if matplotlib.is_interactive():
109 draw_all()
110
111 # IPython >= 2
112 try:
113 ip.events.register('post_execute', post_execute)
114 except AttributeError:
115 # IPython 1.x
116 ip.register_post_execute(post_execute)
117
118 _IP_REGISTERED = post_execute
119 _INSTALL_FIG_OBSERVER = False
120
121 # trigger IPython's eventloop integration, if available
122 from IPython.core.pylabtools import backend2gui
123
124 ipython_gui_name = backend2gui.get(get_backend())
125 if ipython_gui_name:
126 ip.enable_gui(ipython_gui_name)
127 else:
128 _INSTALL_FIG_OBSERVER = True
129
130 # import failed or ipython is not running
131 except (ImportError, _NotIPython):
132 _INSTALL_FIG_OBSERVER = True
133
134
135def uninstall_repl_displayhook():

Callers 2

ionFunction · 0.85
pyplot.pyFile · 0.85

Calls 4

get_backendFunction · 0.90
_NotIPythonClass · 0.85
registerMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected