Skip to content

sweetbean.stimulus.RichInstructions

Rich, scroll-friendly instruction screens (html-keyboard-response).

SweetBean ships a global div { font-size: 36pt } in main.css. Long instruction pages must wrap content in a scoped stylesheet or nested divs inherit that size. This module provides the same pattern as :class:InformedConsent: a single wrapper (.sweetbean-rich-instructions) with defensive typography and semantic hooks for your inner HTML.

Inner HTML conventions (all optional — plain <p> / <h3> work too):

  • <h3 class="sbri-section">…</h3> — section heading (larger than body text).
  • <ul class="sbri-panel-list">…</ul> — inset list / meta panel.
  • <span class="sbri-accent">…</span> — subtle highlight (e.g. percentages).
  • <div class="sbri-example">…</div> — boxed preview block.
  • <div class="sbri-example-prompt">…</div> — prompt line inside the example.
  • <div class="sbri-example-row">…</div> — horizontal row (e.g. two cards).
  • <div class="sbri-example-keys">…</div> — key legend under the example.
  • <p class="sbri-muted">…</p> — secondary note text.
  • <p class="sbri-press">…</p> — footer; used by the default footer when footer_html is omitted.

Pass arbitrary HTML fragments as inner_html; they are inserted verbatim (only the document title string is escaped).

RichInstructions

Bases: HtmlKeyboardResponse

Instruction page with readable typography on SweetBean's dark full-screen UI.

Participants press SPACE (by default) to continue. Auto-fit is off by default so long text scrolls naturally.

Source code in sweetbean/stimulus/RichInstructions.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
class RichInstructions(HtmlKeyboardResponse):
    """
    Instruction page with readable typography on SweetBean's dark full-screen UI.

    Participants press SPACE (by default) to continue. Auto-fit is **off** by
    default so long text scrolls naturally.
    """

    fit_to_viewport = False

    def __init__(
        self,
        *,
        title: str = "Instructions",
        inner_html: str,
        footer_html: str | None = None,
        duration: Any = None,
        choices: list[str] | None = None,
        correct_key: str = "",
        side_effects: Any = None,
        fit_to_viewport: bool | None = None,
        max_width_px: int = 780,
        body_font_px: int = 13,
        title_font_px: int = 32,
        section_font_px: int = 20,
    ):
        if choices is None:
            choices = [" "]
        stimulus_html = render_rich_instructions_html(
            title=title,
            inner_html=inner_html,
            footer_html=footer_html,
            max_width_px=max_width_px,
            body_font_px=body_font_px,
            title_font_px=title_font_px,
            section_font_px=section_font_px,
        )
        super().__init__(
            duration=duration,
            stimulus=stimulus_html,
            choices=choices,
            correct_key=correct_key,
            side_effects=side_effects,
            fit_to_viewport=fit_to_viewport,
        )

render_rich_instructions_html(*, title='Instructions', inner_html, footer_html=None, max_width_px=780, body_font_px=13, title_font_px=32, section_font_px=20)

Return a full <style> + wrapper HTML string (for reuse outside the stimulus).

Source code in sweetbean/stimulus/RichInstructions.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
def render_rich_instructions_html(
    *,
    title: str = "Instructions",
    inner_html: str,
    footer_html: str | None = None,
    max_width_px: int = 780,
    body_font_px: int = 13,
    title_font_px: int = 32,
    section_font_px: int = 20,
) -> str:
    """Return a full ``<style>`` + wrapper HTML string (for reuse outside the stimulus)."""
    foot = (
        footer_html
        if footer_html is not None
        else "<p class='sbri-press'><strong>Press SPACE to continue.</strong></p>"
    )
    safe_title = html.escape(str(title).strip() or "Instructions", quote=True)
    vars_inline = (
        f"--sbri-max-width:{int(max_width_px)}px;"
        f"--sbri-body:{int(body_font_px)}px;"
        f"--sbri-title:{int(title_font_px)}px;"
        f"--sbri-section:{int(section_font_px)}px;"
    )
    return (
        _BASE_STYLE
        + f"<div class='sweetbean-rich-instructions' style='{vars_inline}'>"
        + f"<h2 class='sbri-title'>{safe_title}</h2>"
        + inner_html
        + foot
        + "</div>"
    )