Python is case sensitive. The core module has a psychopy.core.Clock class with a capital C.
To use this class, you would first create an object of that class in the Begin Experiment tab:
myCustomTimer = core.Clock()
listToStoreTimeSpentInQuad = []
In Begin Routine, you create a boolean variable to track whether the mouse is in your stimulus:
endTimeInQuad = None
startTimeInQuad = None
mouseIsInQuad = False
myCustomTimer.reset()
Then you can use the code you used with your custom timer:
if CorrectQuad.contains(mouse) and not mouseIsInQuad: # the mouse was just moved inside the quad
startTimeInQuad = myCustomTimer.getTime()
mouseIsInQuad = True
elif not CorrectQuad.contains(mouse) and mouseIsInQuad: # the mouse was just moved outside the quad
endTimeInQuad = myCustomTimer.getTime()
mouseIsInQuad = False
In the end Routine tab, you can then store the values. I don’t know how you end your routine.
To handle cases, in which the mouse stays in the Quad
stimulus and the routine is ended without the mouse moving outside of it, I added the if (startTimeInQuad is not None) and (endTimeInQuad is None)
condition.
if (startTimeInQuad is not None) and (endTimeInQuad is None):
endTimeInQuad = myCustomTimer.getTime()
thisExp.addData('startTimeInQuad', startTimeInQuad)
thisExp.addData('endTimeInQuad', endTimeInQuad)
if (startTimeInQuad is not None) and (endTimeInQuad is not None):
thisTimeSpendInQuad = endTimeInQuad - startTimeInQuad
else:
thisTimeSpendInQuad = 0
listToStoreTimeSpentInQuad.append(thisTimeSpendInQuad)
If at some point in your experiment, you want to retrieve the mean time spent in the Quad
stimulus, you can use meanTimeSpentInQuad = mean(listToStoreTimeSpentInQuad)
.
P.S. You don’t need to import the psychopy.core
module. The PsychoPy builder does that for you. You can check this if you compile the Python script and check the first few lines with import statements.
I haven’t checked this code, so it still may not be the optimal solution and it may raise errors, which you’ll have to debug. 