VideoTest_lastrun.py 62.5 KB
Newer Older
Monica Connelly's avatar
Monica Connelly committed
1 2 3 4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2020.1.3),
Monica Connelly's avatar
Monica Connelly committed
5
    on March 24, 2020, at 12:38
Monica Connelly's avatar
Monica Connelly committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
If you publish work using this script the most relevant publication is:

    Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) 
        PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. 
        https://doi.org/10.3758/s13428-018-01193-y

"""

from __future__ import absolute_import, division

from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding

from psychopy.hardware import keyboard



# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)

# Store info about the experiment session
psychopyVersion = '2020.1.3'
expName = 'VideoTest'  # from the Builder filename that created this script
expInfo = {'participant': '', 'session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
    core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion

# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath='C:\\Users\\conne\\OneDrive\\Desktop\\Video Test Experiment\\VideoTest_lastrun.py',
    savePickle=True, saveWideText=True,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp
frameTolerance = 0.001  # how close to onset before 'same' frame

# Start Code - component code to be run before the window creation

# Setup the Window
win = visual.Window(
    size=(1024, 768), fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
    units='height')
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
    frameDur = 1.0 / round(expInfo['frameRate'])
else:
    frameDur = 1.0 / 60.0  # could not measure, so guess

# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard()

# Initialize components for Routine "Opening"
OpeningClock = core.Clock()
OpeningText = visual.TextStim(win=win, name='OpeningText',
    text="Opening Text\n\nTesting PsychoPy(v2020.1.3) to Pavlovia video mechanics.\n\n\n\nPress 'space bar'",
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
ContKeyResp1 = keyboard.Keyboard()

# Initialize components for Routine "Video1"
Video1Clock = core.Clock()
Vid1Text = visual.TextStim(win=win, name='Vid1Text',
    text='Test SampVidsGAB_GCU',
    font='Arial',
    pos=(0, 0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
Vid1Movie = visual.MovieStim3(
    win=win, name='Vid1Movie',units='norm', 
    noAudio = True,
    filename='SampVidsGAB_GCU.mp4',
    ori=0, pos=(0, 0), opacity=1,
    loop=True,
    size=0.5,
    depth=-1.0,
    )
ContText1 = visual.TextStim(win=win, name='ContText1',
    text="Press 'space bar'",
    font='Arial',
    pos=(0, -0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-2.0);
Vid1keyresp = keyboard.Keyboard()

# Initialize components for Routine "Video2"
Video2Clock = core.Clock()
Vid2Text = visual.TextStim(win=win, name='Vid2Text',
    text='Test CAB_31.mp4',
    font='Arial',
    pos=(0, 0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
ContText2 = visual.TextStim(win=win, name='ContText2',
    text="Press 'space bar'",
    font='Arial',
    pos=(0, -0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);
Vid2Movie = visual.MovieStim3(
    win=win, name='Vid2Movie',units='norm', 
    noAudio = True,
    filename='CAB_31.mp4',
    ori=0, pos=(0, 0), opacity=1,
    loop=True,
    size=0.5,
    depth=-2.0,
    )
Vid2keyresp = keyboard.Keyboard()

Monica Connelly's avatar
Monica Connelly committed
148 149 150 151 152 153 154 155 156 157 158
# Initialize components for Routine "Initiate"
InitiateClock = core.Clock()
InitiateText = visual.TextStim(win=win, name='InitiateText',
    text="Press 'space bar' to start trial.",
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
InitiateKeyResp = keyboard.Keyboard()

Monica Connelly's avatar
Monica Connelly committed
159 160 161 162 163 164 165 166 167
# Initialize components for Routine "VideoLoop"
VideoLoopClock = core.Clock()
VideoLoopText = visual.TextStim(win=win, name='VideoLoopText',
    text='Loop Test',
    font='Arial',
    pos=(0, 0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
Monica Connelly's avatar
Monica Connelly committed
168 169
Resp1Text = visual.TextStim(win=win, name='Resp1Text',
    text='Resp 1',
Monica Connelly's avatar
Monica Connelly committed
170 171 172 173
    font='Arial',
    pos=(0, -0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
Monica Connelly's avatar
Monica Connelly committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    depth=-2.0);
VLKeyResp02 = keyboard.Keyboard()
Resp2Text = visual.TextStim(win=win, name='Resp2Text',
    text='Resp 2',
    font='Arial',
    pos=(0, -0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-4.0);
VLKeyResp24 = keyboard.Keyboard()
Resp3Text = visual.TextStim(win=win, name='Resp3Text',
    text='Resp 3',
    font='Arial',
    pos=(0, -0.4), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-6.0);
VLKeyResp46 = keyboard.Keyboard()

# Initialize components for Routine "IfResp1"
IfResp1Clock = core.Clock()
IfResp1Text = visual.TextStim(win=win, name='IfResp1Text',
    text="Responded during window 1, Trial to repeat.\n\n\nPress 'space bar'",
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);
IfResp1KeyResp = keyboard.Keyboard()

# Initialize components for Routine "IfResp2"
IfResp2Clock = core.Clock()
IfResp2Text = visual.TextStim(win=win, name='IfResp2Text',
    text="Responded during window 2.\n\n\nPress 'space bar'",
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
Monica Connelly's avatar
Monica Connelly committed
212
    depth=-1.0);
Monica Connelly's avatar
Monica Connelly committed
213 214 215 216 217 218 219 220 221 222 223 224
IfResp2KeyResp = keyboard.Keyboard()

# Initialize components for Routine "IfResp3"
IfResp3Clock = core.Clock()
IfResp3Text = visual.TextStim(win=win, name='IfResp3Text',
    text="Responded during window 3.\n\n\nPress 'space bar'",
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);
IfResp3KeyResp = keyboard.Keyboard()
Monica Connelly's avatar
Monica Connelly committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

# Initialize components for Routine "Finish"
FinishClock = core.Clock()
FinishText = visual.TextStim(win=win, name='FinishText',
    text='Test completed',
    font='Arial',
    pos=(0, 0), height=0.05, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0);

# Create some handy timers
globalClock = core.Clock()  # to track the time since experiment started
routineTimer = core.CountdownTimer()  # to track time remaining of each (non-slip) routine 

# ------Prepare to start Routine "Opening"-------
continueRoutine = True
# update component parameters for each repeat
ContKeyResp1.keys = []
ContKeyResp1.rt = []
_ContKeyResp1_allKeys = []
# keep track of which components have finished
OpeningComponents = [OpeningText, ContKeyResp1]
for thisComponent in OpeningComponents:
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
OpeningClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1

# -------Run Routine "Opening"-------
while continueRoutine:
    # get current time
    t = OpeningClock.getTime()
    tThisFlip = win.getFutureFlipTime(clock=OpeningClock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *OpeningText* updates
    if OpeningText.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        OpeningText.frameNStart = frameN  # exact frame index
        OpeningText.tStart = t  # local t and not account for scr refresh
        OpeningText.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(OpeningText, 'tStartRefresh')  # time at next scr refresh
        OpeningText.setAutoDraw(True)
    
    # *ContKeyResp1* updates
    waitOnFlip = False
    if ContKeyResp1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        ContKeyResp1.frameNStart = frameN  # exact frame index
        ContKeyResp1.tStart = t  # local t and not account for scr refresh
        ContKeyResp1.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(ContKeyResp1, 'tStartRefresh')  # time at next scr refresh
        ContKeyResp1.status = STARTED
        # keyboard checking is just starting
        waitOnFlip = True
        win.callOnFlip(ContKeyResp1.clock.reset)  # t=0 on next screen flip
    if ContKeyResp1.status == STARTED and not waitOnFlip:
        theseKeys = ContKeyResp1.getKeys(keyList=['space'], waitRelease=False)
        _ContKeyResp1_allKeys.extend(theseKeys)
        if len(_ContKeyResp1_allKeys):
            ContKeyResp1.keys = _ContKeyResp1_allKeys[-1].name  # just the last key pressed
            ContKeyResp1.rt = _ContKeyResp1_allKeys[-1].rt
            # a response ends the routine
            continueRoutine = False
    
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
    
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in OpeningComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "Opening"-------
for thisComponent in OpeningComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
thisExp.addData('OpeningText.started', OpeningText.tStartRefresh)
thisExp.addData('OpeningText.stopped', OpeningText.tStopRefresh)
# the Routine "Opening" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# ------Prepare to start Routine "Video1"-------
continueRoutine = True
# update component parameters for each repeat
Vid1keyresp.keys = []
Vid1keyresp.rt = []
_Vid1keyresp_allKeys = []
# keep track of which components have finished
Video1Components = [Vid1Text, Vid1Movie, ContText1, Vid1keyresp]
for thisComponent in Video1Components:
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
Video1Clock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1

# -------Run Routine "Video1"-------
while continueRoutine:
    # get current time
    t = Video1Clock.getTime()
    tThisFlip = win.getFutureFlipTime(clock=Video1Clock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *Vid1Text* updates
    if Vid1Text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        Vid1Text.frameNStart = frameN  # exact frame index
        Vid1Text.tStart = t  # local t and not account for scr refresh
        Vid1Text.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(Vid1Text, 'tStartRefresh')  # time at next scr refresh
        Vid1Text.setAutoDraw(True)
    
    # *Vid1Movie* updates
    if Vid1Movie.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        Vid1Movie.frameNStart = frameN  # exact frame index
        Vid1Movie.tStart = t  # local t and not account for scr refresh
        Vid1Movie.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(Vid1Movie, 'tStartRefresh')  # time at next scr refresh
        Vid1Movie.setAutoDraw(True)
    
    # *ContText1* updates
    if ContText1.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        ContText1.frameNStart = frameN  # exact frame index
        ContText1.tStart = t  # local t and not account for scr refresh
        ContText1.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(ContText1, 'tStartRefresh')  # time at next scr refresh
        ContText1.setAutoDraw(True)
    if ContText1.status == STARTED:
        # is it time to stop? (based on global clock, using actual start)
        if tThisFlipGlobal > ContText1.tStartRefresh + 1.0-frameTolerance:
            # keep track of stop time/frame for later
            ContText1.tStop = t  # not accounting for scr refresh
            ContText1.frameNStop = frameN  # exact frame index
            win.timeOnFlip(ContText1, 'tStopRefresh')  # time at next scr refresh
            ContText1.setAutoDraw(False)
    
    # *Vid1keyresp* updates
    waitOnFlip = False
    if Vid1keyresp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        Vid1keyresp.frameNStart = frameN  # exact frame index
        Vid1keyresp.tStart = t  # local t and not account for scr refresh
        Vid1keyresp.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(Vid1keyresp, 'tStartRefresh')  # time at next scr refresh
        Vid1keyresp.status = STARTED
        # keyboard checking is just starting
        waitOnFlip = True
        win.callOnFlip(Vid1keyresp.clock.reset)  # t=0 on next screen flip
        win.callOnFlip(Vid1keyresp.clearEvents, eventType='keyboard')  # clear events on next screen flip
    if Vid1keyresp.status == STARTED and not waitOnFlip:
        theseKeys = Vid1keyresp.getKeys(keyList=['space'], waitRelease=False)
        _Vid1keyresp_allKeys.extend(theseKeys)
        if len(_Vid1keyresp_allKeys):
            Vid1keyresp.keys = _Vid1keyresp_allKeys[-1].name  # just the last key pressed
            Vid1keyresp.rt = _Vid1keyresp_allKeys[-1].rt
            # a response ends the routine
            continueRoutine = False
    
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
    
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in Video1Components:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "Video1"-------
for thisComponent in Video1Components:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
thisExp.addData('Vid1Text.started', Vid1Text.tStartRefresh)
thisExp.addData('Vid1Text.stopped', Vid1Text.tStopRefresh)
thisExp.addData('Vid1Movie.started', Vid1Movie.tStartRefresh)
thisExp.addData('Vid1Movie.stopped', Vid1Movie.tStopRefresh)
thisExp.addData('ContText1.started', ContText1.tStartRefresh)
thisExp.addData('ContText1.stopped', ContText1.tStopRefresh)
# the Routine "Video1" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# ------Prepare to start Routine "Video2"-------
continueRoutine = True
# update component parameters for each repeat
Vid2keyresp.keys = []
Vid2keyresp.rt = []
_Vid2keyresp_allKeys = []
# keep track of which components have finished
Video2Components = [Vid2Text, ContText2, Vid2Movie, Vid2keyresp]
for thisComponent in Video2Components:
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
Video2Clock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1

# -------Run Routine "Video2"-------
while continueRoutine:
    # get current time
    t = Video2Clock.getTime()
    tThisFlip = win.getFutureFlipTime(clock=Video2Clock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *Vid2Text* updates
    if Vid2Text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        Vid2Text.frameNStart = frameN  # exact frame index
        Vid2Text.tStart = t  # local t and not account for scr refresh
        Vid2Text.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(Vid2Text, 'tStartRefresh')  # time at next scr refresh
        Vid2Text.setAutoDraw(True)
    
    # *ContText2* updates
    if ContText2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        ContText2.frameNStart = frameN  # exact frame index
        ContText2.tStart = t  # local t and not account for scr refresh
        ContText2.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(ContText2, 'tStartRefresh')  # time at next scr refresh
        ContText2.setAutoDraw(True)
    
    # *Vid2Movie* updates
    if Vid2Movie.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        Vid2Movie.frameNStart = frameN  # exact frame index
        Vid2Movie.tStart = t  # local t and not account for scr refresh
        Vid2Movie.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(Vid2Movie, 'tStartRefresh')  # time at next scr refresh
        Vid2Movie.setAutoDraw(True)
    
    # *Vid2keyresp* updates
    waitOnFlip = False
    if Vid2keyresp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        Vid2keyresp.frameNStart = frameN  # exact frame index
        Vid2keyresp.tStart = t  # local t and not account for scr refresh
        Vid2keyresp.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(Vid2keyresp, 'tStartRefresh')  # time at next scr refresh
        Vid2keyresp.status = STARTED
        # keyboard checking is just starting
        waitOnFlip = True
        win.callOnFlip(Vid2keyresp.clock.reset)  # t=0 on next screen flip
        win.callOnFlip(Vid2keyresp.clearEvents, eventType='keyboard')  # clear events on next screen flip
    if Vid2keyresp.status == STARTED and not waitOnFlip:
        theseKeys = Vid2keyresp.getKeys(keyList=['space'], waitRelease=False)
        _Vid2keyresp_allKeys.extend(theseKeys)
        if len(_Vid2keyresp_allKeys):
            Vid2keyresp.keys = _Vid2keyresp_allKeys[-1].name  # just the last key pressed
            Vid2keyresp.rt = _Vid2keyresp_allKeys[-1].rt
            # a response ends the routine
            continueRoutine = False
    
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
    
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in Video2Components:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "Video2"-------
for thisComponent in Video2Components:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
thisExp.addData('Vid2Text.started', Vid2Text.tStartRefresh)
thisExp.addData('Vid2Text.stopped', Vid2Text.tStopRefresh)
thisExp.addData('ContText2.started', ContText2.tStartRefresh)
thisExp.addData('ContText2.stopped', ContText2.tStopRefresh)
thisExp.addData('Vid2Movie.started', Vid2Movie.tStartRefresh)
thisExp.addData('Vid2Movie.stopped', Vid2Movie.tStopRefresh)
# the Routine "Video2" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# set up handler to look after randomisation of conditions etc
trialsloop = data.TrialHandler(nReps=1, method='random', 
    extraInfo=expInfo, originPath=-1,
    trialList=data.importConditions('TestConditions.xlsx'),
    seed=None, name='trialsloop')
thisExp.addLoop(trialsloop)  # add the loop to the experiment
thisTrialsloop = trialsloop.trialList[0]  # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisTrialsloop.rgb)
if thisTrialsloop != None:
    for paramName in thisTrialsloop:
        exec('{} = thisTrialsloop[paramName]'.format(paramName))

for thisTrialsloop in trialsloop:
    currentLoop = trialsloop
    # abbreviate parameter names if possible (e.g. rgb = thisTrialsloop.rgb)
    if thisTrialsloop != None:
        for paramName in thisTrialsloop:
            exec('{} = thisTrialsloop[paramName]'.format(paramName))
    
Monica Connelly's avatar
Monica Connelly committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
    # set up handler to look after randomisation of conditions etc
    Resp1Loop = data.TrialHandler(nReps=5, method='sequential', 
        extraInfo=expInfo, originPath=-1,
        trialList=[None],
        seed=None, name='Resp1Loop')
    thisExp.addLoop(Resp1Loop)  # add the loop to the experiment
    thisResp1Loop = Resp1Loop.trialList[0]  # so we can initialise stimuli with some values
    # abbreviate parameter names if possible (e.g. rgb = thisResp1Loop.rgb)
    if thisResp1Loop != None:
        for paramName in thisResp1Loop:
            exec('{} = thisResp1Loop[paramName]'.format(paramName))
    
    for thisResp1Loop in Resp1Loop:
        currentLoop = Resp1Loop
        # abbreviate parameter names if possible (e.g. rgb = thisResp1Loop.rgb)
        if thisResp1Loop != None:
            for paramName in thisResp1Loop:
                exec('{} = thisResp1Loop[paramName]'.format(paramName))
        
        # ------Prepare to start Routine "Initiate"-------
        continueRoutine = True
        # update component parameters for each repeat
        InitiateKeyResp.keys = []
        InitiateKeyResp.rt = []
        _InitiateKeyResp_allKeys = []
        # keep track of which components have finished
        InitiateComponents = [InitiateText, InitiateKeyResp]
        for thisComponent in InitiateComponents:
            thisComponent.tStart = None
            thisComponent.tStop = None
            thisComponent.tStartRefresh = None
            thisComponent.tStopRefresh = None
            if hasattr(thisComponent, 'status'):
                thisComponent.status = NOT_STARTED
        # reset timers
        t = 0
        _timeToFirstFrame = win.getFutureFlipTime(clock="now")
        InitiateClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
        frameN = -1
        
        # -------Run Routine "Initiate"-------
        while continueRoutine:
            # get current time
            t = InitiateClock.getTime()
            tThisFlip = win.getFutureFlipTime(clock=InitiateClock)
            tThisFlipGlobal = win.getFutureFlipTime(clock=None)
            frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
            # update/draw components on each frame
            
            # *InitiateText* updates
            if InitiateText.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                InitiateText.frameNStart = frameN  # exact frame index
                InitiateText.tStart = t  # local t and not account for scr refresh
                InitiateText.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(InitiateText, 'tStartRefresh')  # time at next scr refresh
                InitiateText.setAutoDraw(True)
            
            # *InitiateKeyResp* updates
            waitOnFlip = False
            if InitiateKeyResp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                InitiateKeyResp.frameNStart = frameN  # exact frame index
                InitiateKeyResp.tStart = t  # local t and not account for scr refresh
                InitiateKeyResp.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(InitiateKeyResp, 'tStartRefresh')  # time at next scr refresh
                InitiateKeyResp.status = STARTED
                # keyboard checking is just starting
                waitOnFlip = True
                win.callOnFlip(InitiateKeyResp.clock.reset)  # t=0 on next screen flip
                win.callOnFlip(InitiateKeyResp.clearEvents, eventType='keyboard')  # clear events on next screen flip
            if InitiateKeyResp.status == STARTED and not waitOnFlip:
                theseKeys = InitiateKeyResp.getKeys(keyList=['space'], waitRelease=False)
                _InitiateKeyResp_allKeys.extend(theseKeys)
                if len(_InitiateKeyResp_allKeys):
                    InitiateKeyResp.keys = _InitiateKeyResp_allKeys[-1].name  # just the last key pressed
                    InitiateKeyResp.rt = _InitiateKeyResp_allKeys[-1].rt
                    # a response ends the routine
                    continueRoutine = False
            
            # check for quit (typically the Esc key)
            if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
                core.quit()
            
            # check if all components have finished
            if not continueRoutine:  # a component has requested a forced-end of Routine
                break
            continueRoutine = False  # will revert to True if at least one component still running
            for thisComponent in InitiateComponents:
                if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                    continueRoutine = True
                    break  # at least one component has not yet finished
            
            # refresh the screen
            if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
                win.flip()
        
        # -------Ending Routine "Initiate"-------
        for thisComponent in InitiateComponents:
            if hasattr(thisComponent, "setAutoDraw"):
                thisComponent.setAutoDraw(False)
        Resp1Loop.addData('InitiateText.started', InitiateText.tStartRefresh)
        Resp1Loop.addData('InitiateText.stopped', InitiateText.tStopRefresh)
        # the Routine "Initiate" was not non-slip safe, so reset the non-slip timer
        routineTimer.reset()
        
        # ------Prepare to start Routine "VideoLoop"-------
        continueRoutine = True
        # update component parameters for each repeat
        VideoLoopMovie = visual.MovieStim3(
            win=win, name='VideoLoopMovie',units='norm', 
            noAudio = True,
            filename=Vids,
            ori=0, pos=(0, 0), opacity=1,
            loop=True,
            size=0.5,
            depth=-1.0,
            )
        VLKeyResp02.keys = []
        VLKeyResp02.rt = []
        _VLKeyResp02_allKeys = []
        VLKeyResp24.keys = []
        VLKeyResp24.rt = []
        _VLKeyResp24_allKeys = []
        VLKeyResp46.keys = []
        VLKeyResp46.rt = []
        _VLKeyResp46_allKeys = []
        # keep track of which components have finished
        VideoLoopComponents = [VideoLoopText, VideoLoopMovie, Resp1Text, VLKeyResp02, Resp2Text, VLKeyResp24, Resp3Text, VLKeyResp46]
        for thisComponent in VideoLoopComponents:
            thisComponent.tStart = None
            thisComponent.tStop = None
            thisComponent.tStartRefresh = None
            thisComponent.tStopRefresh = None
            if hasattr(thisComponent, 'status'):
                thisComponent.status = NOT_STARTED
        # reset timers
        t = 0
        _timeToFirstFrame = win.getFutureFlipTime(clock="now")
        VideoLoopClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
        frameN = -1
        
        # -------Run Routine "VideoLoop"-------
        while continueRoutine:
            # get current time
            t = VideoLoopClock.getTime()
            tThisFlip = win.getFutureFlipTime(clock=VideoLoopClock)
            tThisFlipGlobal = win.getFutureFlipTime(clock=None)
            frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
            # update/draw components on each frame
            
            # *VideoLoopText* updates
            if VideoLoopText.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                VideoLoopText.frameNStart = frameN  # exact frame index
                VideoLoopText.tStart = t  # local t and not account for scr refresh
                VideoLoopText.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(VideoLoopText, 'tStartRefresh')  # time at next scr refresh
                VideoLoopText.setAutoDraw(True)
            
            # *VideoLoopMovie* updates
            if VideoLoopMovie.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                VideoLoopMovie.frameNStart = frameN  # exact frame index
                VideoLoopMovie.tStart = t  # local t and not account for scr refresh
                VideoLoopMovie.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(VideoLoopMovie, 'tStartRefresh')  # time at next scr refresh
                VideoLoopMovie.setAutoDraw(True)
            
            # *Resp1Text* updates
            if Resp1Text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                Resp1Text.frameNStart = frameN  # exact frame index
                Resp1Text.tStart = t  # local t and not account for scr refresh
                Resp1Text.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(Resp1Text, 'tStartRefresh')  # time at next scr refresh
                Resp1Text.setAutoDraw(True)
            if Resp1Text.status == STARTED:
                # is it time to stop? (based on local clock)
                if tThisFlip > 2.0-frameTolerance:
                    # keep track of stop time/frame for later
                    Resp1Text.tStop = t  # not accounting for scr refresh
                    Resp1Text.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(Resp1Text, 'tStopRefresh')  # time at next scr refresh
                    Resp1Text.setAutoDraw(False)
            
            # *VLKeyResp02* updates
            waitOnFlip = False
            if VLKeyResp02.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                VLKeyResp02.frameNStart = frameN  # exact frame index
                VLKeyResp02.tStart = t  # local t and not account for scr refresh
                VLKeyResp02.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(VLKeyResp02, 'tStartRefresh')  # time at next scr refresh
                VLKeyResp02.status = STARTED
                # keyboard checking is just starting
                waitOnFlip = True
                win.callOnFlip(VLKeyResp02.clock.reset)  # t=0 on next screen flip
                win.callOnFlip(VLKeyResp02.clearEvents, eventType='keyboard')  # clear events on next screen flip
            if VLKeyResp02.status == STARTED:
                # is it time to stop? (based on global clock, using actual start)
                if tThisFlipGlobal > VLKeyResp02.tStartRefresh + 2.0-frameTolerance:
                    # keep track of stop time/frame for later
                    VLKeyResp02.tStop = t  # not accounting for scr refresh
                    VLKeyResp02.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(VLKeyResp02, 'tStopRefresh')  # time at next scr refresh
                    VLKeyResp02.status = FINISHED
            if VLKeyResp02.status == STARTED and not waitOnFlip:
                theseKeys = VLKeyResp02.getKeys(keyList=['a', 'l'], waitRelease=False)
                _VLKeyResp02_allKeys.extend(theseKeys)
                if len(_VLKeyResp02_allKeys):
                    VLKeyResp02.keys = _VLKeyResp02_allKeys[0].name  # just the first key pressed
                    VLKeyResp02.rt = _VLKeyResp02_allKeys[0].rt
                    # was this correct?
                    if (VLKeyResp02.keys == str(CorrAns)) or (VLKeyResp02.keys == CorrAns):
                        VLKeyResp02.corr = 1
                    else:
                        VLKeyResp02.corr = 0
                    # a response ends the routine
                    continueRoutine = False
            
            # *Resp2Text* updates
            if Resp2Text.status == NOT_STARTED and tThisFlip >= 2.0-frameTolerance:
                # keep track of start time/frame for later
                Resp2Text.frameNStart = frameN  # exact frame index
                Resp2Text.tStart = t  # local t and not account for scr refresh
                Resp2Text.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(Resp2Text, 'tStartRefresh')  # time at next scr refresh
                Resp2Text.setAutoDraw(True)
            if Resp2Text.status == STARTED:
                # is it time to stop? (based on local clock)
                if tThisFlip > 4.0-frameTolerance:
                    # keep track of stop time/frame for later
                    Resp2Text.tStop = t  # not accounting for scr refresh
                    Resp2Text.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(Resp2Text, 'tStopRefresh')  # time at next scr refresh
                    Resp2Text.setAutoDraw(False)
            
            # *VLKeyResp24* updates
            waitOnFlip = False
            if VLKeyResp24.status == NOT_STARTED and tThisFlip >= 2.0-frameTolerance:
                # keep track of start time/frame for later
                VLKeyResp24.frameNStart = frameN  # exact frame index
                VLKeyResp24.tStart = t  # local t and not account for scr refresh
                VLKeyResp24.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(VLKeyResp24, 'tStartRefresh')  # time at next scr refresh
                VLKeyResp24.status = STARTED
                # keyboard checking is just starting
                waitOnFlip = True
                win.callOnFlip(VLKeyResp24.clock.reset)  # t=0 on next screen flip
                win.callOnFlip(VLKeyResp24.clearEvents, eventType='keyboard')  # clear events on next screen flip
            if VLKeyResp24.status == STARTED:
                # is it time to stop? (based on local clock)
                if tThisFlip > 4.0-frameTolerance:
                    # keep track of stop time/frame for later
                    VLKeyResp24.tStop = t  # not accounting for scr refresh
                    VLKeyResp24.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(VLKeyResp24, 'tStopRefresh')  # time at next scr refresh
                    VLKeyResp24.status = FINISHED
            if VLKeyResp24.status == STARTED and not waitOnFlip:
                theseKeys = VLKeyResp24.getKeys(keyList=['a', 'l'], waitRelease=False)
                _VLKeyResp24_allKeys.extend(theseKeys)
                if len(_VLKeyResp24_allKeys):
                    VLKeyResp24.keys = _VLKeyResp24_allKeys[0].name  # just the first key pressed
                    VLKeyResp24.rt = _VLKeyResp24_allKeys[0].rt
                    # was this correct?
                    if (VLKeyResp24.keys == str(CorrAns)) or (VLKeyResp24.keys == CorrAns):
                        VLKeyResp24.corr = 1
                    else:
                        VLKeyResp24.corr = 0
                    # a response ends the routine
                    continueRoutine = False
            
            # *Resp3Text* updates
            if Resp3Text.status == NOT_STARTED and tThisFlip >= 4.0-frameTolerance:
                # keep track of start time/frame for later
                Resp3Text.frameNStart = frameN  # exact frame index
                Resp3Text.tStart = t  # local t and not account for scr refresh
                Resp3Text.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(Resp3Text, 'tStartRefresh')  # time at next scr refresh
                Resp3Text.setAutoDraw(True)
            if Resp3Text.status == STARTED:
                # is it time to stop? (based on local clock)
                if tThisFlip > 6.0-frameTolerance:
                    # keep track of stop time/frame for later
                    Resp3Text.tStop = t  # not accounting for scr refresh
                    Resp3Text.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(Resp3Text, 'tStopRefresh')  # time at next scr refresh
                    Resp3Text.setAutoDraw(False)
            
            # *VLKeyResp46* updates
            waitOnFlip = False
            if VLKeyResp46.status == NOT_STARTED and tThisFlip >= 4.0-frameTolerance:
                # keep track of start time/frame for later
                VLKeyResp46.frameNStart = frameN  # exact frame index
                VLKeyResp46.tStart = t  # local t and not account for scr refresh
                VLKeyResp46.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(VLKeyResp46, 'tStartRefresh')  # time at next scr refresh
                VLKeyResp46.status = STARTED
                # keyboard checking is just starting
                waitOnFlip = True
                win.callOnFlip(VLKeyResp46.clock.reset)  # t=0 on next screen flip
                win.callOnFlip(VLKeyResp46.clearEvents, eventType='keyboard')  # clear events on next screen flip
            if VLKeyResp46.status == STARTED:
                # is it time to stop? (based on local clock)
                if tThisFlip > 6.0-frameTolerance:
                    # keep track of stop time/frame for later
                    VLKeyResp46.tStop = t  # not accounting for scr refresh
                    VLKeyResp46.frameNStop = frameN  # exact frame index
                    win.timeOnFlip(VLKeyResp46, 'tStopRefresh')  # time at next scr refresh
                    VLKeyResp46.status = FINISHED
            if VLKeyResp46.status == STARTED and not waitOnFlip:
                theseKeys = VLKeyResp46.getKeys(keyList=['a', 'l'], waitRelease=False)
                _VLKeyResp46_allKeys.extend(theseKeys)
                if len(_VLKeyResp46_allKeys):
                    VLKeyResp46.keys = _VLKeyResp46_allKeys[0].name  # just the first key pressed
                    VLKeyResp46.rt = _VLKeyResp46_allKeys[0].rt
                    # was this correct?
                    if (VLKeyResp46.keys == str(CorrAns)) or (VLKeyResp46.keys == CorrAns):
                        VLKeyResp46.corr = 1
                    else:
                        VLKeyResp46.corr = 0
                    # a response ends the routine
                    continueRoutine = False
            
            # check for quit (typically the Esc key)
            if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
                core.quit()
            
            # check if all components have finished
            if not continueRoutine:  # a component has requested a forced-end of Routine
                break
            continueRoutine = False  # will revert to True if at least one component still running
            for thisComponent in VideoLoopComponents:
                if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                    continueRoutine = True
                    break  # at least one component has not yet finished
            
            # refresh the screen
            if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
                win.flip()
        
        # -------Ending Routine "VideoLoop"-------
        for thisComponent in VideoLoopComponents:
            if hasattr(thisComponent, "setAutoDraw"):
                thisComponent.setAutoDraw(False)
        Resp1Loop.addData('VideoLoopText.started', VideoLoopText.tStartRefresh)
        Resp1Loop.addData('VideoLoopText.stopped', VideoLoopText.tStopRefresh)
        Resp1Loop.addData('VideoLoopMovie.started', VideoLoopMovie.tStartRefresh)
        Resp1Loop.addData('VideoLoopMovie.stopped', VideoLoopMovie.tStopRefresh)
        Resp1Loop.addData('Resp1Text.started', Resp1Text.tStartRefresh)
        Resp1Loop.addData('Resp1Text.stopped', Resp1Text.tStopRefresh)
        # check responses
        if VLKeyResp02.keys in ['', [], None]:  # No response was made
            VLKeyResp02.keys = None
            # was no response the correct answer?!
            if str(CorrAns).lower() == 'none':
               VLKeyResp02.corr = 1;  # correct non-response
            else:
               VLKeyResp02.corr = 0;  # failed to respond (incorrectly)
        # store data for Resp1Loop (TrialHandler)
        Resp1Loop.addData('VLKeyResp02.keys',VLKeyResp02.keys)
        Resp1Loop.addData('VLKeyResp02.corr', VLKeyResp02.corr)
        if VLKeyResp02.keys != None:  # we had a response
            Resp1Loop.addData('VLKeyResp02.rt', VLKeyResp02.rt)
        Resp1Loop.addData('VLKeyResp02.started', VLKeyResp02.tStartRefresh)
        Resp1Loop.addData('VLKeyResp02.stopped', VLKeyResp02.tStopRefresh)
        Resp1Loop.addData('Resp2Text.started', Resp2Text.tStartRefresh)
        Resp1Loop.addData('Resp2Text.stopped', Resp2Text.tStopRefresh)
        # check responses
        if VLKeyResp24.keys in ['', [], None]:  # No response was made
            VLKeyResp24.keys = None
            # was no response the correct answer?!
            if str(CorrAns).lower() == 'none':
               VLKeyResp24.corr = 1;  # correct non-response
            else:
               VLKeyResp24.corr = 0;  # failed to respond (incorrectly)
        # store data for Resp1Loop (TrialHandler)
        Resp1Loop.addData('VLKeyResp24.keys',VLKeyResp24.keys)
        Resp1Loop.addData('VLKeyResp24.corr', VLKeyResp24.corr)
        if VLKeyResp24.keys != None:  # we had a response
            Resp1Loop.addData('VLKeyResp24.rt', VLKeyResp24.rt)
        Resp1Loop.addData('VLKeyResp24.started', VLKeyResp24.tStartRefresh)
        Resp1Loop.addData('VLKeyResp24.stopped', VLKeyResp24.tStopRefresh)
        Resp1Loop.addData('Resp3Text.started', Resp3Text.tStartRefresh)
        Resp1Loop.addData('Resp3Text.stopped', Resp3Text.tStopRefresh)
        # check responses
        if VLKeyResp46.keys in ['', [], None]:  # No response was made
            VLKeyResp46.keys = None
            # was no response the correct answer?!
            if str(CorrAns).lower() == 'none':
               VLKeyResp46.corr = 1;  # correct non-response
            else:
               VLKeyResp46.corr = 0;  # failed to respond (incorrectly)
        # store data for Resp1Loop (TrialHandler)
        Resp1Loop.addData('VLKeyResp46.keys',VLKeyResp46.keys)
        Resp1Loop.addData('VLKeyResp46.corr', VLKeyResp46.corr)
        if VLKeyResp46.keys != None:  # we had a response
            Resp1Loop.addData('VLKeyResp46.rt', VLKeyResp46.rt)
        Resp1Loop.addData('VLKeyResp46.started', VLKeyResp46.tStartRefresh)
        Resp1Loop.addData('VLKeyResp46.stopped', VLKeyResp46.tStopRefresh)
        # If the participant does not respond during the video
        if VLKeyResp02.keys not in ['a', 'l']:
            Resp1Loop.finished = True
        else:
            Resp1Loop.finished = False
        # the Routine "VideoLoop" was not non-slip safe, so reset the non-slip timer
        routineTimer.reset()
        
        # ------Prepare to start Routine "IfResp1"-------
        continueRoutine = True
        # update component parameters for each repeat
        IfResp1KeyResp.keys = []
        IfResp1KeyResp.rt = []
        _IfResp1KeyResp_allKeys = []
        # keep track of which components have finished
        IfResp1Components = [IfResp1Text, IfResp1KeyResp]
        for thisComponent in IfResp1Components:
            thisComponent.tStart = None
            thisComponent.tStop = None
            thisComponent.tStartRefresh = None
            thisComponent.tStopRefresh = None
            if hasattr(thisComponent, 'status'):
                thisComponent.status = NOT_STARTED
        # reset timers
        t = 0
        _timeToFirstFrame = win.getFutureFlipTime(clock="now")
        IfResp1Clock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
        frameN = -1
        
        # -------Run Routine "IfResp1"-------
        while continueRoutine:
            # get current time
            t = IfResp1Clock.getTime()
            tThisFlip = win.getFutureFlipTime(clock=IfResp1Clock)
            tThisFlipGlobal = win.getFutureFlipTime(clock=None)
            frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
            # update/draw components on each frame
            
            # *IfResp1Text* updates
            if IfResp1Text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                IfResp1Text.frameNStart = frameN  # exact frame index
                IfResp1Text.tStart = t  # local t and not account for scr refresh
                IfResp1Text.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(IfResp1Text, 'tStartRefresh')  # time at next scr refresh
                IfResp1Text.setAutoDraw(True)
            
            # *IfResp1KeyResp* updates
            waitOnFlip = False
            if IfResp1KeyResp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
                # keep track of start time/frame for later
                IfResp1KeyResp.frameNStart = frameN  # exact frame index
                IfResp1KeyResp.tStart = t  # local t and not account for scr refresh
                IfResp1KeyResp.tStartRefresh = tThisFlipGlobal  # on global time
                win.timeOnFlip(IfResp1KeyResp, 'tStartRefresh')  # time at next scr refresh
                IfResp1KeyResp.status = STARTED
                # keyboard checking is just starting
                waitOnFlip = True
                win.callOnFlip(IfResp1KeyResp.clock.reset)  # t=0 on next screen flip
                win.callOnFlip(IfResp1KeyResp.clearEvents, eventType='keyboard')  # clear events on next screen flip
            if IfResp1KeyResp.status == STARTED and not waitOnFlip:
                theseKeys = IfResp1KeyResp.getKeys(keyList=['space'], waitRelease=False)
                _IfResp1KeyResp_allKeys.extend(theseKeys)
                if len(_IfResp1KeyResp_allKeys):
                    IfResp1KeyResp.keys = _IfResp1KeyResp_allKeys[-1].name  # just the last key pressed
                    IfResp1KeyResp.rt = _IfResp1KeyResp_allKeys[-1].rt
                    # a response ends the routine
                    continueRoutine = False
            # `continueRoutine` seems to only work on frame checking
            
            # If they didn't hit something too early
            if VLKeyResp02.keys not in ['a', 'l']:
                # We don't display this routine
                continueRoutine = False
            
            # check for quit (typically the Esc key)
            if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
                core.quit()
            
            # check if all components have finished
            if not continueRoutine:  # a component has requested a forced-end of Routine
                break
            continueRoutine = False  # will revert to True if at least one component still running
            for thisComponent in IfResp1Components:
                if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                    continueRoutine = True
                    break  # at least one component has not yet finished
            
            # refresh the screen
            if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
                win.flip()
        
        # -------Ending Routine "IfResp1"-------
        for thisComponent in IfResp1Components:
            if hasattr(thisComponent, "setAutoDraw"):
                thisComponent.setAutoDraw(False)
        Resp1Loop.addData('IfResp1Text.started', IfResp1Text.tStartRefresh)
        Resp1Loop.addData('IfResp1Text.stopped', IfResp1Text.tStopRefresh)
        # the Routine "IfResp1" was not non-slip safe, so reset the non-slip timer
        routineTimer.reset()
        thisExp.nextEntry()
        
    # completed 5 repeats of 'Resp1Loop'
    
    
    # ------Prepare to start Routine "IfResp2"-------
Monica Connelly's avatar
Monica Connelly committed
1078 1079
    continueRoutine = True
    # update component parameters for each repeat
Monica Connelly's avatar
Monica Connelly committed
1080 1081 1082
    IfResp2KeyResp.keys = []
    IfResp2KeyResp.rt = []
    _IfResp2KeyResp_allKeys = []
Monica Connelly's avatar
Monica Connelly committed
1083
    # keep track of which components have finished
Monica Connelly's avatar
Monica Connelly committed
1084 1085
    IfResp2Components = [IfResp2Text, IfResp2KeyResp]
    for thisComponent in IfResp2Components:
Monica Connelly's avatar
Monica Connelly committed
1086 1087 1088 1089 1090 1091 1092 1093 1094
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
Monica Connelly's avatar
Monica Connelly committed
1095
    IfResp2Clock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
Monica Connelly's avatar
Monica Connelly committed
1096 1097
    frameN = -1
    
Monica Connelly's avatar
Monica Connelly committed
1098
    # -------Run Routine "IfResp2"-------
Monica Connelly's avatar
Monica Connelly committed
1099 1100
    while continueRoutine:
        # get current time
Monica Connelly's avatar
Monica Connelly committed
1101 1102
        t = IfResp2Clock.getTime()
        tThisFlip = win.getFutureFlipTime(clock=IfResp2Clock)
Monica Connelly's avatar
Monica Connelly committed
1103 1104 1105
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
Monica Connelly's avatar
Monica Connelly committed
1106
        # `continueRoutine` seems to only work on frame checking
Monica Connelly's avatar
Monica Connelly committed
1107
        
Monica Connelly's avatar
Monica Connelly committed
1108 1109 1110 1111
        # If they didn't hit something too early
        if VLKeyResp24.keys not in ['a', 'l']:
            # We don't display this routine
            continueRoutine = False
Monica Connelly's avatar
Monica Connelly committed
1112
        
Monica Connelly's avatar
Monica Connelly committed
1113 1114
        # *IfResp2Text* updates
        if IfResp2Text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
Monica Connelly's avatar
Monica Connelly committed
1115
            # keep track of start time/frame for later
Monica Connelly's avatar
Monica Connelly committed
1116 1117 1118 1119 1120
            IfResp2Text.frameNStart = frameN  # exact frame index
            IfResp2Text.tStart = t  # local t and not account for scr refresh
            IfResp2Text.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(IfResp2Text, 'tStartRefresh')  # time at next scr refresh
            IfResp2Text.setAutoDraw(True)
Monica Connelly's avatar
Monica Connelly committed
1121
        
Monica Connelly's avatar
Monica Connelly committed
1122
        # *IfResp2KeyResp* updates
Monica Connelly's avatar
Monica Connelly committed
1123
        waitOnFlip = False
Monica Connelly's avatar
Monica Connelly committed
1124
        if IfResp2KeyResp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
Monica Connelly's avatar
Monica Connelly committed
1125
            # keep track of start time/frame for later
Monica Connelly's avatar
Monica Connelly committed
1126 1127 1128 1129 1130
            IfResp2KeyResp.frameNStart = frameN  # exact frame index
            IfResp2KeyResp.tStart = t  # local t and not account for scr refresh
            IfResp2KeyResp.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(IfResp2KeyResp, 'tStartRefresh')  # time at next scr refresh
            IfResp2KeyResp.status = STARTED
Monica Connelly's avatar
Monica Connelly committed
1131 1132
            # keyboard checking is just starting
            waitOnFlip = True
Monica Connelly's avatar
Monica Connelly committed
1133 1134 1135 1136 1137 1138 1139 1140
            win.callOnFlip(IfResp2KeyResp.clock.reset)  # t=0 on next screen flip
            win.callOnFlip(IfResp2KeyResp.clearEvents, eventType='keyboard')  # clear events on next screen flip
        if IfResp2KeyResp.status == STARTED and not waitOnFlip:
            theseKeys = IfResp2KeyResp.getKeys(keyList=['space'], waitRelease=False)
            _IfResp2KeyResp_allKeys.extend(theseKeys)
            if len(_IfResp2KeyResp_allKeys):
                IfResp2KeyResp.keys = _IfResp2KeyResp_allKeys[-1].name  # just the last key pressed
                IfResp2KeyResp.rt = _IfResp2KeyResp_allKeys[-1].rt
Monica Connelly's avatar
Monica Connelly committed
1141 1142 1143
                # a response ends the routine
                continueRoutine = False
        
Monica Connelly's avatar
Monica Connelly committed
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
        # check for quit (typically the Esc key)
        if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
            core.quit()
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            break
        continueRoutine = False  # will revert to True if at least one component still running
        for thisComponent in IfResp2Components:
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
    # -------Ending Routine "IfResp2"-------
    for thisComponent in IfResp2Components:
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
    trialsloop.addData('IfResp2Text.started', IfResp2Text.tStartRefresh)
    trialsloop.addData('IfResp2Text.stopped', IfResp2Text.tStopRefresh)
    # the Routine "IfResp2" was not non-slip safe, so reset the non-slip timer
    routineTimer.reset()
    
    # ------Prepare to start Routine "IfResp3"-------
    continueRoutine = True
    # update component parameters for each repeat
    IfResp3KeyResp.keys = []
    IfResp3KeyResp.rt = []
    _IfResp3KeyResp_allKeys = []
    # keep track of which components have finished
    IfResp3Components = [IfResp3Text, IfResp3KeyResp]
    for thisComponent in IfResp3Components:
        thisComponent.tStart = None
        thisComponent.tStop = None
        thisComponent.tStartRefresh = None
        thisComponent.tStopRefresh = None
        if hasattr(thisComponent, 'status'):
            thisComponent.status = NOT_STARTED
    # reset timers
    t = 0
    _timeToFirstFrame = win.getFutureFlipTime(clock="now")
    IfResp3Clock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
    frameN = -1
    
    # -------Run Routine "IfResp3"-------
    while continueRoutine:
        # get current time
        t = IfResp3Clock.getTime()
        tThisFlip = win.getFutureFlipTime(clock=IfResp3Clock)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
        frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
        # update/draw components on each frame
        # `continueRoutine` seems to only work on frame checking
        
        # If they didn't hit something too early
        if VLKeyResp46.keys not in ['a', 'l']:
            # We don't display this routine
            continueRoutine = False
        
        # *IfResp3Text* updates
        if IfResp3Text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
            # keep track of start time/frame for later
            IfResp3Text.frameNStart = frameN  # exact frame index
            IfResp3Text.tStart = t  # local t and not account for scr refresh
            IfResp3Text.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(IfResp3Text, 'tStartRefresh')  # time at next scr refresh
            IfResp3Text.setAutoDraw(True)
        
        # *IfResp3KeyResp* updates
        waitOnFlip = False
        if IfResp3KeyResp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
Monica Connelly's avatar
Monica Connelly committed
1218
            # keep track of start time/frame for later
Monica Connelly's avatar
Monica Connelly committed
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
            IfResp3KeyResp.frameNStart = frameN  # exact frame index
            IfResp3KeyResp.tStart = t  # local t and not account for scr refresh
            IfResp3KeyResp.tStartRefresh = tThisFlipGlobal  # on global time
            win.timeOnFlip(IfResp3KeyResp, 'tStartRefresh')  # time at next scr refresh
            IfResp3KeyResp.status = STARTED
            # keyboard checking is just starting
            waitOnFlip = True
            win.callOnFlip(IfResp3KeyResp.clock.reset)  # t=0 on next screen flip
            win.callOnFlip(IfResp3KeyResp.clearEvents, eventType='keyboard')  # clear events on next screen flip
        if IfResp3KeyResp.status == STARTED and not waitOnFlip:
            theseKeys = IfResp3KeyResp.getKeys(keyList=['space'], waitRelease=False)
            _IfResp3KeyResp_allKeys.extend(theseKeys)
            if len(_IfResp3KeyResp_allKeys):
                IfResp3KeyResp.keys = _IfResp3KeyResp_allKeys[-1].name  # just the last key pressed
                IfResp3KeyResp.rt = _IfResp3KeyResp_allKeys[-1].rt
                # a response ends the routine
                continueRoutine = False
Monica Connelly's avatar
Monica Connelly committed
1236 1237 1238 1239 1240 1241 1242 1243 1244
        
        # check for quit (typically the Esc key)
        if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
            core.quit()
        
        # check if all components have finished
        if not continueRoutine:  # a component has requested a forced-end of Routine
            break
        continueRoutine = False  # will revert to True if at least one component still running
Monica Connelly's avatar
Monica Connelly committed
1245
        for thisComponent in IfResp3Components:
Monica Connelly's avatar
Monica Connelly committed
1246 1247 1248 1249 1250 1251 1252 1253
            if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break  # at least one component has not yet finished
        
        # refresh the screen
        if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
            win.flip()
    
Monica Connelly's avatar
Monica Connelly committed
1254 1255
    # -------Ending Routine "IfResp3"-------
    for thisComponent in IfResp3Components:
Monica Connelly's avatar
Monica Connelly committed
1256 1257
        if hasattr(thisComponent, "setAutoDraw"):
            thisComponent.setAutoDraw(False)
Monica Connelly's avatar
Monica Connelly committed
1258 1259 1260
    trialsloop.addData('IfResp3Text.started', IfResp3Text.tStartRefresh)
    trialsloop.addData('IfResp3Text.stopped', IfResp3Text.tStopRefresh)
    # the Routine "IfResp3" was not non-slip safe, so reset the non-slip timer
Monica Connelly's avatar
Monica Connelly committed
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
    routineTimer.reset()
    thisExp.nextEntry()
    
# completed 1 repeats of 'trialsloop'


# ------Prepare to start Routine "Finish"-------
continueRoutine = True
# update component parameters for each repeat
# keep track of which components have finished
FinishComponents = [FinishText]
for thisComponent in FinishComponents:
    thisComponent.tStart = None
    thisComponent.tStop = None
    thisComponent.tStartRefresh = None
    thisComponent.tStopRefresh = None
    if hasattr(thisComponent, 'status'):
        thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
FinishClock.reset(-_timeToFirstFrame)  # t0 is time of first possible flip
frameN = -1

# -------Run Routine "Finish"-------
while continueRoutine:
    # get current time
    t = FinishClock.getTime()
    tThisFlip = win.getFutureFlipTime(clock=FinishClock)
    tThisFlipGlobal = win.getFutureFlipTime(clock=None)
    frameN = frameN + 1  # number of completed frames (so 0 is the first frame)
    # update/draw components on each frame
    
    # *FinishText* updates
    if FinishText.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
        # keep track of start time/frame for later
        FinishText.frameNStart = frameN  # exact frame index
        FinishText.tStart = t  # local t and not account for scr refresh
        FinishText.tStartRefresh = tThisFlipGlobal  # on global time
        win.timeOnFlip(FinishText, 'tStartRefresh')  # time at next scr refresh
        FinishText.setAutoDraw(True)
    
    # check for quit (typically the Esc key)
    if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
        core.quit()
    
    # check if all components have finished
    if not continueRoutine:  # a component has requested a forced-end of Routine
        break
    continueRoutine = False  # will revert to True if at least one component still running
    for thisComponent in FinishComponents:
        if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
            continueRoutine = True
            break  # at least one component has not yet finished
    
    # refresh the screen
    if continueRoutine:  # don't flip if this routine is over or we'll get a blank screen
        win.flip()

# -------Ending Routine "Finish"-------
for thisComponent in FinishComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
thisExp.addData('FinishText.started', FinishText.tStartRefresh)
thisExp.addData('FinishText.stopped', FinishText.tStopRefresh)
# the Routine "Finish" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# Flip one final time so any remaining win.callOnFlip() 
# and win.timeOnFlip() tasks get executed before quitting
win.flip()

# these shouldn't be strictly necessary (should auto-save)
thisExp.saveAsWideText(filename+'.csv')
thisExp.saveAsPickle(filename)
logging.flush()
# make sure everything is closed down
thisExp.abort()  # or data files will save again on exit
win.close()
core.quit()