[IPython-dev] custom widget example : python and javascript

Matthias BUSSONNIER bussonniermatthias@gmail....
Mon Nov 12 11:38:29 CST 2012


Hi Massimo, 

The documentation is really sparse on the JS side. 
What you will need to do is :

publish javascript form python, 
this javascript will have access to a `container` variable that you will have to make visible, 
and add all the element you which inside (using query).

This javascript can bind event to `IPython.notebook.kernel.execute(code,callback)` 
to execute code in the kernel. 

you can have a look at `docs/examples/widgets/directview`
where there is a drop down menu that ask you on which engine you wish to execute the code. 
So this should be a good starting point. 


Brian have also a pending PR to make things easier
https://github.com/ipython/ipython/pull/2518

-- 
Matthias


Le 12 nov. 2012 à 17:10, Massimo Di Stefano a écrit :

> 
> Hi IPython!
> 
> 
> i was tring to learn how to code a cell in order to have interaction between  python <->  Javascript (jquery?)
> 
> i can try to explain with an example …
> 
> let's say i have a dictionary in python :
> 
> 
>>>> mydict = {'key1':'val1', 'key2':'val2'}
> 
> and a function that take as input the dict and print out the value :
> 
>>>> def printval(mydict, keyN):
>           print maydict['keyN']
> 
> 
> what i'm tring to learn is :
> 
> how to render inside an "IPython notebook cell"   a js gui tool like a "dropdown menu"  that will contain the "mydict keys"
> and  button that will connect the selected value in the dropdown menu to the printval function ?
> 
> i guess it should be trivial for who knows the how the internal engine works, i was really attracted by the  new "js plugin system" (i saw it in NYC at the PyData … cool!)
> for me an example like this can be a perfect starting point to start to develop something useful ….
> 
> thamk you for you great support!
> 
> Massimo.
> 
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev



More information about the IPython-dev mailing list