[Nipy-devel] Re: [Enthought-dev] "Hello Chaco" example

Robert Kern robert.kern at gmail.com
Sun May 28 22:45:11 CDT 2006


Jonathan Taylor wrote:
> Hi,
> 
> I was wondering if I could get some help in creating a really small
> envisage application (with some reusable plugins) that would allow me
> to, say, plot an RGBA image through chaco. I have played a little with
> envisage before, and managed to create some of my own plugins (albeit
> not great), so I am not asking this question in total ignorance.
> 
> The examples in the subversion repository don't seem to use chaco, so I
> am a little lost on how to start.
> 
> This plugin would hopefully eventually be part of a larger application
> for the "nipy" project (http://neuroimaging.scipy.org) which could serve
> as a more complex "Hello World" example for other scientific groups
> wanting to get started with envisage.

Mike McLay recently visited us at Enthought, and we worked on an example
Envisage application.

  http://svn.enthought.com/svn/enthought/branches/probabilities-fleshed-out/

Unfortunately, because it was developed face-to-face, most of my explanations of
the code were verbal instead of in the code. However, it does show how to create
a Chaco2 plot in a GUI Envisage application.

The application currently consists of a single plugin wrapped around a tiny
library that represents probability distributions. It uses the
enthought.envisage.workbench plugin for the UI (and I recommend that new GUI
Envisage applications do the same rather than use enthought.envisage.ui). The
plugin, in src/lib/probabilities/plugin/single_project, is a concrete
implementation of the largely abtract enthought.envisage.single_project plugin.
It provides the notion of a project which holds Python objects and can save
itself out to a file (there are lots of options here, but this implementation
goes to a pickle).

Chaco2 comes into play in the view/plot_pdf.py file in the plugin. It provides a
workbench View that will plot the PDF of the currently selected probability
distribution in the project tree. It is used in a workbench Perspective defined
in plugin_definition.py . I can talk more about what workbench Perspectives and
Views are; just ask.

A View is pretty simple: primarily, you just need to implement the
create_control() method that returns a wx widget. Here, we instatiate an
enthought.enable2.wx.Window with a Chaco2 plot as its component, and return its
.control attribute. The rest of the PlotPdfView class holds data and sets up
trait notifiers to track the selection in the project (it replots when a new
distribution is selected).

Doing a similar thing with the original Chaco and Enable should be similar. The
parts that I described above didn't change much, IIRC.

About these targeted, focused questions: I love 'em. Keep 'em coming. We can
probably write up the results in the Wiki.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the Nipy-devel mailing list