Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.clear()
- # We have to draw something in order to clear the background.
- my_canvas.circle(0,0,0,color=self.get('background'))
- my_canvas.show()
- self.sleep(100)
- # 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.")
- elif event.key == pygame.K_SPACE:
- key = True
- # If a key was pressed or a button was clicked, exit the loop
- if button or key:
- break
- # Set the given responses so that they will be logged by
- # the logger item. Note that for the variable "mouse_click" (see below)
- # True' indicates that a mouse click was given, whereas'False'
- # indicates that no mouse response was given. This, in combination
- # with the variable 'stim', will enable you to evaluate participants'
- # performance (i.e. whether a mouse click was correct or a false alarm, etc.):
- exp.set("mouse_click", button)
- # 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()
- # Finally, log the responses:
- self.experiment.items['logger'].prepare()
- self.experiment.items['logger'].run()
- # And set the variable 'form_response' to 'NA' again.
- exp.set('form_response', "NA")
Advertisement
Add Comment
Please, Sign In to add comment