[IPython-dev] Leo, IPython and the summer of code
Edward K. Ream
edreamleo at charter.net
Tue Jul 5 09:11:39 CDT 2005
There are slight inaccuracies in section 2.2 (complexity level) and section
1 (overview) of the description of the interactive notebooks project at
Section 2.2 states, "This project is relatively complicated.it will require
a fair amount of thinking in terms of overall library architecture."
Section 1 states, "The full-blown implementation of a graphical shell
supporting this kind of work model is probably too ambitious for a summer
project. Simultaneous support for rich-text editing, embedded graphics and
syntax-highlighted code is extremely complex, and likely to require far more
effort than can be mustered by an individual developer for a short-term
Actually, this project is already complete. Leo,
http://webpages.charter.net/edreamleo/front.html, already _is_ an
interactive notebook for Python and IPython. Any remaining work on this
project, if done within the framework of Leo, would likely involve tasks of
one hour to one day in duration. I can state this with confidence because I
am Leo's author.
What is Leo you ask? Leo is full featured outlining editor. Leo is Open
Software (Python license), written in 100% pure Python using Tkinter. Leo
has an extremely active group of users. Many are wildly enthusiastic. Leo
is presently one of the top 100 SourceForge sites. Leo is
production-quality software; bugs are typically fixed in a few days.
More importantly, Leo, right now, implements everything envisioned in the
- Leo works well with IPython. See below for details.
- Leo has a powerful plugin mechanism. An ipython plugin would be the
natural way to do larger summer of code projects in Leo.
- Leo outlines are far more capable than typical notebooks. Clones allow
multiple views of data to exist within a single outline.
- Leo's rst2 plugin already supports rst markup, including embedded
- Leo plugins can define extensions to markup and Leo directives. Such
extensions might be useful in larger summer of code projects.
- Leo can create various external files (called derived files) from a single
outline. Derived files can be edited in any editor, and changes made to
derived files in others editors automatically appear in an outline when Leo
reopens it. The format of derived files involves 10 years of design and
- Leo shows that a simple markup language called noweb,
http://www.eecs.harvard.edu/~nr/noweb/, when used in an outline context, is
much more powerful than a more complex markup in a 'flat' context. There is
absolutely no need for yet another markup language.
- noweb markup is language neutral: it can be used in combination with any
- If markup other than noweb were really needed, the ipython plugin could
define a syntax colorer for that markup.
- Leo supports syntax coloring for LaTeX, cweb and many other languages. In
the near future, this colorer will become even more flexible.
- Several flavors of htmlize scripts already exist. Writing other custom
converters would be dead easy. (For those who understand, just put the
script of the converter in an @button node.)
- Leo is a superb scripting environment for Python. See
http://webpages.charter.net/edreamleo/WhatIsLeo.html In this environment,
all manner of customizations become very easy. For example, @button nodes
would be the way to do smaller summer of code projects.
- As shown below, scripts run from Leo (or from IPython invoked from Leo)
have full access to all data in Leo outlines. This crucial element is
missing from the project description.
- Leo works well with editors such as vim and emacs.
- Leo can silently run a script in batch mode. Just execute:
leo.py --batch yourScript.py <arguments to Leo>
In short, Leo already goes far beyond the capabilities described in the
summer of code proposal. The following section describes how IPython
presently works with Leo.
Using IPython and Leo
To embed IPython into Leo simply create a node in a Leo outline whose body
text contains the standard embedding code:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
To run IPython from Leo, do the following:
1. Make sure that Leo is running with a console window visible.
2. Select the node containing the above script and do Leo's Execute Script
command. Better yet, you can create a 'script button' in Leo's icon area
that will run this script when pressed. (The scripting plugin must be
enabled in order to create script buttons.)
After executing this script, (either using the Execute Script command or by
pressing the 'ipython' script button) Leo continues to run while IPython is
running. Way cool.
Important: When started from Leo using the script above, the c, g and p
variables are defined in IPython. c is Leo's present commander (window), g
is the leoGlobals module and p is the present position in the outline.
These three variables give you access to all the data in the present Leo
outline! This is essentially perfect integration with Leo and IPython,
right out of the box.
For example, the following script, **when executed by IPython invoked from
Leo**, prints all the headlines of the present outline, properly indented:
for p in c.allNodes_iter():
print p.level()*' ',p.headString()
Leo already is a complete interactive notebook for IPython, with all the
features described in the proposal. Furthermore, Leo shows how the proposal
could be improved :-) Please tell me if I have misunderstood the proposal
in any way.
Please look at Leo carefully: as far as the proposal is concerned, you can
probably accomplish more in one week using Leo than you could in six months
without Leo. After using Leo for a bit you will certainly have ideas for
improving how Leo and IPython work together. Implementing those ideas would
likely take just a few hours in the context of Leo. Use plugins for larger
projects; use @button nodes for smaller (instant) projects.
I am willing to do whatever it takes to make Leo work better with IPython.
I would love for the IPython community to get what Leo is all about.
P.S. At the EuroPython conference there was unanimous agreement that Leo
needs better documentation for newcomers, and that Leo must be able to
simulate emacs and vim key bindings so Leo can be used more easily without a
mouse. These are now top priority items and I hope to finish both within a
month. Please don't let these defects get in the way of learning Leo. In
particular, please do ask questions about Leo either here or at Leo's help
Edward K. Ream email: edreamleo at charter.net
Leo: Literate Editor with Outlines
More information about the IPython-dev