Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,59 @@ html[data-theme="dark"] .tigre-strip img { filter: none; }
display: none;
}

/* Demos index: plain images with the title under them, like the home page's
"From real scans" strip. No frames, shadows or hover overlays. The whole
tile stays one link (sphinx-gallery stretches the link over it). */
.sphx-glr-thumbnails {
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
gap: 1.5rem 1rem;
}
.sphx-glr-thumbcontainer,
.sphx-glr-thumbcontainer:hover {
box-shadow: none;
border: 0;
padding: 0;
margin: 0;
min-height: 0;
text-align: left;
align-items: stretch;
gap: 0;
}
.sphx-glr-thumbcontainer[tooltip]::before,
.sphx-glr-thumbcontainer[tooltip]::after,
.sphx-glr-thumbcontainer[tooltip]:hover::before,
.sphx-glr-thumbcontainer[tooltip]:hover::after { display: none; }
.sphx-glr-thumbcontainer img {
display: block;
width: 100%;
max-width: none;
max-height: none;
height: auto;
aspect-ratio: 4 / 3;
object-fit: contain;
background: #FFFFFF;
border: 1px solid var(--pst-color-border);
border-radius: 0.25rem;
}
.bd-content .sphx-glr-thumbcontainer .sphx-glr-thumbnail-title {
position: static;
margin-top: 0.4rem;
padding: 0;
font-size: 0.9rem;
font-weight: 400;
text-align: left;
color: var(--pst-color-text-base);
}
.sphx-glr-thumbcontainer:hover .sphx-glr-thumbnail-title {
color: var(--pst-color-link-hover);
text-decoration: underline;
}
.sphx-glr-thumbcontainer:focus-within {
outline: 3px solid var(--pst-color-accent);
outline-offset: 3px;
border-radius: 0.25rem;
}

/* Code tabs (home and install pages): a quiet frame; orange only on the active tab. */
.bd-content .sd-tab-set > .sd-tab-content {
box-shadow: none;
Expand Down
Binary file added docs/_static/demo-no-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def _wheel_commands():
"show_memory": False,
"write_computation_times": False,
"image_scrapers": ("tigre_demos.scraper",),
# Thumbnail for demos shown without output (they need data or hardware the
# website build does not have): a grey TIGRE icon.
"default_thumb_file": str(pathlib.Path(__file__).parent / "_static" / "demo-no-output.png"),
# Notebooks open in Google Colab (see _colab_button below): their first cell
# installs the latest release's wheel there, and does nothing elsewhere.
"first_notebook_cell": (
Expand Down Expand Up @@ -316,6 +319,55 @@ def _thumbnail_alt(app, exception):
page.write_text(new, encoding="utf-8")


def _demo_thumbnails(app, exception):
"""Tidy the demo thumbnails on the demos index.

- Animated thumbnails become still. Demos that animate a volume get an
animated GIF thumbnail, so the index had a dozen images moving at once;
the animations stay on the demo pages. The kept frame is the one with
most mid-grey pixels, which shows most of the object (the first and last
slices are often empty).
- Demos shown without output get a grey TIGRE icon instead of
sphinx-gallery's blue and yellow placeholder. (``default_thumb_file``
does the same for newly rendered demos; this covers the stored ones.)
"""
if exception is not None or app.builder.format != "html":
return
import numpy as np
from PIL import Image

images = pathlib.Path(app.outdir, "_images")
placeholder = pathlib.Path(app.confdir, "_static", "demo-no-output.png")

def mid_grey(frame):
grey = np.asarray(frame.convert("L"))
return int(((grey > 40) & (grey < 220)).sum())

for thumb in images.glob("sphx_glr_*_thumb.gif"):
with Image.open(thumb) as im:
frames = getattr(im, "n_frames", 1)
if frames < 2:
continue
scores = []
for k in range(frames):
im.seek(k)
scores.append(mid_grey(im))
im.seek(int(np.argmax(scores)))
still = im.convert("RGB")
still.save(thumb)

for thumb in images.glob("sphx_glr_*_thumb.png"):
with Image.open(thumb) as im:
rgb = np.asarray(im.convert("RGB")).astype(int)
size = im.size
blue = (np.abs(rgb - [173, 216, 230]).sum(-1) < 40).mean()
yellow = (np.abs(rgb - [255, 228, 181]).sum(-1) < 40).mean()
if blue > 0.005 and yellow > 0.1:
with Image.open(placeholder) as ph:
ph.convert("RGB").resize(size).save(thumb)


def setup(app):
app.connect("source-read", _colab_button)
app.connect("build-finished", _thumbnail_alt)
app.connect("build-finished", _demo_thumbnails)