labcomputer, psychopy, joystick problem
using the labcomputer with a joystick in Psychopy
problem 1
if using the code as given at the psychopy website gives this error:
Traceback (most recent call last): File "E:\wilberth\joystick.py", line 15, infrom psychopy.hardware import joystick File "C:\Python27\lib\site-packages\psychopy\hardware\joystick\__init__.py", line 36, in import pyglet_input File "C:\Python27\lib\site-packages\psychopy\hardware\joystick\pyglet_input\__init__.py", line 163, in from directinput import get_devices, get_joysticks File "C:\Python27\lib\site-packages\psychopy\hardware\joystick\pyglet_input\directinput.py", line 6, in import app File "C:\Python27\lib\site-packages\psychopy\hardware\joystick\pyglet_input\app\__init__.py", line 150, in from win32 import Win32EventLoop as PlatformEventLoop File "C:\Python27\lib\site-packages\psychopy\hardware\joystick\pyglet_input\app\win32.py", line 44, in from pyglet.libs.win32 import _kernel32, _user32, types, constants ImportError: No module named libs.win32
Psychopy coder solution
- download the newest version of pyglet.zip from https://pypi.python.org/pypi/pyglet#downloads
- unzip it somewhere
- make a new directory C:\Python27\Lib\site-packages-local
- from the archive copy the subdirectories 'pyglet' and 'pyglet.egg-info' to C:\Python27\Lib\site-packages-local
- in your python code use for the initialization:
import sys sys.path.insert(0, "C:\\Python27\\Lib\\site-packages-local") # import psychopy libraries from psychopy.hardware import joystick joy = joystick.Joystick(0)
and where reading joystick input:joy.getX()
Psychopy builder solution (also works for coder)
in psychopy builder this solution is won't do, since you cannot insert code before importing psychopy libraries. There the solution is:
- download the newest version of pyglet.zip from https://pypi.python.org/pypi/pyglet#downloads
- unzip it somewhere
- from the archive copy the subdirectories 'pyglet' the location of your experiment file (.psyexp)
- in your python code use for the initialization:
from psychopy.hardware import joystick joy = joystick.Joystick(0)
and where reading joystick input:joy.getX()
Problem 2
If you get the error message:
Traceback (most recent call last): File "E:\joystick_universal.py", line 85, inwin.flip() # redraw the buffer File "C:\Python27\lib\site-packages\psychopy\visual\window.py", line 610, in flip dispatcher.dispatch_events() AttributeError: 'DirectInputDevice' object has no attribute 'dispatch_events'
as shown in https://groups.google.com/forum/#!topic/psychopy-users/CO37d-PMQ9k you can fix it by changing the file window.py line 610:
<- dispatcher.dispatch_events() -> dispatcher._dispatch_events()
Alternative, you you can alter your script:
# after joy = joystick.Joystick(0) has been called, assuming your window is called 'win': for d in win._eventDispatchers: d.dispatch_events = d._dispatch_events