Spaces:
Sleeping
Sleeping
File size: 1,460 Bytes
4c1c394 fb9c7be 4c1c394 fb9c7be 4c1c394 fb9c7be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """
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)
|