Skip to content

How to implement a container widget? #293

Answered by manzt
asaboor-gh asked this question in General
Discussion options

You must be logged in to vote

Well I dug into this a bit. Turns out it's not too hard to accomplish what you want currently with anywidget. Model serializers just allow you to hook into view.model.get(<name>) and view.model.set(<name>, <value>). As long as the Python serializer (ipy.widget_serialization) targets JSON (and doesn't include binary data), you can accomplish this deserialization manually:

let children = deserialize_children(view.model.get("children"));

Looking into unpacked_models, it's pretty straightforward to implement yourself for children:

import anywidget
import traitlets
import ipywidgets as ipw

class Box(anywidget.AnyWidget):
    _esm = """
    async function unpack_models(model_ids, manager) {

Replies: 10 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by manzt
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@naschmitz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #28 on September 17, 2023 16:41.