The IPython Frontends

Updated: 3/21/2006

Overview

In general terms, the IPython Frontend refers to the part of IPython that manages the user interface. Currently, the only UI for IPython is the standard terminal based IPython. In the curent design of IPython this terminal based UI is inextricably tied to the other aspects of IPython. This non-modular design has made it very difficult to plug parts of IPython into other systems (such as IDEs). Our goal is to completely separate the UI aspect of IPython from the other components (The IPython Core and IPython Kernel).

More specifically, the responsibilities of the IPython frontend will be:

  1. To display an appropriate IPython prompt.
  2. To process keyboard and mouse events and call the appropriate underlying components of IPython.
  3. To display and format the output and errors of commands that have been run.

Another way of saying this is to specify the things that the IPython Core and IPython Kernel will know nothing about:

  1. Readline or curses.
  2. How things (prompts, stdout, stdin) are displayed. (This may quite be true. See Output Display below.)
  3. Keyboard or mouse events.
  4. Any terminal or GUI related thing.

Thus, the Frontend must handle all of these things. Another effect of this refactoring is that the frontend will only be able to access the IPython Core/Kernel using a standard API. That is, the frontend will not be able to directly access the internals of IPython.

Details About Certain Aspects

It is probably helpful to give examples of how the frontend will perform certain tasks.

Tab Completion

The frontend will handle certain aspects of tab completion. Tab completion will happens as thus:

  1. The user will type a partial command
  2. The user will hit the tab (or another) key to initiate tab completion
  3. The frontend will intercept the event, read the partial command and call an appropriate method in the IPython Core.
  4. When the frontend gets the results of the completion call, it displays them for the user.

In this process, the frontend must be able to handle errors. For instance, it might be possible that the IPython Core cannot complete a certain partial command.

Magic Commands

The frontend will do no processing of IPython's magic commands. All Magic command handling will be done by the IPython Core.

Syntax Highlighting and Colorizing

The frontend will be responsible for all syntax higthlighting and colorizing of input/output, etc. The IPython Core will return the stdout and stderr of commands in a form that can easily be colorized in an appropriate manner (probably using a generic markup language).

Output Display

Current IPython modifies sys.displayhook() to capture objects that would otherwise be repr()'d and passes them through pprint.pprint() to format them for display in the Out[NN]: prompts. Unfortunately, this requires access to the actual Python object. Since the kernel/core may be running remotely, some of this formatting must be done there. However, the precise formatting may depend on the front-end. I (RTK) think that the frontend needs to be able to tell the kernel/core which formatter to use. Possibly, it may need to send the formatter code to the kernel/core if it is remote.