[visionegg] mouse works -now: right/left mouse button and reaction Time
- From: Christoph Lehmann <lehmann@xxxxxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Tue, 10 Dec 2002 14:25:35 +0100
Hi Andrew
Thanks for the hint with the unnecessary controller... now it works
fine, I get the time, the mouse is pressed in the file logged at the
end.
1) I have to know, which button has been pressed: LEFT or RIGHT
what is the most easiest way, to achieve this?
2) the timing of the mouse press is now nicely logged. but what I need,
to get the reaction time, is the exact time, where the picture has been
swapped to the screen. How can I log this time together with the name of
the stimulus for each stimulus?
when we have this, there is a lot of stuff already achieved.
now, only waiting for each stimulus for the next trigger needs to be
implemented
-> 3)
thanks a lot!!
Christoph
-------------------------------------------------------------
#!/usr/bin/env python
"""Load a picture from a file."""
############################
# Import various modules #
############################
from random import *
import os
from VisionEgg import *
from VisionEgg.Core import *
from VisionEgg.Textures import *
from math import *
import pygame
path =
"/home/christoph/work/programming/my_ve_projects/load_picture/data/"
#the path the images are in
photo = []
photoX = []
# present them in random order
for filename in os.listdir(path):
photo.append(filename)
length = len(photo)
for i in range(0, length):
ran = randint(0, len(photo)-1)
file = photo[ran]
photoX.append(file)
photo.pop(ran)
os.chdir(path)
screen = get_default_screen()
duration_per_image = 1 # seconds
num_images = len(photoX)
# Create list of stimuli
preloaded_stimulus_list = [] # empty at first
for i in range(num_images):
# Read the texture file
texture = TextureFromFile(photoX[i])
x = screen.size[0]/2 - texture.orig.size[0]/2
y = screen.size[1]/2 - texture.orig.size[1]/2
# Load the texture to OpenGL, prepare for display
stimulus = TextureStimulus(texture = texture,
size = texture.orig.size,
lowerleft=(x,y))
# Add to list of stimuli
preloaded_stimulus_list.append( stimulus )
def image_selector( t ):
i = int(t/duration_per_image)
return [ preloaded_stimulus_list[i] ]
viewport = Viewport(screen=screen)
#############################################
# Create event handler callback functions #
#############################################
# mouse state global variables
pressed = 0
released = 0
button_press_time = []
def mousebuttondown(event):
global pressed
button_press_time.append(VisionEgg.timing_func())
def mousebuttonup(event):
global released
handle_event_callbacks = [(pygame.locals.MOUSEBUTTONDOWN,
mousebuttondown),
(pygame.locals.MOUSEBUTTONUP, mousebuttonup)]
p = Presentation(go_duration=(duration_per_image *
num_images,'seconds'),
viewports=[viewport],
check_events=1,
handle_event_callbacks=handle_event_callbacks)
#############################################################
# Connect the controllers with the variables they control #
#############################################################
p.add_controller(viewport,'stimuli',
FunctionController(during_go_func=image_selector) )
#######################
# Run the stimulus! #
#######################
p.go()
############################################
# write the button press times to a file #
############################################
f=open('/home/christoph/work/programming/my_ve_projects/load_picture/exp_log_file',
'w')
for x in button_press_time:
f.write(repr(x)+'\n')
f.close()
----------------------------------------------------------
--
Christoph Lehmann
Department of Psychiatric Neurophysiology
University Hospital of Clinical Psychiatry
Waldau
CH-3000 Bern 60
Switzerland
Phone: ++41 31 930 93 83
Fax: ++41 31 930 96 61
Email: lehmann@xxxxxxxxxxxx
Web:
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
Other related posts:
- » [visionegg] mouse works -now: right/left mouse button and reaction Time