Skip to content

gallery

gallery #

Gallery — a grid of pictures, captioned by their keys when keyed.

Gallery #

Bases: Component

images in a grid; a keyed collection captions each picture with its key.

Built with of, each picture links to its entry's page; given plainly, the pictures link nowhere. An entry with no picture is left out. Any still image shows, as a thumbnail transcoded once and kept.

cgui.Gallery(target.sessions.photo)  # captioned by capture time
cgui.Gallery(target.sessions.values()[-1].images)
cgui.Gallery([target.reference, target.sessions.values()[-1].photo])
cgui.Gallery.of(target.sessions, lambda s: s.photo)
Source code in capturegraph-ui/capturegraph_ui/viewers/gallery.py
class Gallery(Component):
    """``images`` in a grid; a keyed collection captions each picture with its key.

    Built with ``of``, each picture links to its entry's page; given plainly,
    the pictures link nowhere. An entry with no picture is left out. Any still
    image shows, as a thumbnail transcoded once and kept.

    ```python
    cgui.Gallery(target.sessions.photo)  # captioned by capture time
    cgui.Gallery(target.sessions.values()[-1].images)
    cgui.Gallery([target.reference, target.sessions.values()[-1].photo])
    cgui.Gallery.of(target.sessions, lambda s: s.photo)
    ```
    """

    images: list[cg.StillImageFile] | cg.Map | cg.Array
    entries: Entries | None = None

    @classmethod
    def of[K, E](
        cls,
        container: cg.Map[K, E] | cg.Array[E],
        image: Callable[[E], cg.StillImageFile | None],
    ) -> Self:
        """A gallery of ``image`` over ``container``'s elements, each linked to its entry's page.

        Args:
            container: A ``Map`` or ``Array``, such as ``target.sessions``.
            image: The picture for one element — any still image;
                ``None`` (or ``Missing``) leaves that entry out.

        ```python
        cgui.Gallery.of(target.sessions, lambda s: s.photo)
        ```
        """
        images, entries = entries_of(container, image, cls.__name__)
        return cls(images, entries=entries)

    def html(self, render: Render) -> str:
        """A grid of figures, one per image."""
        items = items_of(self.images)
        hrefs = item_hrefs(render, self.entries, len(items))
        shown = web_images([image for _, _, image in items], THUMBNAIL_AXIS)
        return element(
            "div",
            {"class": "cg-gallery"},
            *(
                picture(
                    render.stage(image),
                    None if key is None else caption(key),
                    None if key is None else label_html(key),
                    href,
                )
                for (_, key, _), image, href in zip(items, shown, hrefs, strict=True)
                if not cg.is_missing(image)
            ),
        )

html(render) #

A grid of figures, one per image.

Source code in capturegraph-ui/capturegraph_ui/viewers/gallery.py
def html(self, render: Render) -> str:
    """A grid of figures, one per image."""
    items = items_of(self.images)
    hrefs = item_hrefs(render, self.entries, len(items))
    shown = web_images([image for _, _, image in items], THUMBNAIL_AXIS)
    return element(
        "div",
        {"class": "cg-gallery"},
        *(
            picture(
                render.stage(image),
                None if key is None else caption(key),
                None if key is None else label_html(key),
                href,
            )
            for (_, key, _), image, href in zip(items, shown, hrefs, strict=True)
            if not cg.is_missing(image)
        ),
    )

of(container, image) classmethod #

A gallery of image over container's elements, each linked to its entry's page.

Parameters:

Name Type Description Default
container Map[K, E] | Array[E]

A Map or Array, such as target.sessions.

required
image Callable[[E], StillImageFile | None]

The picture for one element — any still image; None (or Missing) leaves that entry out.

required
cgui.Gallery.of(target.sessions, lambda s: s.photo)
Source code in capturegraph-ui/capturegraph_ui/viewers/gallery.py
@classmethod
def of[K, E](
    cls,
    container: cg.Map[K, E] | cg.Array[E],
    image: Callable[[E], cg.StillImageFile | None],
) -> Self:
    """A gallery of ``image`` over ``container``'s elements, each linked to its entry's page.

    Args:
        container: A ``Map`` or ``Array``, such as ``target.sessions``.
        image: The picture for one element — any still image;
            ``None`` (or ``Missing``) leaves that entry out.

    ```python
    cgui.Gallery.of(target.sessions, lambda s: s.photo)
    ```
    """
    images, entries = entries_of(container, image, cls.__name__)
    return cls(images, entries=entries)