Open andymcarter opened 6 years ago
I don't think this should be supported, those are two different worlds, the display mechanism (out of the ipywidget realm) and the widgets. I think a better solution would be to inherit from HBox, and add the children. Would that work for you?
The base _ipython_display_
for widgets will be removed in the next major version and we will fully rely on _repr_mimebundle_
.
Understood Maarten, thanks. Hadn't appreciated that _ipython_display_
wasn't a specific thing for widgets.
I guess I should inherit from HBox, create HTML and ToggleButtons widgets in the __init__
, then pass them as children to super().__init__
. Then I could override the required methods on this class to delegate to the ToggleButtons (like get_interact_value()
). Sounds like a more compositional approach would be beneficial here?
Yes, I think that would be a better approach. If you want it to behave like a ToggleButtons, you could copy its traits (removing .tag(sync=True)
and link the traits together.
Xref #1811.
I have been subclassing the basic ipywidgets to develop notebook GUIs, and have been trying to 'wrap' a basic widget with a HTML label to the left (for consistent layouts). I'm aware there is a
description
kwarg but I often want to create a single class which contains multiple widgets (e.g. a start and end date picker), but just has a single label.I understand
_ipython_display_
can be overrided to change how a widget is displayed (following the example here).This works fine when calling a widget to display directly (see below):
However, if I try to add these widgets to a Box, the
_ipython_display_
method is not respected, and the widget displays as if it is the simple inherited widget (in this case, the Togglebuttons).Can I get the custom
_ipython_display_
behaviour when combining these 'wrapped' widgets into a dashboard Box?ipywidgets version 7.4.2 IPython 7.1.1