ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Custom dunder method to detect ipywidget

Open govinda18 opened this issue 3 years ago • 3 comments

Problem

When I want to make any class behave like an ipywidget, it is not straight-forward. Suppose I have some class A and I want it to work like an ipywidget generated using some method create_widget(a: A), it is not entirely possible.

I can ofcourse override the _ipython_display_ method, but still not helps me embed A into other ipywidgets. For example, ipywidgets.HBox([A()]) wont work, I must do ipywidgets.HBox([create_widget(A())]). The create_widget can possible be a factory that is not meant to be exposed to the user.

An obvious solution is to create a property called widget in but this still requires a user to do some extra unintuitive work of saying .widget everytime.

Proposed Solution

There should be a way to make any class behave like an ipywidget. For example, if a class has a dunder like __get_ipywidget__, it can behave as an ipywidget and the method can be expected to return an ipywidget corresponding to the class.

govinda18 avatar Sep 07 '22 14:09 govinda18

This sounds really interesting. We briefly discussed it in the ipywidgets dev meeting. Would you like to come to the dev meeting so we can more fully flesh out what this would look like and its ramifications? Would you like to implement a prototype once we flesh out the design?

jasongrout avatar Sep 13 '22 16:09 jasongrout

Sure can you share the details of the dev meeting. I can take it up some time next month.

Thanks.

govinda18 avatar Sep 15 '22 12:09 govinda18

The meeting info is at https://github.com/jupyter-widgets/team-compass#weekly-team-meetings

jasongrout avatar Sep 17 '22 19:09 jasongrout