ipywidgets
ipywidgets copied to clipboard
Custom dunder method to detect ipywidget
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.
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?
Sure can you share the details of the dev meeting. I can take it up some time next month.
Thanks.
The meeting info is at https://github.com/jupyter-widgets/team-compass#weekly-team-meetings