Skip to content

enable %gui/%pylab magics in the Kernel #905

Merged
merged 3 commits into from Oct 21, 2011

3 participants

@minrk
IPython member
minrk commented Oct 20, 2011

This isn't as significant as it looks, as it's principally a big dedent in zmq.ipkernel. All the single-method Kernel subclasses were just dedented, and are used as functions. This lets them be plugged into the existing kernel's event loop.

The enable_pylab and magic_gui methods in zmqshell only differ from the originals in the source of the enable_gui function, and the change of the default pylab backend to inline, from auto.

So you can now activate pylab mode after launch, in the QtConsole or Notebook.

@minrk
IPython member
minrk commented Oct 20, 2011

another difference: unlike the Terminal versions, eventloop integration can only be done once and is not reversible.

@jdmarch
jdmarch commented Oct 20, 2011

In Windows 7, works beautifully with ipython-qtconsole as long as command line switch --pylab is not specified. If it is, qtconsole freezes after banner text, just before first input prompt.

@minrk minrk enable %gui/%pylab magics in the Kernel
This isn't as significant as it looks, as it's principally a big
dedent in zmq.ipkernel.  All the single-method Kernel subclasses were just dedented, and are used as functions.  This lets them be plugged into the existing kernel's event loop.

The enable_pylab and magic_gui methods in zmqshell only differ from the originals in the source of the enable_gui function, and the change of the default pylab backend to inline, from matplotlib autodetect.
d39f0ca
@minrk
IPython member
minrk commented Oct 20, 2011

rebased on master, and that bug should be fixed. Thanks!

@jdmarch
jdmarch commented Oct 20, 2011

Yes, that bug is fixed.

@jdmarch
jdmarch commented Oct 20, 2011

If %pylab is invoked twice, there is no RuntimeError traceback, but if --pylab is on the command line, then user does %reset, then %pylab, there is such a traceback in qtconsole, which does not seem useful.

FWIW in the context of this PR: in ipython terminal there is also an unhelpful UserWarning (but at least no traceback) the first time that %pylab is re-invoked (but not subsequent times). This is whether or not the initial invocation was from --pylab or from %pylab.

@fperez
IPython member
fperez commented Oct 21, 2011

Fantastic! Many thanks, @minrk. Tested, works great!

One comment only: when started at the cmd line with --pylab, the qtconsole now shows the pylab message above the banner, where as it should appear below the banner like it does in the terminal.

I should note that before, we were simply swallowing that message, so this is already an improvement as we should show it. It's just that I hadn't realized we were swallowing it, while it's apparent now that it appears misplaced.

Great job though, many thanks!!

@minrk
IPython member
minrk commented Oct 21, 2011

We weren't actually swallowing it before - no message was output at all. We were calling the respective low-level functions separately, rather than pylab_activate() itself, which does setup and the message. I can investigate why stdout messages posted prior to the first execution go above instead of below the banner (you can see the same by adding 'print "hi"' to exec_lines, or even ipython qtconsole -c 'print "hello"'). Perhaps @epatters knows exactly where to look. Should be a simple matter of moving the Cursor.

@minrk
IPython member
minrk commented Oct 21, 2011

Nevermind, I found it, will push in a sec.

@minrk
IPython member
minrk commented Oct 21, 2011

pushed - now print statements prior to first execution (including pylab) should come up after the main banner.

@minrk minrk quiet error messages instead of tracebacks in %pylab/%gui
Including Terminal pylab, for unsupported backends

Also fix %pylab default in kernel to 'auto' like everywhere else, for uniformity.
69f6680
@minrk
IPython member
minrk commented Oct 21, 2011

@jdmarch error messages should be quieter now, no more tracebacks.

The default backend is now 'auto' like everywhere else, so you have to %pylab inline to get the inline backend.

@fperez fperez merged commit 6f94725 into ipython:master Oct 21, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.