@@ -2686,50 +2686,49 @@ def prepare_selection_handler(selection_handler, custom_html, custom_js, custom_
26862686 Returns
26872687 -------
26882688 tuple
2689- (custom_html, custom_js, custom_css) with handler content merged.
2689+ (custom_html, custom_js, custom_css, handler_widgets) with handler
2690+ content merged. ``handler_widgets`` is a list of widget instances
2691+ owned by the handlers (may be empty).
26902692 """
2691- if selection_handler is None :
2692- return custom_html , custom_js , custom_css
2693+ handler_widgets = []
26932694
2694- if isinstance (selection_handler , Iterable ) and not isinstance (
2695- selection_handler , SelectionHandlerBase
2696- ):
2697- for handler in selection_handler :
2698- if custom_html is None :
2699- custom_html = handler .html
2700- else :
2701- custom_html += handler .html
2702-
2703- if custom_js is None :
2704- custom_js = handler .javascript
2705- else :
2706- custom_js += handler .javascript
2695+ if selection_handler is None :
2696+ return custom_html , custom_js , custom_css , handler_widgets
27072697
2708- if custom_css is None :
2709- custom_css = handler .css
2710- else :
2711- custom_css += handler .css
2712- elif isinstance (selection_handler , SelectionHandlerBase ):
2698+ def _process_one (handler ):
2699+ nonlocal custom_html , custom_js , custom_css
27132700 if custom_html is None :
2714- custom_html = selection_handler .html
2701+ custom_html = handler .html
27152702 else :
2716- custom_html += selection_handler .html
2703+ custom_html += handler .html
27172704
27182705 if custom_js is None :
2719- custom_js = selection_handler .javascript
2706+ custom_js = handler .javascript
27202707 else :
2721- custom_js += selection_handler .javascript
2708+ custom_js += handler .javascript
27222709
27232710 if custom_css is None :
2724- custom_css = selection_handler .css
2711+ custom_css = handler .css
27252712 else :
2726- custom_css += selection_handler .css
2713+ custom_css += handler .css
2714+
2715+ # Collect any widgets owned by this handler
2716+ if hasattr (handler , "widgets" ):
2717+ handler_widgets .extend (handler .widgets )
2718+
2719+ if isinstance (selection_handler , Iterable ) and not isinstance (
2720+ selection_handler , SelectionHandlerBase
2721+ ):
2722+ for handler in selection_handler :
2723+ _process_one (handler )
2724+ elif isinstance (selection_handler , SelectionHandlerBase ):
2725+ _process_one (selection_handler )
27272726 else :
27282727 raise ValueError (
27292728 "selection_handler must be an instance of SelectionHandlerBase or an iterable of SelectionHandlerBase instances"
27302729 )
27312730
2732- return custom_html , custom_js , custom_css
2731+ return custom_html , custom_js , custom_css , handler_widgets
27332732
27342733
27352734def prepare_dynamic_tooltip (dynamic_tooltip ):
0 commit comments