""" Shared Bokeh widget instances and layout helpers referenced by multiple panels. These are created once at import time. Any panel that needs to read or write these widgets imports them from here to avoid creating duplicates. """ from bokeh.layouts import column from bokeh.models import TextInput, Button, CustomJS, Slider, Toggle # Feature navigation (used by feature panel, feature list, patch explorer, clip search) feature_input = TextInput(title="Feature Index:", value="", width=120) go_button = Button(label="Go", width=60) random_btn = Button(label="Random", width=70) # Image display controls (used by feature panel and zoom/alpha re-render) zoom_slider = Slider( title="Zoom (patches)", value=16, start=1, end=16, step=1, width=220, ) heatmap_alpha_slider = Slider( title="Heatmap opacity", value=1.0, start=0.0, end=1.0, step=0.05, width=220, ) def make_collapsible(title: str, body, initially_open: bool = False): """Wrap a Bokeh widget in a toggle-able collapsible section.""" btn = Toggle( label=("▼ " if initially_open else "▶ ") + title, active=initially_open, button_type="light", width=500, height=30, ) body.visible = initially_open btn.js_on_click(CustomJS(args=dict(body=body, btn=btn, title=title), code=""" body.visible = btn.active; btn.label = (btn.active ? '▼ ' : '▶ ') + title; """)) return column(btn, body)