Group prompt
************

A prompt that shows the members of a small group, and later their
answers.

Round-based games with a handful of players share a common display:
everyone in the group as an animal, ticks for who has answered, and
then everyone's answer in a speech bubble. "GroupPrompt" draws that
display above a page's controls.

Design constraints:

* Members are shown by pseudonym ("psynet.pseudonym"), or all as the
  same figure with "names="anonymous"", never by participant ID. The
  page refers to members by seat ("psynet.sync.group_seats()"), which
  is also how "GroupBarrier" reports live ticks.

* By default a member has answered once they are waiting at a barrier
  of the group ("psynet.sync._is_waiting_at_barrier"), typically the
  barrier after the decision page. Live ticks come from that barrier's
  arrival updates, so they don't work with "on_arrival_message=None".
  A member who reached the barrier because their page's time limit ran
  out gets a dash instead of a tick
  ("psynet.sync.reached_barrier_after_time_limit()").

* Live redraws re-create the prompt on the server from a signed token,
  so only options that can be serialized take part in them; functions
  and "answers" fix the display when the page loads.

* Who is drawn follows two rules based on stored facts: the group's
  active members, plus, on a results page, everyone in "answers". A
  former member drawn for their answer is faded and labelled "(left)"
  unless their stored removal reason
  ("psynet.sync.SyncGroup.remove_participant()") is moving on or
  finishing (see Showing the group).

* The HTML is built on the server; "static/scripts/group-prompt.js"
  only updates it live (ticks, dashes and joining or leaving members),
  so pages without JavaScript still show the group.

class psynet.group_prompt.GroupPrompt(text=None, *, participant, group=_PARTICIPANTS_GROUP, group_type=None, answers=None, highlight=None, note=None, show_progress=None, names='on_hover', text_align='left')

   Bases: "Prompt"

   Shows the members of a group, who has answered, and their answers.

   Members appear as their pseudonym animals drawn in their colours
   ("sticker_html"; see Pseudonyms): in a row for up to four people,
   and in a zigzag across the width of the page for more. Hovering
   over or tapping a member brings their speech bubble to the front.
   The prompt draws the group's active members, plus, with "answers",
   everyone who has an entry there, even after they left the group
   (see Showing the group).

   A page shows either progress (ticks for who has answered) or
   "answers". A progress page updates live: ticks and dashes as
   members reach a barrier of the group, and members as they join or
   leave. A page with "answers" is fixed when it loads.

   Parameters:
      * **text** -- Text shown above the group, as for "Prompt".

      * **participant** -- The participant viewing the page.

      * **group** -- The "SyncGroup" to show. By default, the
        participant's group of type "group_type", or, if they have
        only ever been in groups of one type, their group of that
        type; a participant who is or has been in groups of several
        types needs "group_type" or "group". If the lookup finds no
        group, for example because a barrier removed them for being
        late, the page shows just "text", as it does for "group=None".
        A group passed explicitly, such as "trial.sync_group", which
        keeps the group the trial was played in, is drawn even if the
        viewer has left it.

      * **group_type** ("Optional"["str"]) -- The type of group to
        show when "group" is omitted, for example ""pair"".

      * **answers** ("Optional"["Dict"["Union"["int", "str"],
        "Union"["str", "Markup", "None"]]]) -- Optional
        "{participant_id: answer}" to show in speech bubbles, for
        example after the group's barrier has released. Answers are
        shown as text; pass "Markup" for HTML such as an image.
        Members with an entry, even "None" (as for a member who ran
        out of time), are drawn even after they left the group, for
        example for their next group; "None" shows no bubble. A former
        member is faded and labelled "(left)", unless they moved on or
        finished ("reason="moved_on"" or ""finished""). Active members
        without an entry get no bubble.

      * **highlight** ("Optional"["Dict"["Union"["int", "str"],
        "str"]]) -- Optional "{participant_id: style}". ""winner"" and
        ""duplicate"" have built-in styles; any other style becomes
        the CSS class "psynet-group-member--<style>". In both
        dictionaries the IDs may be strings, as in a dictionary read
        back from a participant variable.

      * **note** ("Optional"["str"]) -- Optional short text shown
        below the group, for example "1 was picked twice". Like the
        group, it is hidden when there is no group to show.

      * **show_progress** ("Optional"["bool"]) -- Whether members who
        have answered get a tick. A member who reached a barrier of
        the group because their page's time limit ran out gets a dash
        instead. While ticks appear live, the page hides the group
        arrival notice ("2/3 of your group are ready."), which would
        repeat them. Defaults to "True", or "False" with "answers",
        which can't be combined with "True".

      * **names** ("str") --

        How members other than the viewer, who is labelled "You", are
        named:

        * ""on_hover"" (default): by pseudonym, read out by screen
          readers and shown on hover;

        * ""shown"": by pseudonym, also written below each animal;

        * ""anonymous"": all drawn as the same neutral figure,
          labelled below with "Your partner" in the viewer's pair and
          "Another player" otherwise, so that nobody can recognise a
          member they met in an earlier group. Pair it with
          "ChatRoom(names="anonymous")" on pages with a chat room.

      * **text_align** ("str") -- CSS alignment of the text.

   get_css()

      Page-local CSS for the group display.

   get_js_page_modules()

      The module that adds ticks as members answer.

   get_js_vars()

      Configuration for live ticks.

   property group_html: Markup

      HTML for the group display, or nothing without a group.

   property plain_text

      The prompt's text followed by its "note", which shows only with
      a group.

psynet.group_prompt.redrawn_group_html(unique_id, token)

   Return "{"html": ...}", the group display a live page shows, drawn
   again now.

   Parameters:
      * **unique_id** (*str*) -- The participant's unique ID.

      * **token** (*str*) -- The page's redraw token (see
        "GroupPrompt.get_js_vars").

   Returns:
      "{"html": None}" if the token is invalid or belongs to someone
      else.

   Return type:
      dict
