Beispiel #1
0
def present_trial(chosen_for_sequence,window_positions,images,the_blob):
	#to calculate proportion of looks
	w0,w1,w2,w3=0,0,0,0
	w0_counter = 0
	item_start=time()
	#in order to pause the experiment
	global paused
	if not paused:

		#haven't looked away yet, keep running
		started_lookaway = False

		#if they lookaway for _ seconds
		lookaway_for_time =2.0

		if not use_tobii_sim:
		# start recording the "eye gaze" data
			tobii_controller.start_tracking()

		# A queue of animation operations
		trial_start = time()
		#create the windows as TobiiSprites so they are eye-trackable

		w0 = TobiiSprite(screen, window_positions[0], kstimulus("laura_diss/window.jpg"), scale=.35,tobii_controller=tobii_controller)
		w1 = TobiiSprite(screen, window_positions[1], kstimulus("laura_diss/window.jpg"), scale=.35,tobii_controller=tobii_controller)
		w2 = TobiiSprite(screen, window_positions[2], kstimulus("laura_diss/window.jpg"), scale=.35,tobii_controller=tobii_controller)
		w3 = TobiiSprite(screen, window_positions[3], kstimulus("laura_diss/window.jpg"), scale=.35,tobii_controller=tobii_controller)
		# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

		images = [
		CommandableImageSprite(screen, OFF_LEFT, images[0], scale=IMAGE_SCALE, name="0"),
		CommandableImageSprite(screen, OFF_LEFT, images[1], scale=IMAGE_SCALE,name="1"),
		CommandableImageSprite(screen, OFF_LEFT, images[2], scale=IMAGE_SCALE,name="2"),
		CommandableImageSprite(screen, OFF_LEFT, images[3], scale=IMAGE_SCALE,name="3")]

		img = CommandableImageSprite(screen, OFF_LEFT,chosen_for_sequence[0][0] , scale=IMAGE_SCALE)

		#create the display Queue and queue up all the images
		Q = DisplayQueue()

		for value in chosen_for_sequence:


			#img = CommandableImageSprite(screen, OFF_LEFT, value[0], scale=IMAGE_SCALE)
			position = value[1]
			#the animation
			Q.append(obj=images[value[2]], action='wait', duration=1.0)
			Q.append(obj=images[value[2]], action='move', pos=position, duration=0.0)
			Q.append(obj=images[value[2]],action='circlescale',duration=1, amount=.08, period=1)
			Q.append(obj=images[value[2]],action='move',pos=OFF_LEFT,duration=0.0)

		dos = OrderedUpdates(the_blob,w0,w1,w2,w3,images)
		# What order do we draw sprites and things in?
		# Draw and update in this order



		for event in kelpy_standard_event_loop(screen,Q, dos, throw_null_events=True):
			#update
			pygame.display.flip()
			#record the active box
			print >> open(matched,'a'),[time()-exp_start,Q.get_obj().get_name()]

			#tobii_controller.record_event(Q.get_obj().get_name())


			#can stop the experiment on a click event
			if is_click(event):
				if not use_tobii_sim:
					tobii_controller.stop_tracking()
					tobii_controller.close_data_file()
					tobii_controller.destroy()
					quit()
				quit()

				if event.type == pygame.QUIT:
					pygame.quit()
					return

			#item animation time has run out, move on
			if time()-item_start >len(chosen_images_and_quadrants)*2:
				break

			#the kind of complicated lookaway stuff
			if not the_blob.is_looked_at():
				if not started_lookaway:
					print "you started looking away"
					#start tracking how long they are looking away for
					started_lookaway_time = time()
					started_lookaway = True
					print time()-started_lookaway_time

				#if they have looked away for longer than lookaway_for_time, it "counts" as a lookaway
				if (time() - started_lookaway_time > lookaway_for_time):
					print "HEY YOURE NOT LOOKING"
					break
			#if they look back at the blob, restart the lookaway clock
			elif the_blob.is_looked_at():
				started_lookaway=False

			if is_space_pressed():
				paused=True




		#can unpause by pressing spacebar
		while paused:
			for event in pygame.event.get():
				if event.type==KEYUP:
					if event.key==K_SPACE:
						paused = False


	else:
		#COVERTASK! (will run when sequence == 5)
		cover_task()