Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Generated by OpenSesame 0.27 (Frisky Freud)
- # Mon Jan 21 12:00:42 2013 (posix)
- # <http://www.cogsci.nl/opensesame>
- set foreground "white"
- set subject_parity "even"
- set description "A template containing a practice and an experimental phase"
- set title "Extended template"
- set compensation "0"
- set coordinates "relative"
- set height "768"
- set mouse_backend "xpyriment"
- set width "1024"
- set sampler_backend "legacy"
- set keyboard_backend "legacy"
- set background "black"
- set subject_nr "0"
- set canvas_backend "xpyriment"
- set start "experiment"
- set synth_backend "legacy"
- define loop patch_loop
- set repeat "1"
- set description "A single block of trials"
- set skip "0"
- set offset "no"
- set item "stream_of_patches"
- set column_order ""
- set cycles "1"
- set order "random"
- run stream_of_patches
- define sequence vigilance_task
- set flush_keyboard "yes"
- set description "A sequence containing a single block of trials followed by feedback to the participant"
- run patch_loop "always"
- define form_multiple_choice mc
- set allow_multiple "yes"
- set description "A simple multiple choice item"
- set question "Do you like bunnies?"
- set button_text "Ok"
- set advance_immediately "yes"
- set form_title "Form title"
- set form_var "response"
- __options__
- Yes
- No
- Maybe
- __end__
- define sequence stream_of_patches
- set flush_keyboard "yes"
- set description "A single trial"
- run mc "never"
- run inline_script "always"
- define loop experimental_loop
- set repeat "1"
- set description "A loop containing one or more experimental blocks"
- set item "vigilance_task"
- set column_order "practice"
- set cycles "1"
- set order "random"
- setcycle 0 practice "no"
- run vigilance_task
- define sequence experiment
- set flush_keyboard "yes"
- set description "The main sequence of the experiment"
- run constants "always"
- run experimental_loop "always"
- define inline_script constants
- set _run ""
- ___prepare__
- # Here we'll define the visual stimulus list and the
- # auditory stimulus list.
- global patch_list
- patch_list = ["horizontal.png"] * 100 + ["vertical.png"] * 20
- global sound_list
- sound_list = ["sound1.wav", "sound2.wav"]
- global wait, ISI
- # Wait between blank screen and patch (to make it
- # flickering):
- wait = 100
- # Inter stimulus interval:
- ISI = 1000
- __end__
- set description "Executes Python code"
- define inline_script inline_script
- ___run__
- import pygame
- from openexp.exceptions import response_error
- # Start by playing the sound file:
- my_sampler.play()
- sampler_paused = False
- for i in range(len(patch_list)):
- if sampler_paused:
- my_sampler.resume()
- # Determine the stimulus by selecting one item from the
- # stimulus list (without replacement).
- stim = patch_list.pop()
- # Set the stimulus for future use in the GUI (notably, the logger
- # item):
- exp.set("stim", stim)
- # Determine the absolute path to the image in
- # the file pool:
- path = exp.get_file(stim)
- # Show the stimulus:
- # Start with a gray background for a certain duration:
- my_canvas.show()
- self.sleep(1000)
- # Present the patch
- my_canvas.image(path)
- my_canvas.show()
- start_time = self.time()
- time_passed = 0
- while time_passed < ISI:
- # Keep checking whether the duration of this
- # while loop is still below the maximum duration
- # (i.e. ISI).
- time_passed = self.time()-start_time
- print time_passed
- # To poll the keyboard and mouse at the same time, we use pygame
- # directly. This means that this piece of code requires the xpyriment
- # or pygame backend! See:
- # <http://www.pygame.org/docs/ref/event.html>
- button = False
- key = False
- # Loop through all 'events', which are key presses or button clicks
- for event in pygame.event.get([pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN]):
- if event.type == pygame.MOUSEBUTTONDOWN:
- button = True
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- raise response_error("The escape key was pressed.")
- key = True
- # If a key was pressed or a button was clicked, exit the loop
- if button or key:
- break
- # If a mouse response was collected, the for loop will be
- # continued. However, if the spacebar was pressed, we need to
- # do something else:
- if key:
- # Pause the sampler:
- my_sampler.pause()
- sampler_paused = True
- # Show the in-the-GUI-prepared form items:
- self.experiment.items['mc'].prepare()
- self.experiment.items['mc'].run()
- __end__
- ___prepare__
- # Create a canvas item to display the stimulus:
- global my_canvas
- from openexp.canvas import canvas
- my_canvas = canvas(exp, bgcolor = "gray")
- # Create a sampler item that we'll need for playing
- # the sounds.
- global my_sampler
- from openexp.sampler import sampler
- # Determine the to-be-played sound file:
- sound_stim = sound_list.pop()
- sound_file = exp.get_file(sound_stim)
- my_sampler = sampler(exp, sound_file)
- __end__
- set description "Executes Python code"
Advertisement
Add Comment
Please, Sign In to add comment