Show More
@@ -422,6 +422,9 b' class InteractiveShell(SingletonConfigurable):' | |||||
422 | # Private interface |
|
422 | # Private interface | |
423 | _post_execute = Instance(dict) |
|
423 | _post_execute = Instance(dict) | |
424 |
|
424 | |||
|
425 | # Tracks any GUI loop loaded for pylab | |||
|
426 | pylab_gui_select = None | |||
|
427 | ||||
425 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, |
|
428 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, | |
426 | user_module=None, user_ns=None, |
|
429 | user_module=None, user_ns=None, | |
427 | custom_exceptions=((), None)): |
|
430 | custom_exceptions=((), None)): |
@@ -174,13 +174,16 b' def select_figure_format(shell, fmt):' | |||||
174 | #----------------------------------------------------------------------------- |
|
174 | #----------------------------------------------------------------------------- | |
175 |
|
175 | |||
176 |
|
176 | |||
177 | def find_gui_and_backend(gui=None): |
|
177 | def find_gui_and_backend(gui=None, gui_select=None): | |
178 | """Given a gui string return the gui and mpl backend. |
|
178 | """Given a gui string return the gui and mpl backend. | |
179 |
|
179 | |||
180 | Parameters |
|
180 | Parameters | |
181 | ---------- |
|
181 | ---------- | |
182 | gui : str |
|
182 | gui : str | |
183 | Can be one of ('tk','gtk','wx','qt','qt4','inline'). |
|
183 | Can be one of ('tk','gtk','wx','qt','qt4','inline'). | |
|
184 | gui_select : str | |||
|
185 | Can be one of ('tk','gtk','wx','qt','qt4','inline'). | |||
|
186 | This is any gui already selected by the shell. | |||
184 |
|
187 | |||
185 | Returns |
|
188 | Returns | |
186 | ------- |
|
189 | ------- | |
@@ -198,6 +201,13 b' def find_gui_and_backend(gui=None):' | |||||
198 | # In this case, we need to find what the appropriate gui selection call |
|
201 | # In this case, we need to find what the appropriate gui selection call | |
199 | # should be for IPython, so we can activate inputhook accordingly |
|
202 | # should be for IPython, so we can activate inputhook accordingly | |
200 | gui = backend2gui.get(backend, None) |
|
203 | gui = backend2gui.get(backend, None) | |
|
204 | ||||
|
205 | # If we have already had a gui active, we need it and inline are the | |||
|
206 | # ones allowed. | |||
|
207 | if gui_select and gui != gui_select: | |||
|
208 | gui = gui_select | |||
|
209 | backend = backends[gui] | |||
|
210 | ||||
201 | return gui, backend |
|
211 | return gui, backend | |
202 |
|
212 | |||
203 |
|
213 | |||
@@ -330,7 +340,18 b' def pylab_activate(user_ns, gui=None, import_all=True, shell=None):' | |||||
330 | The actual gui used (if not given as input, it was obtained from matplotlib |
|
340 | The actual gui used (if not given as input, it was obtained from matplotlib | |
331 | itself, and will be needed next to configure IPython's gui integration. |
|
341 | itself, and will be needed next to configure IPython's gui integration. | |
332 | """ |
|
342 | """ | |
333 | gui, backend = find_gui_and_backend(gui) |
|
343 | pylab_gui_select = shell.pylab_gui_select if shell is not None else None | |
|
344 | # Try to find the appropriate gui and backend for the settings | |||
|
345 | gui, backend = find_gui_and_backend(gui, pylab_gui_select) | |||
|
346 | if shell is not None and gui != 'inline': | |||
|
347 | # If we have our first gui selection, store it | |||
|
348 | if pylab_gui_select is None: | |||
|
349 | shell.pylab_gui_select = gui | |||
|
350 | # Otherwise if they are different | |||
|
351 | elif gui != pylab_gui_select: | |||
|
352 | print ('Warning: Cannot change to a different GUI toolkit: %s.' | |||
|
353 | ' Using %s instead.' % (gui, pylab_gui_select)) | |||
|
354 | gui, backend = find_gui_and_backend(pylab_gui_select) | |||
334 | activate_matplotlib(backend) |
|
355 | activate_matplotlib(backend) | |
335 | import_pylab(user_ns, import_all) |
|
356 | import_pylab(user_ns, import_all) | |
336 | if shell is not None: |
|
357 | if shell is not None: |
General Comments 0
You need to be logged in to leave comments.
Login now