def present_trial(imagepath): """ The sprite in this trial will move around the screen based on eye gaze. """ ## This is a TobiiSprite which has activated its Followable state (is_following = True) img = TobiiSprite( screen, spot.center, imagepath, tobii_controller, scale=IMAGE_SCALE) img.enable_follow(); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Set up the updates, etc. # A queue of animation operations Q = DisplayQueue() # Draw a single animation in if you want! # Q.append(obj=img, action='darken', amount=0.5, duration=4.0) # What order do we draw sprites and things in? dos = OrderedUpdates(img) # Draw and update in this order #start tracking tobii_controller.start_tracking() start_time = time() ## The standard event loop in kelpy -- this loops infinitely to process interactions ## and throws events depending on what the user does for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True): #if (img.is_looked_at()): # play_sound(sound_yup_path, wait=True, volume=7.0) # break if( time() - start_time > MAX_DISPLAY_TIME): break # If the event is a click: if is_click(event): break if event.type == QUIT: tobii_controller.close_data_file() tobii_controller.destroy() img.process_follow(event) tobii_controller.stop_tracking() print img.get_look_time() duration = time() - start_time print looking_proportions(dos, duration)
def present_trial(imagepath): """ This is the main function used to run this demo. It is fed an imagepath and uses this to create a CommandableImageSprite offscreen. This Sprite is later moved onto the screen, where it hangs out until it is clicked. """ #create a tobii simulator tobii_sim = TobiiSimController(screen) #create a tobii sprite img = TobiiSprite( screen, spot.center, imagepath, tobii_sim, scale=IMAGE_SCALE) # this sets this sprite to follow eye gaze once it's first looked at img.enable_follow(); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Set up the updates, etc. # A queue of animation operations Q = DisplayQueue() # Draw a single animation in if you want! # What order do we draw sprites and things in? dos = OrderedUpdates(img) # Draw and update in this order ## Note the start time... start_time = time() # start recording the "eye gaze" data tobii_sim.start_tracking() ## The standard event loop in kelpy -- this loops infinitely to process interactions ## and throws events depending on what the user does trial_time = 5.0 for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True): #stay in the event loop until the trial time has passed if (time() - start_time > trial_time): print "trial end" break #can check if the image is being looked at #img.is_following = img.is_looked_at() #have the sprite follow the "eye gaze" img.process_follow(event) #stop collecting "eye gaze" data tobii_sim.stop_tracking()
def present_trial(imagepath): """ This is the main function used to run this demo. It is fed an imagepath and uses this to create a CommandableImageSprite offscreen. This Sprite is later moved onto the screen, where it hangs out until it is clicked. """ ## Images here are commandable sprites, so we can tell them what to do using Q below img = TobiiSprite( screen, spot.center, imagepath, tobii_controller, scale=IMAGE_SCALE) img.enable_follow() drum = DropSprite(screen, (609,407), kstimulus("common_objects/drum.png"), scale=IMAGE_SCALE) img.register_drag_zone(drum) images = [drum, img] # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Set up the updates, etc. # A queue of animation operations Q = DisplayQueue() # What order do we draw sprites and things in? dos = OrderedUpdates(images) # Draw and update in this order start_time = time() #start tracking tobii_controller.start_tracking() ## The standard event loop in kelpy -- this loops infinitely to process interactions ## and throws events depending on what the user does for event in kelpy_standard_event_loop(screen, Q, dos, throw_null_events=True): # This also turns it off when the sprite it not looked at any longer. img.process_follow(event) ## simple, right? if was_dragged_into_zone(event): ## This is a function located in the EventHandler that watches for drag zone events. print "Nice Drumming!" play_sound(kstimulus("sounds/Button-Reverb.wav")) if event.type == QUIT: tobii_controller.close_data_file() tobii_controller.destroy() tobii_controller.stop_tracking()