psychopy.org | Reference | Downloads | Github

event.Mouse.mouseMoved() failing

Not sure if this is a bug, or if anybody else has encountered this problem on newer versions of psychopy (i’m on v1.90.dev1)

i’m trying to detect a mouse movement, and if detected update the orientation of a line based on the angle of the cursor from centre (calculating the orientation is simple). In previous versions of psychopy this had worked fine, but for some reason when i initialise a mouse within script (mouse = event.Mouse(win=screen)) and then later check if the mouse has moved in order to continue with a response using :

if mouse.mouseMoved():
    dialup=True

it fails, giving this File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/event.py", line 594, in mouseMoved if self.prevPos[0] != self.lastPos[0]: TypeError: 'NoneType' object has no attribute '__getitem__'

Pretty weird error, is psychopy somehow failing to initialise the mouse as an object earlier on in the script, causing this?

any advice appreciated!

@srchekroud, the error is occurring because in the Mouse method, self.lastPos = None during instantiation of the mouse object, which is then copied to self.prevPos in the mouseMoved method (which then becomes a NoneType). After this, self.getPos redefines self.lastPos to an [x,y] list type. So, there appears to be an error in that mouseMoved will fail given those parameters.

To bypass this error you could reset the mouse coordinates:

while True:
    mouse.mouseMoved(reset=(0,0))
    if not mouse.mouseMoved():
        win.flip()
    if mouse.mouseMoved():
        dialup = True
        win.flip()