[visionegg] the attachments...

shit...don't know, why they are not attached... here they are inline:

------------------------------------------------------------------------------
FOR THE MOUSE INPUT:
------------------------------------------------------------------------------
------------------------------------------------------------------------------
#!/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 = 0.10 # 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)


########################
#  Define controllers  #
########################
class MouseButtonController( Controller ):
    def __init__(self):
        Controller.__init__(self,
                            return_type=type(None),
                            eval_frequency=Controller.EVERY_FRAME)

    def during_go_eval(self,t=None):
        # do the following ...
        return None

#############################################
#  Create event handler callback functions  #
#############################################

# mouse state global variables
pressed = 0
released = 0
button_press_time = []

def mousebuttondown(event):
    global pressed
    if event.type == pygame.locals.MOUSEBUTTONDOWN:
        pressed = 1
        button_press_time.append(VisionEgg.timing_func())
        
def mousebuttonup(event):
    global released
    if event.type == pygame.locals.MOUSEBUTTONUP:
        released = 1

        
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(None, None, MouseButtonController() )
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(x+'\n')
f.close()

------------------------------------------------------------------------------
------------------------------------------------------------------------------

FOR THE TRIGGER INPUT

------------------------------------------------------------------------------
------------------------------------------------------------------------------
#!/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 *
import VisionEgg.Daq                 #for trigger input
from VisionEgg.DaqLPT import *       #for trigger input
from math import *
import pygame                        #for mouse input

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 = 0.10 # 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)


########################
#  Define controllers  #
########################
class MouseButtonController( Controller ):
    def __init__(self):
        Controller.__init__(self,
                            return_type=type(None),
                            eval_frequency=Controller.EVERY_FRAME)

    def during_go_eval(self,t=None):
        # do the following ...
        return None

#############################################
#  Create event handler callback functions  #
#############################################

# mouse state global variables
pressed = 0
released = 0
button_press_time = []

def mousebuttondown(event):
    global pressed
    if event.type == pygame.locals.MOUSEBUTTONDOWN:
        pressed = 1
        button_press_time.append(VisionEgg.timing_func())
        
def mousebuttonup(event):
    global released
    if event.type == pygame.locals.MOUSEBUTTONUP:
        released = 1

        
handle_event_callbacks = [(pygame.locals.MOUSEBUTTONDOWN,
mousebuttondown),
                          (pygame.locals.MOUSEBUTTONUP, mousebuttonup)]

p = Presentation(go_duration=(duration_per_image *
num_images,'seconds'),
                 trigger_go_if_armed=0, # wait for trigger
                 viewports=[viewport],
                 check_events=1,
                 handle_event_callbacks=handle_event_callbacks)

#############################################################
#  Connect the controllers with the variables they control  #
#############################################################

#### Mouse input stuff ...
p.add_controller(None, None, MouseButtonController() )

#### Usual stuff ...
p.add_controller(viewport,'stimuli',
                 FunctionController(during_go_func=image_selector) )

#### Trigger input stuff ...
# Stimulus on controller
stimulus_on_controller =
ConstantController(during_go_value=1,between_go_value=0)

# Create a trigger input controller
trigger_in_controller = LPTTriggerInController()

# Add the trigger output controller to the presentation's list of
controllers
p.add_controller(stimulus,'on',stimulus_on_controller)
p.add_controller(p,'trigger_go_if_armed',trigger_in_controller)

#######################
#  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(x+'\n')
f.close()






======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html

Other related posts: