Show More
@@ -0,0 +1,108 b'' | |||
|
1 | { | |
|
2 | "metadata": { | |
|
3 | "name": "Pylab Switching" | |
|
4 | }, | |
|
5 | "nbformat": 3, | |
|
6 | "nbformat_minor": 0, | |
|
7 | "worksheets": [ | |
|
8 | { | |
|
9 | "cells": [ | |
|
10 | { | |
|
11 | "cell_type": "code", | |
|
12 | "collapsed": false, | |
|
13 | "input": [ | |
|
14 | "# Should pop up a GUI window\n", | |
|
15 | "%pylab qt\n", | |
|
16 | "plot([1,2,3])" | |
|
17 | ], | |
|
18 | "language": "python", | |
|
19 | "metadata": {}, | |
|
20 | "outputs": [ | |
|
21 | { | |
|
22 | "output_type": "stream", | |
|
23 | "stream": "stdout", | |
|
24 | "text": [ | |
|
25 | "\n", | |
|
26 | "Welcome to pylab, a matplotlib-based Python environment [backend: Qt4Agg].\n", | |
|
27 | "For more information, type 'help(pylab)'.\n" | |
|
28 | ] | |
|
29 | }, | |
|
30 | { | |
|
31 | "output_type": "pyout", | |
|
32 | "prompt_number": 3, | |
|
33 | "text": [ | |
|
34 | "[<matplotlib.lines.Line2D at 0x4566850>]" | |
|
35 | ] | |
|
36 | } | |
|
37 | ], | |
|
38 | "prompt_number": 3 | |
|
39 | }, | |
|
40 | { | |
|
41 | "cell_type": "code", | |
|
42 | "collapsed": false, | |
|
43 | "input": [ | |
|
44 | "# Should make an inline figure\n", | |
|
45 | "%pylab inline\n", | |
|
46 | "plot([1,2,3])" | |
|
47 | ], | |
|
48 | "language": "python", | |
|
49 | "metadata": {}, | |
|
50 | "outputs": [ | |
|
51 | { | |
|
52 | "output_type": "stream", | |
|
53 | "stream": "stdout", | |
|
54 | "text": [ | |
|
55 | "\n", | |
|
56 | "Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].\n", | |
|
57 | "For more information, type 'help(pylab)'.\n" | |
|
58 | ] | |
|
59 | }, | |
|
60 | { | |
|
61 | "output_type": "pyout", | |
|
62 | "prompt_number": 4, | |
|
63 | "text": [ | |
|
64 | "[<matplotlib.lines.Line2D at 0x4830ad0>]" | |
|
65 | ] | |
|
66 | }, | |
|
67 | { | |
|
68 | "output_type": "display_data", | |
|
69 | "png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD9CAYAAACoXlzKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAESVJREFUeJzt3V9oVFcCx/HftBHqGKvmwQQmWQqNLRk1mcRCWNA6IlJi\nawhV1sqmDZqHEFatr8WHqhUpKEikIPYlIj5Y0EIDTYQ+OIpKDGK6lPpgLIZMomQNEjDQ4qhnH7Jm\nZ8xk/t6ZuX++Hxhwck/nHi53j1+ON7M+Y4wRAMA13ij1BAAA1mJhBwCXYWEHAJdhYQcAl2FhBwCX\nYWEHAJdJubD/9ddfam5uVigUUjAY1FdffZV03P79+7Vq1So1NDRoeHi4IBMFAGSmLNXBt956S1eu\nXJHf79fz58+1fv16Xb9+XevXr58b09/fr/v372tkZES3bt1Sd3e3BgcHCz5xAEByabdi/H6/JOnZ\ns2d68eKFKioqEo739fWpo6NDktTc3Kzp6WlNTk4WYKoAgEykLHZJevnypZqamvTHH3+ou7tbwWAw\n4fjExIRqamrm3ldXV2t8fFyVlZVzP/P5fBZOGQC8I5cvB0hb7G+88YZ+/fVXjY+P69q1a4pEImlP\nnGwhN8bwsuD19ddfl3wObnpxPbmednv95z9G//iH0fvv5/5tLxk/FbNs2TJ9/PHHun37dsLPA4GA\notHo3Pvx8XEFAoGcJwQAXnXpklRfL/3tb1I+z6GkXNinpqY0PT0tSfrzzz/1yy+/qLGxMWFMa2ur\nzp07J0kaHBzU8uXLE7ZhAACpPX4s7dwpHTwo/fijdPy4tHhx7p+Xco/90aNH6ujo0MuXL/Xy5Ut9\n/vnn2rx5s86cOSNJ6urq0tatW9Xf36/a2lotWbJEvb29uc8GaYXD4VJPwVW4ntbiembv0iVp716p\nvV06eza/Bf0VnzGm4F/b6/P5VITTAIBjPH48u6D/+99Sb6/097/P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d+8mjPn5559NS0uLMcaYwcFB09zcbNXpXSeT63nlyhWzbdu2Es3QWa5du2bu3Lmz4GLE\nvZm5dNeS+zI7jx49MsPDw8YYY54+fWree++9vNdOy75SYGhoSLW1tXrnnXe0aNEiffbZZ/rpp58S\nxmTz3LvXZXI9JZ44ypSVv5PhdemupcR9mY2qqiqFQiFJUnl5uerq6vTw4cOEMdnen5Yt7BMTE6qp\nqZl7X11drYmJibRjxsfHrZqCq2RyPX0+n27evKmGhgZt3bpVd+/eLfY0XYN70zrcl7kbHR3V8PCw\nmpubE36e7f1p2df2Jnt+PZnX/ybP9L/zmkyuS1NTk6LRqPx+vwYGBtTW1qZ79+4VYXbuxL1pDe7L\n3MzMzGjHjh3q6elReXn5vOPZ3J+WFfvrz7RHo1FVV1enHMNz7wvL5HouXbpUfr9fktTS0qJYLKYn\nT54UdZ5uwb1pHe7L7MViMW3fvl3t7e1qa2ubdzzb+9Oyhf2DDz7QyMiIRkdH9ezZM/3www9qbW1N\nGMNz75nL5HpOTk7O/S0+NDQkY4wqKipKMV3H4960Dvdldowx6uzsVDAY1IEDB5KOyfb+tGwrpqys\nTN99950++ugjvXjxQp2dnaqrq9OZM2ck8dx7tjK5nhcvXtTp06dVVlYmv9+vCxculHjW9sXvZFgn\n3bXkvszOjRs3dP78edXX16uxsVGSdOzYMY2NjUnK7f70Gf75GgBcpeT/13gAAGuxsAOAy7CwA4DL\nsLADgMuwsAOAy7CwA4DL/BdtJN59CWl7cgAAAABJRU5ErkJggg==\n" | |
|
70 | } | |
|
71 | ], | |
|
72 | "prompt_number": 4 | |
|
73 | }, | |
|
74 | { | |
|
75 | "cell_type": "code", | |
|
76 | "collapsed": false, | |
|
77 | "input": [ | |
|
78 | "# New GUI window--should *NOT* have the visual settings of inline\n", | |
|
79 | "%pylab qt\n", | |
|
80 | "plot([1,2,3])" | |
|
81 | ], | |
|
82 | "language": "python", | |
|
83 | "metadata": {}, | |
|
84 | "outputs": [ | |
|
85 | { | |
|
86 | "output_type": "stream", | |
|
87 | "stream": "stdout", | |
|
88 | "text": [ | |
|
89 | "\n", | |
|
90 | "Welcome to pylab, a matplotlib-based Python environment [backend: Qt4Agg].\n", | |
|
91 | "For more information, type 'help(pylab)'.\n" | |
|
92 | ] | |
|
93 | }, | |
|
94 | { | |
|
95 | "output_type": "pyout", | |
|
96 | "prompt_number": 11, | |
|
97 | "text": [ | |
|
98 | "[<matplotlib.lines.Line2D at 0x5253850>]" | |
|
99 | ] | |
|
100 | } | |
|
101 | ], | |
|
102 | "prompt_number": 11 | |
|
103 | } | |
|
104 | ], | |
|
105 | "metadata": {} | |
|
106 | } | |
|
107 | ] | |
|
108 | } No newline at end of file |
@@ -423,6 +423,9 b' class InteractiveShell(SingletonConfigurable):' | |||
|
423 | 423 | # Private interface |
|
424 | 424 | _post_execute = Instance(dict) |
|
425 | 425 | |
|
426 | # Tracks any GUI loop loaded for pylab | |
|
427 | pylab_gui_select = None | |
|
428 | ||
|
426 | 429 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, |
|
427 | 430 | user_module=None, user_ns=None, |
|
428 | 431 | 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 | 178 | """Given a gui string return the gui and mpl backend. |
|
179 | 179 | |
|
180 | 180 | Parameters |
|
181 | 181 | ---------- |
|
182 | 182 | gui : str |
|
183 | 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 | 188 | Returns |
|
186 | 189 | ------- |
@@ -198,6 +201,13 b' def find_gui_and_backend(gui=None):' | |||
|
198 | 201 | # In this case, we need to find what the appropriate gui selection call |
|
199 | 202 | # should be for IPython, so we can activate inputhook accordingly |
|
200 | 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 | 211 | return gui, backend |
|
202 | 212 | |
|
203 | 213 | |
@@ -205,23 +215,20 b' def activate_matplotlib(backend):' | |||
|
205 | 215 | """Activate the given backend and set interactive to True.""" |
|
206 | 216 | |
|
207 | 217 | import matplotlib |
|
208 | if backend.startswith('module://'): | |
|
209 | # Work around bug in matplotlib: matplotlib.use converts the | |
|
210 | # backend_id to lowercase even if a module name is specified! | |
|
211 | matplotlib.rcParams['backend'] = backend | |
|
212 | else: | |
|
213 | matplotlib.use(backend) | |
|
214 | 218 | matplotlib.interactive(True) |
|
215 | 219 | |
|
220 | # Matplotlib had a bug where even switch_backend could not force | |
|
221 | # the rcParam to update. This needs to be set *before* the module | |
|
222 | # magic of switch_backend(). | |
|
223 | matplotlib.rcParams['backend'] = backend | |
|
224 | ||
|
225 | import matplotlib.pyplot | |
|
226 | matplotlib.pyplot.switch_backend(backend) | |
|
227 | ||
|
216 | 228 | # This must be imported last in the matplotlib series, after |
|
217 | 229 | # backend/interactivity choices have been made |
|
218 | 230 | import matplotlib.pylab as pylab |
|
219 | 231 | |
|
220 | # XXX For now leave this commented out, but depending on discussions with | |
|
221 | # mpl-dev, we may be able to allow interactive switching... | |
|
222 | #import matplotlib.pyplot | |
|
223 | #matplotlib.pyplot.switch_backend(backend) | |
|
224 | ||
|
225 | 232 | pylab.show._needmain = False |
|
226 | 233 | # We need to detect at runtime whether show() is called by the user. |
|
227 | 234 | # For this, we wrap it into a decorator which adds a 'called' flag. |
@@ -272,6 +279,7 b' def configure_inline_support(shell, backend, user_ns=None):' | |||
|
272 | 279 | from IPython.zmq.pylab.backend_inline import InlineBackend |
|
273 | 280 | except ImportError: |
|
274 | 281 | return |
|
282 | from matplotlib import pyplot | |
|
275 | 283 | |
|
276 | 284 | user_ns = shell.user_ns if user_ns is None else user_ns |
|
277 | 285 | |
@@ -282,12 +290,23 b' def configure_inline_support(shell, backend, user_ns=None):' | |||
|
282 | 290 | |
|
283 | 291 | if backend == backends['inline']: |
|
284 | 292 | from IPython.zmq.pylab.backend_inline import flush_figures |
|
285 | from matplotlib import pyplot | |
|
286 | 293 | shell.register_post_execute(flush_figures) |
|
294 | ||
|
295 | # Save rcParams that will be overwrittern | |
|
296 | shell._saved_rcParams = dict() | |
|
297 | for k in cfg.rc: | |
|
298 | shell._saved_rcParams[k] = pyplot.rcParams[k] | |
|
287 | 299 | # load inline_rc |
|
288 | 300 | pyplot.rcParams.update(cfg.rc) |
|
289 | 301 | # Add 'figsize' to pyplot and to the user's namespace |
|
290 | 302 | user_ns['figsize'] = pyplot.figsize = figsize |
|
303 | else: | |
|
304 | from IPython.zmq.pylab.backend_inline import flush_figures | |
|
305 | if flush_figures in shell._post_execute: | |
|
306 | shell._post_execute.pop(flush_figures) | |
|
307 | if hasattr(shell, '_saved_rcParams'): | |
|
308 | pyplot.rcParams.update(shell._saved_rcParams) | |
|
309 | del shell._saved_rcParams | |
|
291 | 310 | |
|
292 | 311 | # Setup the default figure format |
|
293 | 312 | fmt = cfg.figure_format |
@@ -321,7 +340,18 b' def pylab_activate(user_ns, gui=None, import_all=True, shell=None):' | |||
|
321 | 340 | The actual gui used (if not given as input, it was obtained from matplotlib |
|
322 | 341 | itself, and will be needed next to configure IPython's gui integration. |
|
323 | 342 | """ |
|
324 | 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) | |
|
325 | 355 | activate_matplotlib(backend) |
|
326 | 356 | import_pylab(user_ns, import_all) |
|
327 | 357 | if shell is not None: |
@@ -61,3 +61,79 b' def test_import_pylab():' | |||
|
61 | 61 | pt.import_pylab(ns, import_all=False) |
|
62 | 62 | nt.assert_true('plt' in ns) |
|
63 | 63 | nt.assert_equal(ns['np'], np) |
|
64 | ||
|
65 | ||
|
66 | class TestPylabSwitch(object): | |
|
67 | class Shell(object): | |
|
68 | pylab_gui_select = None | |
|
69 | ||
|
70 | def setup(self): | |
|
71 | import matplotlib | |
|
72 | def act_mpl(backend): | |
|
73 | matplotlib.rcParams['backend'] = backend | |
|
74 | ||
|
75 | # Save rcParams since they get modified | |
|
76 | self._saved_rcParams = matplotlib.rcParams | |
|
77 | matplotlib.rcParams = dict(backend='Qt4Agg') | |
|
78 | ||
|
79 | # Mock out functions | |
|
80 | self._save_am = pt.activate_matplotlib | |
|
81 | pt.activate_matplotlib = act_mpl | |
|
82 | self._save_ip = pt.import_pylab | |
|
83 | pt.import_pylab = lambda *a,**kw:None | |
|
84 | self._save_cis = pt.configure_inline_support | |
|
85 | pt.configure_inline_support = lambda *a,**kw:None | |
|
86 | ||
|
87 | def teardown(self): | |
|
88 | pt.activate_matplotlib = self._save_am | |
|
89 | pt.import_pylab = self._save_ip | |
|
90 | pt.configure_inline_support = self._save_cis | |
|
91 | import matplotlib | |
|
92 | matplotlib.rcParams = self._saved_rcParams | |
|
93 | ||
|
94 | def test_qt(self): | |
|
95 | s = self.Shell() | |
|
96 | gui = pt.pylab_activate(dict(), None, False, s) | |
|
97 | nt.assert_equal(gui, 'qt') | |
|
98 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
99 | ||
|
100 | gui = pt.pylab_activate(dict(), 'inline', False, s) | |
|
101 | nt.assert_equal(gui, 'inline') | |
|
102 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
103 | ||
|
104 | gui = pt.pylab_activate(dict(), 'qt', False, s) | |
|
105 | nt.assert_equal(gui, 'qt') | |
|
106 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
107 | ||
|
108 | gui = pt.pylab_activate(dict(), 'inline', False, s) | |
|
109 | nt.assert_equal(gui, 'inline') | |
|
110 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
111 | ||
|
112 | gui = pt.pylab_activate(dict(), None, False, s) | |
|
113 | nt.assert_equal(gui, 'qt') | |
|
114 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
115 | ||
|
116 | def test_inline(self): | |
|
117 | s = self.Shell() | |
|
118 | gui = pt.pylab_activate(dict(), 'inline', False, s) | |
|
119 | nt.assert_equal(gui, 'inline') | |
|
120 | nt.assert_equal(s.pylab_gui_select, None) | |
|
121 | ||
|
122 | gui = pt.pylab_activate(dict(), 'inline', False, s) | |
|
123 | nt.assert_equal(gui, 'inline') | |
|
124 | nt.assert_equal(s.pylab_gui_select, None) | |
|
125 | ||
|
126 | gui = pt.pylab_activate(dict(), 'qt', False, s) | |
|
127 | nt.assert_equal(gui, 'qt') | |
|
128 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
129 | ||
|
130 | def test_qt_gtk(self): | |
|
131 | s = self.Shell() | |
|
132 | gui = pt.pylab_activate(dict(), 'qt', False, s) | |
|
133 | nt.assert_equal(gui, 'qt') | |
|
134 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
135 | ||
|
136 | gui = pt.pylab_activate(dict(), 'gtk', False, s) | |
|
137 | nt.assert_equal(gui, 'qt') | |
|
138 | nt.assert_equal(s.pylab_gui_select, 'qt') | |
|
139 |
@@ -218,6 +218,6 b' def enable_gui(gui, kernel=None):' | |||
|
218 | 218 | " and no IPython Application with a kernel appears to be running." |
|
219 | 219 | ) |
|
220 | 220 | loop = loop_map[gui] |
|
221 | if kernel.eventloop is not None and kernel.eventloop is not loop: | |
|
221 | if loop and kernel.eventloop is not None and kernel.eventloop is not loop: | |
|
222 | 222 | raise RuntimeError("Cannot activate multiple GUI eventloops") |
|
223 | 223 | kernel.eventloop = loop |
General Comments 0
You need to be logged in to leave comments.
Login now