-
Notifications
You must be signed in to change notification settings - Fork 60
Description
The MimeBundeDescriptor introduces a more library agnostic connection between python model and JS view, but currently doesn't support two important features from ipywidgets.Widget. First a mechanism to both send and receive messages from the front end. The latter could be simple enough to implement with a special method (akin to _anywidget_get_state):
class Foo:
_repr_mimebundle_ = MimeBundleDescriptor()
def _anywidget_handle_custom_msg(self, msg):
...But I'm having trouble thinking of a way to allow for custom messages to be sent. Right now this can be accomplished with:
class Foo:
_repr_mimebundle_ = MimeBundleDescriptor()
Foo()._repr_mimebundle_._comm.send(...)
# probably do not want to expose Comm directly bc custom messages have a particular formatbut I'd be ok with adding a send method to ReprMimeBundle directly (like send_state):
class Foo:
_repr_mimebundle_ = MimeBundleDescriptor()
Foo()._repr_mimebundle_.send(contents, buffers
# alias for ReprMimeBundle._comm.send({"method": "custom", "content": content}, buffers=buffers)Of course, using the _repr_mimbundle_ name is a bit verbose, but I like how it makes it clear how these messages are only received if the front end is activated.
Second, we should have a way of marking attributes which shouldn't automatically be synchronized with the frontend. This would be the opposite of sync=True for traitlets where by default everything is synchronized.