##// END OF EJS Templates
add `--matplotlib` flag to terminal IPython...
MinRK -
Show More
@@ -103,6 +103,11 b" shell_flags['pylab'] = ("
103 """Pre-load matplotlib and numpy for interactive use with
103 """Pre-load matplotlib and numpy for interactive use with
104 the default matplotlib backend."""
104 the default matplotlib backend."""
105 )
105 )
106 shell_flags['matplotlib'] = (
107 {'InteractiveShellApp' : {'matplotlib' : 'auto'}},
108 """Configure matplotlib for interactive use with
109 the default matplotlib backend."""
110 )
106
111
107 # it's possible we don't want short aliases for *all* of these:
112 # it's possible we don't want short aliases for *all* of these:
108 shell_aliases = dict(
113 shell_aliases = dict(
@@ -115,6 +120,7 b' shell_aliases = dict('
115 ext='InteractiveShellApp.extra_extension',
120 ext='InteractiveShellApp.extra_extension',
116 gui='InteractiveShellApp.gui',
121 gui='InteractiveShellApp.gui',
117 pylab='InteractiveShellApp.pylab',
122 pylab='InteractiveShellApp.pylab',
123 matplotlib='InteractiveShellApp.matplotlib',
118 )
124 )
119 shell_aliases['cache-size'] = 'InteractiveShell.cache_size'
125 shell_aliases['cache-size'] = 'InteractiveShell.cache_size'
120
126
@@ -169,6 +175,11 b' class InteractiveShellApp(Configurable):'
169 gui = CaselessStrEnum(('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx'), config=True,
175 gui = CaselessStrEnum(('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx'), config=True,
170 help="Enable GUI event loop integration ('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx')."
176 help="Enable GUI event loop integration ('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx')."
171 )
177 )
178 matplotlib = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'inline', 'auto'],
179 config=True,
180 help="""Configure matplotlib for interactive use with
181 the default matplotlib backend."""
182 )
172 pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'inline', 'auto'],
183 pylab = CaselessStrEnum(['tk', 'qt', 'wx', 'gtk', 'osx', 'inline', 'auto'],
173 config=True,
184 config=True,
174 help="""Pre-load matplotlib and numpy for interactive use,
185 help="""Pre-load matplotlib and numpy for interactive use,
@@ -194,27 +205,42 b' class InteractiveShellApp(Configurable):'
194
205
195 def init_gui_pylab(self):
206 def init_gui_pylab(self):
196 """Enable GUI event loop integration, taking pylab into account."""
207 """Enable GUI event loop integration, taking pylab into account."""
197 if self.gui or self.pylab:
208 enable = False
198 shell = self.shell
209 shell = self.shell
199 try:
200 if self.pylab:
210 if self.pylab:
201 gui, backend = pylabtools.find_gui_and_backend(self.pylab)
211 enable = shell.enable_pylab
202 self.log.info("Enabling GUI event loop integration, "
212 key = self.pylab
203 "toolkit=%s, pylab=%s" % (gui, self.pylab))
213 elif self.matplotlib:
204 if self.pylab == "auto":
214 enable = shell.enable_matplotlib
205 print ("using matplotlib backend: %s" % backend)
215 key = self.matplotlib
206 shell.enable_pylab(self.pylab, import_all=self.pylab_import_all)
216 elif self.gui:
207 else:
217 enable = shell.enable_gui
208 self.log.info("Enabling GUI event loop integration, "
218 key = self.gui
209 "toolkit=%s" % self.gui)
219
210 shell.enable_gui(self.gui)
220 if not enable:
221 return
222
223 try:
224 r = enable(key)
211 except ImportError:
225 except ImportError:
212 self.log.warn("pylab mode doesn't work as matplotlib could not be found." + \
226 self.log.warn("Eventloop or matplotlib integration failed. Is matplotlib installed?")
213 "\nIs it installed on the system?")
214 self.shell.showtraceback()
227 self.shell.showtraceback()
228 return
215 except Exception:
229 except Exception:
216 self.log.warn("GUI event loop or pylab initialization failed")
230 self.log.warn("GUI event loop or pylab initialization failed")
217 self.shell.showtraceback()
231 self.shell.showtraceback()
232 return
233
234 if isinstance(r, tuple):
235 gui, backend = r[:2]
236 self.log.info("Enabling GUI event loop integration, "
237 "eventloop=%s, matplotlib=%s", gui, backend)
238 if key == "auto":
239 print ("using matplotlib backend: %s" % backend)
240 else:
241 gui = r
242 self.log.info("Enabling GUI event loop integration, "
243 "eventloop=%s", gui)
218
244
219 def init_extensions(self):
245 def init_extensions(self):
220 """Load all IPython extensions in IPythonApp.extensions.
246 """Load all IPython extensions in IPythonApp.extensions.
General Comments 0
You need to be logged in to leave comments. Login now