Implementation of Jupyter cells in Leo

65 views
Skip to first unread message

Edward K. Ream

unread,
Jan 10, 2017, 11:50:53 AM1/10/17
to leo-editor
The design phase has gone smoothly, so let's consider some strategies for making fully functional Jupyter cells within Leo.  This is possible, in at least two ways:

1. Create a fully functional html representation of each cell, and render that html in Leo's existing body pane. It may be possible to use `nbconvert --to html` to get the html.

2. Create a custom Qt widget that looks and works exactly like the desired cell.

The real work is connecting each cell to the appropriate kernel, and displaying the results. Clearly is possible--both IPython itself and the Jupyter notebook do it.

But there is lots of magic (behind-the-scenes complications) involved. Furthermore, pyzo renders graphics output in a popup Qt pane, which is too bad because Leo can't use the pyzo code as is. And pyzo puts the following bizarre warning in the IPython pane every time it produces graphics output:

QQQ
Note on using QApplication.exec_():

The GUI event loop is already running in the pyzo kernel, and exec_()

does not block. In most cases your app should run fine without the need

for modifications. For clarity, this is what the pyzo kernel does:

- Prevent deletion of objects in the local scope of functions leading to exec_()

- Prevent system exit right after the exec_() call

QQQ


Not exactly smooth :-)


Summary


Leo's existing body pane may suffice for rendering an html representation of each pane.  Otherwise, a custom Qt widget will be needed, with separate areas for labels and code and output.  No big deal. Anyone care to create such a thing?

Communicating with the Jupyter kernels is the major task. Happily, the newish Jupyter architecture guarantees that Leo can, in fact, be a Jupyter client. All it takes is blood, sweat and code. pyzo may be a guide, but it isn't a complete guide.

EKR

Edward K. Ream

unread,
Jan 10, 2017, 12:07:49 PM1/10/17
to leo-editor
On Tuesday, January 10, 2017 at 11:50:53 AM UTC-5, Edward K. Ream wrote:

...there is lots of magic (behind-the-scenes complications) involved. Furthermore, pyzo renders graphics output in a popup Qt pane, which is too bad because Leo can't use the pyzo code as is.

I should emphasize that pyzo is a model for embedding an actual IPython interpreter pane within Leo. Otoh, Jupyter notebooks just have cells. They have no need for a separate interpreter area.

Still, it's may be that embedding functional cells into Leo requires roughly the same amount of infrastructure as embedding an IPython interp.  We shall see.

It's time to study the IPython/Jupyter internals once again, including tools and add-ons.

EKR

Edward K. Ream

unread,
Jan 10, 2017, 12:18:46 PM1/10/17
to leo-editor
On Tuesday, January 10, 2017 at 11:50:53 AM UTC-5, Edward K. Ream wrote:

pyzo puts the following warning in the IPython pane every time it produces graphics output: QQQ Note on using QApplication.exec_(): [snip] QQQ

pyzo/pyzokernel/guiintegration.py emits this message. A comment says this is because the "extra" wrapping around the Qt even loop can cause debugging mysteries.

Leo will never use such a wrapper, so this message will never appear in Leo.

This kind of detail is getting far from design considerations.  It's time to create a Leo issue to track progress on this project.

EKR

Edward K. Ream

unread,
Jan 11, 2017, 1:47:45 AM1/11/17
to leo-editor
On Tuesday, January 10, 2017 at 12:18:46 PM UTC-5, Edward K. Ream wrote:

It's time to create a Leo issue to track progress on [the Jupyter in Leo] project.

Satish Goda

unread,
Jan 17, 2017, 4:16:25 AM1/17/17
to leo-editor
Edward. While perusing the jupyter sub-projects on Github, I came across https://github.com/jupyter/qtconsole

Have you looked at this already? 
qtconsole.png

Edward K. Ream

unread,
Jan 17, 2017, 4:33:39 AM1/17/17
to leo-editor
On Tue, Jan 17, 2017 at 3:16 AM, Satish Goda <satis...@gmail.com> wrote:
Edward. While perusing the jupyter sub-projects on Github, I came across https://github.com/jupyter/qtconsole

​Yes.  This is the console that pops up when drawing in image within ipython.

I have studied this code, and attempted to adapt it to Leo. There may be some code in the attic somewhere. I don't remember whether I ever got it to work inside Leo.

I'm glad you asked this question. It reminds me that I have forgotten what I have done previously ;-)  I do remember, though, the realization that all those cool ipython demos are cool because they use pyplot/matplotlib.

Edward
Reply all
Reply to author
Forward
0 new messages