[IPython-User] Custom communication with IPython notebook widgets

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[IPython-User] Custom communication with IPython notebook widgets

gabriele.lanaro
Hi! I'm trying to develop a complex widget (a molecular viewer) that is able to display multiple representations of the same chemical system.

I am aware of the traitlets system and how it works but I was wondering if it's possible to develop an API of this kind:

mv = MolecularViewer() # that's a DOMWidget
mv.call_method("addSurface", params)
# That would trigger a method in the corresponding javascript code
#
#  MolecularViewer = IPython.DOMWidget.extend{
#  ...
#  addSurface = function(params) {
#      ....
#         } 
#  }

I've seen there is a "send" method of the IPython.Widget class https://github.com/ipython/ipython/blob/master/IPython/html/widgets/widget.py#L254 that looks like it may be related to sending those custom messages to the JS side, but I fail to understand how this works.

Thank you very much,

Gabriele

_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Custom communication with IPython notebook widgets

rossant
> I've seen there is a "send" method of the IPython.Widget class
> https://github.com/ipython/ipython/blob/master/IPython/html/widgets/widget.py#L254
> that looks like it may be related to sending those custom messages to the JS
> side, but I fail to understand how this works.

Yes, you can use send() to exchange Python dictionaries/JavaScript
objects between the kernel and the browser. The on_msg() methods are
called when a message is received. The messages need to be
serializable so it might be a good idea to only use numbers, strings,
and lists.
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: Custom communication with IPython notebook widgets

gabriele.lanaro
Thank you very much! This method is working properly

Gabriele

On Fri, Oct 31, 2014 at 12:46 AM, Cyrille Rossant <[hidden email]> wrote:
> I've seen there is a "send" method of the IPython.Widget class
> https://github.com/ipython/ipython/blob/master/IPython/html/widgets/widget.py#L254
> that looks like it may be related to sending those custom messages to the JS
> side, but I fail to understand how this works.

Yes, you can use send() to exchange Python dictionaries/JavaScript
objects between the kernel and the browser. The on_msg() methods are
called when a message is received. The messages need to be
serializable so it might be a good idea to only use numbers, strings,
and lists.
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user