##// 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:
210 if self.pylab:
200 if self.pylab:
211 enable = shell.enable_pylab
201 gui, backend = pylabtools.find_gui_and_backend(self.pylab)
212 key = self.pylab
202 self.log.info("Enabling GUI event loop integration, "
213 elif self.matplotlib:
203 "toolkit=%s, pylab=%s" % (gui, self.pylab))
214 enable = shell.enable_matplotlib
204 if self.pylab == "auto":
215 key = self.matplotlib
205 print ("using matplotlib backend: %s" % backend)
216 elif self.gui:
206 shell.enable_pylab(self.pylab, import_all=self.pylab_import_all)
217 enable = shell.enable_gui
207 else:
218 key = self.gui
208 self.log.info("Enabling GUI event loop integration, "
219
209 "toolkit=%s" % self.gui)
220 if not enable:
210 shell.enable_gui(self.gui)
221 return
211 except ImportError:
222
212 self.log.warn("pylab mode doesn't work as matplotlib could not be found." + \
223 try:
213 "\nIs it installed on the system?")
224 r = enable(key)
214 self.shell.showtraceback()
225 except ImportError:
215 except Exception:
226 self.log.warn("Eventloop or matplotlib integration failed. Is matplotlib installed?")
216 self.log.warn("GUI event loop or pylab initialization failed")
227 self.shell.showtraceback()
217 self.shell.showtraceback()
228 return
229 except Exception:
230 self.log.warn("GUI event loop or pylab initialization failed")
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