[IPython-dev] IPython.fronend progress

Barry Wark barrywark@gmail....
Sun Jun 15 18:03:31 CDT 2008


I'm getting close to being ready to merge the ipython-frontend branch
into trunk. At this point, I would like to update folks on the status
of IPython.frontend and solicit comments and review before things get
merged to trunk..

====
Overview
====

IPython's InteractiveShell (in 0.8.4) is currently tied to the
terminal. Thus, alternative frontends that integrate with native GUI
toolkits and provide alternative rendering functionality (something
like a Mathematica notebook-style interface) are currently very
difficult implement with the IPython InteractiveShell. With the
integration of ipython1 into IPython, we now have the opportunity to
separate the interpreter/engine from the UI and to make it easier to
write other types of frontends for IPython. In the IPython.frontend
package, we intend to provide base functionality to make writing these
frontends easier.

As a proof of concept, I've written a frontend for IPython in the
Cocoa toolkit for OS X. This Cocoa frontend is implemented as a
drop-in component that can be included by devleopers of Cocoa apps.
I've also written a demo application that provides a Matlab-style
workspace (command-line and user namespace browser) using this Cocoa
frontend. With the IPython.frontend.frontend.FrontEndBase and the
GUI-integration provided by Twisted, the Cocoa frontend requires about
400 lines of code (including managing the text widget to simulate a
CLI interface).

If you would like to try out the Cocoa interface on OSX, you will
currently need OS X 10.5 or greater with Developer Tools installed.
Download the ipython-frontend branch from launchpad.net. In the
IPython/frontend/cocoa/examples/ folder, you will find an Xcode
project for IPython1Sandbox. Building and running this app should get
you started. Feel free to ask me if you have any questions. Of course
the normal caveats apply: this is VERY new code and many things may
not work. Use at your own risk. When you find bugs, please report them
on launchpad.net/ipython.

====
For Developers
====

The purpose of IPython.frontend is to provide a base class
(frontend.frontendbase.FrontEndBase) for frontend writers to use in
developing GUI frontends for IPython. FrontendBase provides all of the
basic functionality required by the front end (testing for block
completeness, managing history, executing blocks on an
IPython.kernel.engineservice.IEngineBasic-implementing engine, and
rendering results and errors asynchronously (via Twisted deferreds)).
GUI frontends will want to subclass FrontEndBase and override the
render methods (render_result and render_error) to render results and
errors respectively. Each execute request can be assigned a "blockID"
to allow the frontend to identify the block corresponding to the
result/error. The frontend can assign this blockID or a UUID will be
assigned automatically. Frontends may also override update_prompt to
update the input prompt for a block once it's number is known (it may
not be known until the engine executes the block if more than one
client is using the same engine). The subclass must also decide when
to send a block to the engine. For this, FrontEndBase provides
is_complete to test whether a block is a complete statement. Once a
block is complete, the frontend can send it to the engine by passing
it to FrontEndBase's execute method. The result of execute is a
twisted.internet.deferred.Deferred result of the execution of that
block.


At this point, I would appreciate comments on the entire frontend
package before we consider merging ipython-frontend into trunk. There
aren't any changes in the ipython-frontend branch outside of the
IPython.frontend package EXCEPT to
IPython.kernel.engineservice.ThreadedEngineService. I updated
I.kernel.engineservice.ThreadedEngineService so that it now works and
added associated tests in I.kernel.tests.test_engineservice.py. All
tests pass on my Mac. ThreadedEngineService is required to prevent
long-running execute calls from blocking the main GUI thread. There
currently isn't any method for canceling or interrupting an executing
block, but at least it doesn't block the GUI thread. Moving to a
TaskClient instead of ThreadedEngineService might fix this... but
that's for the future.

I'm currently working to improve the documentation/comments, but the
code in there are at least tests for most of the code in
frontend.frontendbase at this point.

- Barry


More information about the IPython-dev mailing list