[IPython-dev] [sympy] Re: using reST for representing the notebook cells+text

Brian Granger ellisonbg at gmail.com
Wed Feb 24 15:24:18 EST 2010


Ondrej,

>> The pyjamas classes would contain the logic for the user interface,
>> and calling out to the
>> Notebook/Cell web service and pass XML/json back and forth....
>
> That's right. I just did more studying of this and I don't want to
> parse xml by hand in javascript/pyjamas. I would like to use the
> builtin functionality
>  for RPC, essentially, you just call python methods on both sides and
> things get automatically transfered (using json/xml RPC) behind the
> scene, it's very convenient.

Nice, that was my impression with pyjamas.  Sounds cool.

> Here is my current code, that runs in the browser:
>
> http://github.com/certik/sympy_gamma/blob/login/templates/nb.py
>
> and here is the code, that runs on the server, listens at some url
> (/eval_cell/...) and evaluates the cell:
>
> http://github.com/certik/sympy_gamma/blob/login/app/views.py#L126
>
> it's just 15 lines, 7 of those are debug prints.

This is super nice code.  Very easy to understand.  I really like how
pyjamas works.

>
> So there is no way to remember sessions, worksheets anything yet. So I
> will have Notebook/Cells on the server, the eval_cell() method will
> (besides the actual evaluation) keep the tree structure of
> Notebook/Cells updated. This structure will know how to export/import
> to/from many formats (reST, xml, ...), that part is clear.

Yes, you will have to add urls and handlers that know how to add
cells, delete cells,
etc.  I would follow a RESTful design of those URLS:

http://en.wikipedia.org/wiki/Representational_State_Transfer

> The rendering itself is done using pyjamas, so the Notebook/Cells
> classes don't need to know anything about it, they just contain the
> logic.

OK, this is the aspect of this model I still don't quite see - where
the representation
stuff is handled.

> On the browser part, I will also need some
> Notebook_pyjamas/Cell_pyjamas classes, that are purely responsible for
> rendering and I need somehow to initialize them from the server. I
> think I will do that by implementing Notebook_pyjamas.add_cell()
> method, that will be exported using RPC to the server, so the server
> will call this method as many times as needed, and add there
> parameters (input_text, output_text, type_of_the_cell="text"/"eval").

Yep.

> This would also solve my problem with passing data to the pyjamas app.
> So far I passed it by saving it to the "meta" tags in the header of
> the html page, and then getting it from inside pyjamas. But it sucks,
> it's not very versatile. See e.g. here the code to read it:
>
> http://github.com/certik/sympy_gamma/blob/login/templates/nb.py#L453
>
> it reads the html elements and returns a Python dict with the options.
> It's very fragile.

Right using json rpc will be much better.

> So this pyjamas development is a bit different to what one was used to
> before (e.g. generating the html on the server), essentially the
> philosophy is to initialize "Python" in the browser as soon as
> possible and then do everything on the Python level. And generate all
> html in the browser itself, from Python by constructing appropriate
> pyjamas GUI widgets (e.g. I subclassed the TextArea widget that
> implements the html textarea, with backspace/tab, shift+enter,
> correctly resizing it, calculating (x, y) coordinates of the cursor
> /nontrivial.../, etc, etc). It's kind of a fake, since there is no
> Python in the browser, just javascript, so it took my a while to
> realize that I can think of this really as having a Python interpreter
> in the browser (resp. a static subset of Python).

This is great ,I am curious to see how this evolves.

Brian

> Ondrej
>



-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com



More information about the IPython-dev mailing list