Skip to content

Input Dialogs

This SightLab example demonstrates how to display a series of dialog prompts to collect participant demographic and consent information using Vizard’s vizinput module, and log each response to the experiment summary.

Overview

Before trials begin, participants are prompted to enter age, gender, ethnicity, employment status (and job title if employed), and name. A final consent message appears before the main simulation starts.

Code Example

import sightlab_utils.sightlab as sl
from sightlab_utils.settings import *

# Initialize SightLab (default GUI mode)
sightlab = sl.SightLab()

def sightLabExperiment():
    # Wait for experiment start trigger
yield viztask.waitEvent(EXPERIMENT_START)
    # Allow resetting view with 'R' key
    viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)

    for trial in range(sightlab.getTrialCount()):
        # Wait for trial start event
        yield viztask.waitEvent(TRIAL_START)

        import vizinput

        # Store responses in a dict
        responses = {}

        # --- Demographic Prompts ---
        responses['Age'] = vizinput.input("What is your age?")
        responses['Gender'] = vizinput.choose(
            "What is your gender?",
            ["Male", "Female", "Other", "Prefer not to answer"]
        )
        responses['Ethnicity'] = vizinput.choose(
            "What is your ethnicity?",
            [
                "White/Caucasian (non-Hispanic)",
                "African American",
                "Hispanic/Latino",
                "Asian/Pacific Islander",
                "Middle Eastern/West Asian",
                "Other"
            ]
        )
        # Yes/No returns 1 or 0
        responses['Employed'] = vizinput.ask("Are you currently employed?")

        # If employed, ask for job title
        if responses['Employed']:
            responses['Job Title'] = vizinput.input("What is your job title?")

        # Log each response
        for key, value in responses.items():
            sightlab.setExperimentSummaryData(key, value)

        # --- Name & Consent ---
        vizinput.message("Please enter your name in the space provided.")
        responses['Name'] = vizinput.input("Enter your name:")
        sightlab.setExperimentSummaryData('Name', responses['Name'])

        vizinput.message(
            "By clicking continue, you consent to participate. The simulation will begin after you close this dialog."
        )

        # put any other code to run to run in your trial
        #wait for the specified end trial condition (either set in the GUI or code. Spacebar in this case)
        yield viztask.waitEvent(TRIAL_END)

# Schedule SightLab
viztask.schedule(sightlab.runExperiment)
viztask.schedule(sightLabExperiment)

How It Works

  1. Initialization: A SightLab instance is created in default (GUI) mode.
  2. Start Events: The script waits for EXPERIMENT_START and TRIAL_START events before showing any dialogs.
  3. Demographic Collection:
  4. vizinput.input(prompt) opens a text-entry dialog.
  5. vizinput.choose(prompt, options) opens a multiple-choice dialog.
  6. vizinput.ask(prompt) returns a boolean-like value (1 = Yes, 0 = No).
  7. Logging: Each answer is stored via sightlab.setExperimentSummaryData(key, value) for later export.
  8. Consent Prompt: A final message confirms participant consent.
  9. Flow Control: yield viztask.waitEvent(TRIAL_END) signals the end of the dialog trial.

Customization Options

  • Additional Questions: Insert more vizinput calls for questionnaires or experience ratings.
  • Validation: Add Python checks on input (e.g., numeric ranges for age) before logging.
  • Sequential Triggers: Use textContinueEvent in startTrial to tie dialogs to button presses.
  • GUI Integration: Combine with SightLab’s GUI workflow to launch dialogs automatically.

Running the Example

  1. Place this script in your Sightlab project folder.
  2. Adjust trial count or environment settings via your SightLab GUI or settings.py.
  3. Launch in Vizard/SightLab; dialogs will appear before each trial sequence.
Was this page helpful?