[IPython-dev] first experiment creating Software Carpentry teaching materials using the IPython Notebook

Matthias BUSSONNIER bussonniermatthias@gmail....
Sun Mar 24 14:08:27 CDT 2013


Le 24 mars 2013 à 19:51, MinRK a écrit :

>> 
>> With one clarification on #2:  There is not a hook for you to add css classes to the cells live in the notebook, but this can certainly be added.  The cell metadata is how you would do this, but interpreting the metadata to add the class to the div will need to be added.
> Understood --- but that seems like it _ought_ to be a pretty simple extension (he said hopefully).
> 
> It certainly should be - one thing we would need to do to support such an extension is add a hook for the 'cell-metadata-changed' event. 

No need to, the setters provided by the extensions just have to emit events.

To take back an example from 
http://elacave.lmdb.eu/~carreau/yui/classes/IPython.CellToolbar.html

(setters and getters are defined inline, but they could be provided separately and be imported )

     * @example
     *
     *      var select_type = CellToolbar.utils.select_ui_generator([
     *              ["<None>"            , undefined      ],
     *              ["Header Slide" , "header_slide" ],
     *              ["Slide"        , "slide"        ],
     *              ["Fragment"     , "fragment"     ],
     *              ["Skip"         , "skip"         ],
     *              ],
     *              // setter
     *              function(cell, value){
     *                  // we check that the slideshow namespace exist and create it if needed
     *                  if (cell.metadata.slideshow == undefined){cell.metadata.slideshow = {}}
     *                  // set the value
     *                  // ONE CAN EMMIT THE CHANGED VALUE HERE
     *                  cell.metadata.slideshow.slide_type = value
     *                  },
     *              //geter
     *              function(cell){ var ns = cell.metadata.slideshow;
     *                  // if the slideshow namespace does not exist return `undefined`
     *                  // (will be interpreted as `false` by checkbox) otherwise
     *                  // return the value
     *                  return (ns == undefined)? undefined: ns.slide_type
     *                  }
     *      CellToolbar.register_callback('slideshow.select', select_type);
     *
     */

This allow people to rely on other plugin, and the plugin author can change the way the metadata are store/read al long as the getters/setters are exposed.
See what I mean ? Or I should write an example ?

-- 
Matthias




More information about the IPython-dev mailing list