Skip to content

Commit

Permalink
Merge pull request #3 from mh105/main-pep8-style-update
Browse files Browse the repository at this point in the history
STY: PEP8 style updates
  • Loading branch information
TEParsons authored Jun 6, 2024
2 parents f88a63d + 3d753a3 commit 713a3f0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 48 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# OS generated files #
######################
.directory
.gdb_history
.DS_Store
ehthumbs.db
Icon?
*.orig
old
Thumbs.db
nonSVN
.hg*
*.log

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion psychopy_eyetracker_sr_research/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
devices by SR Research (via ioHub).
"""

__version__ = "0.0.2"
__version__ = "0.0.2"
2 changes: 1 addition & 1 deletion psychopy_eyetracker_sr_research/sr_research/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# Part of the PsychoPy library
# Copyright (C) 2012-2020 iSolver Software Solutions (C) 2021 Open Science Tools Ltd.
# Distributed under the terms of the GNU General Public License (GPL).
# Distributed under the terms of the GNU General Public License (GPL).
10 changes: 5 additions & 5 deletions psychopy_eyetracker_sr_research/sr_research/eyelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
]

from .eyetracker import (
EyeTracker,
EyeTracker,
MonocularEyeSampleEvent,
BinocularEyeSampleEvent,
BinocularEyeSampleEvent,
FixationStartEvent,
FixationEndEvent,
FixationEndEvent,
SaccadeStartEvent,
SaccadeEndEvent,
SaccadeEndEvent,
BlinkStartEvent,
BlinkEndEvent)
BlinkEndEvent)
94 changes: 53 additions & 41 deletions psychopy_eyetracker_sr_research/sr_research/eyelink/eyetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gevent
import threading
import pylink
import numpy as np

try:
from psychopy.gui.wxgui import ProgressBarDialog
Expand All @@ -16,72 +17,78 @@
from psychopy.iohub import EXP_SCRIPT_DIRECTORY
from psychopy.iohub.errors import print2err, printExceptionDetailsToStdErr
from psychopy.iohub.devices import Computer, Device
from psychopy.iohub.devices.eyetracker.eye_events import *
from psychopy.iohub.devices.eyetracker.eye_events import (
EventConstants,
EyeTrackerDevice
)

try:
pylink.enableUTF8EyeLinkMessages()
except Exception:
pass


def start_eyelink(eyelink):
eyelink.startRecording(1, 1, 1, 1)
gevent.sleep(0.01)
if not eyelink.waitForBlockStart(100, 1, 0):
print2err('EYETRACKER_START_RECORD_EXCEPTION ')


def stop_eyelink(eyelink):
eyelink.stopRecording()


class EyeTracker(EyeTrackerDevice):
"""
The SR Research EyeLink implementation of the Common Eye Tracker Interface
can be used by providing the following EyeTracker path as the device
class in the iohub_config.yaml device settings file:
eyetracker.hw.sr_research.eyelink
Examples:
A. Start ioHub with SR Research EyeLink 1000 and run tracker calibration::
from psychopy.iohub import launchHubServer
from psychopy.core import getTime, wait
iohub_config = {'eyetracker.hw.sr_research.eyelink.EyeTracker':
{'name': 'tracker',
'model_name': 'EYELINK 1000 DESKTOP',
'runtime_settings': {'sampling_rate': 500,
'runtime_settings': {'sampling_rate': 500,
'track_eyes': 'RIGHT'}
}
}
io = launchHubServer(**iohub_config)
# Get the eye tracker device.
tracker = io.devices.tracker
# run eyetracker calibration
r = tracker.runSetupProcedure()
B. Print all eye tracker events received for 2 seconds::
# Check for and print any eye tracker events received...
tracker.setRecordingState(True)
stime = getTime()
while getTime()-stime < 2.0:
for e in tracker.getEvents():
print(e)
C. Print current eye position for 5 seconds::
# Check for and print current eye position every 100 msec.
stime = getTime()
while getTime()-stime < 5.0:
print(tracker.getPosition())
wait(0.1)
tracker.setRecordingState(False)
# Stop the ioHub Server
io.quit()
"""
Expand Down Expand Up @@ -175,7 +182,7 @@ def __init__(self, *args, **kwargs):
# If edf file name has been set to EXPFILE, use the datastore file name as the local
# edf file name, getting around the 8 char host name limit.
EyeTracker._local_edf_dir = os.path.join(EyeTracker._local_edf_dir, "data")
if self._iohub_server.dsfile:
if self._iohub_server.dsfile:
local_file_name = self._iohub_server.dsfile.fileName[:-5]
EyeTracker._full_edf_name = local_file_name
EyeTracker._host_edf_name = default_native_data_file_name
Expand All @@ -188,7 +195,8 @@ def __init__(self, *args, **kwargs):
if len(default_native_data_file_name) > 7:
EyeTracker._full_edf_name = default_native_data_file_name
twoDigitRand = np.random.randint(10, 99)
EyeTracker._host_edf_name = self._full_edf_name[:3] + str(twoDigitRand) + self._full_edf_name[5:7]
EyeTracker._host_edf_name = self._full_edf_name[:3] +\
str(twoDigitRand) + self._full_edf_name[5:7]
else:
EyeTracker._full_edf_name = default_native_data_file_name
EyeTracker._host_edf_name = default_native_data_file_name
Expand Down Expand Up @@ -271,7 +279,7 @@ def setConnectionState(self, enable):
return EyeTrackerConstants.EYETRACKER_OK
else:
print2err('INVALID_METHOD_ARGUMENT_VALUE')
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def isConnected(self):
Expand All @@ -291,7 +299,7 @@ def isConnected(self):
"""
try:
return self._eyelink.isConnected() != 0
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def sendCommand(self, key, value=None):
Expand Down Expand Up @@ -326,7 +334,7 @@ def sendCommand(self, key, value=None):
r = self._readResultFromTracker(cmdstr)
print2err('[%s] result: %s' % (cmdstr, r))
return EyeTrackerConstants.EYETRACKER_OK
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def sendMessage(self, message_contents, time_offset=None):
Expand All @@ -350,7 +358,7 @@ def sendMessage(self, message_contents, time_offset=None):
if r == 0:
return EyeTrackerConstants.EYETRACKER_OK
return EyeTrackerConstants.EYETRACKER_ERROR
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()
return EyeTrackerConstants.EYETRACKER_ERROR

Expand Down Expand Up @@ -386,8 +394,11 @@ def runSetupProcedure(self, calibration_args={}):
* C = Start Calibration
* V = Start Validation
* ENTER should be pressed at the end of a calibration or validation to accept the calibration, or in the case of validation, use the option drift correction that can be performed as part of the validation process in the EyeLink system.
* ESC can be pressed at any time to exit the current state of the setup procedure and return to the initial blank screen state.
* ENTER should be pressed at the end of a calibration or validation to accept the calibration,
or in the case of validation, use the option drift correction that can be performed as part of
the validation process in the EyeLink system.
* ESC can be pressed at any time to exit the current state of the setup procedure and return to
the initial blank screen state.
* O = Exit the runSetupProcedure method and continue with the experiment.
"""
try:
Expand Down Expand Up @@ -439,7 +450,7 @@ def runSetupProcedure(self, calibration_args={}):

return reply

except Exception as e:
except Exception:
printExceptionDetailsToStdErr()
return EyeTrackerConstants.EYETRACKER_ERROR

Expand All @@ -455,7 +466,7 @@ def isRecordingEnabled(self):
"""
try:
return self._eyelink.isRecording() == 0
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def enableEventReporting(self, enabled=True):
Expand All @@ -464,7 +475,7 @@ def enableEventReporting(self, enabled=True):
try:
enabled = EyeTrackerDevice.enableEventReporting(self, enabled)
return self.setRecordingState(enabled)
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def setRecordingState(self, recording):
Expand All @@ -491,7 +502,7 @@ def setRecordingState(self, recording):
while starter_thread.is_alive() or Computer.getTime()-stime < 0.5:
gevent.sleep(0.001)
starter_thread.join()
#print2err('start: ', Computer.getTime()-stime)
# print2err('start: ', Computer.getTime()-stime)
if Computer.platform == 'win32' and EyeTracker._keyboard:
EyeTracker._keyboard._syncPressedKeyState()
EyeTrackerDevice.enableEventReporting(self, True)
Expand All @@ -504,15 +515,15 @@ def setRecordingState(self, recording):
while stopper_thread.is_alive() or Computer.getTime()-stime < 0.5:
gevent.sleep(0.001)
stopper_thread.join()
#print2err('stop: ', Computer.getTime() - stime)
# print2err('stop: ', Computer.getTime() - stime)
if Computer.platform == 'win32' and EyeTracker._keyboard:
EyeTracker._keyboard._syncPressedKeyState()
EyeTrackerDevice.enableEventReporting(self, False)

self._latest_sample = None
self._latest_gaze_position = None
return self.isRecordingEnabled()
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def getLastSample(self):
Expand All @@ -533,7 +544,7 @@ def getLastSample(self):
"""
try:
return self._latest_sample
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def getLastGazePosition(self):
Expand Down Expand Up @@ -562,7 +573,7 @@ def getLastGazePosition(self):
"""
try:
return self._latest_gaze_position
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def _poll(self):
Expand Down Expand Up @@ -1131,7 +1142,7 @@ def _eyeTrackerToDisplayCoords(self, eyetracker_point):

gxn, gyn = eyetracker_point[0] / dw, eyetracker_point[1] / dh
return cl + cw * gxn, cb + ch * (1.0 - gyn)
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def _displayToEyeTrackerCoords(self, display_x, display_y):
Expand All @@ -1147,7 +1158,7 @@ def _displayToEyeTrackerCoords(self, display_x, display_y):
(display_y - ch / 2) / ch
return cxn * dw, cyn * dh

except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

def _setRuntimeSettings(self, runtimeSettings):
Expand Down Expand Up @@ -1384,7 +1395,8 @@ def _eyelinkSetScreenPhysicalData(self):
(hsw, hsh, hsw, hsh))
else:
print2err(
'ERROR: "physical_stimudisplay_x,display_ylus_area":"width" or "height" value could not be read from monitor settings')
'ERROR: "physical_stimudisplay_x,display_ylus_area":"width" or "height" value '
'could not be read from monitor settings')
return False

# calibration coord space
Expand Down Expand Up @@ -1592,7 +1604,7 @@ def _getTrackerMode(*args, **kwargs):
try:
r = pylink.getEYELINK().getTrackerMode()
return _EYELINK_HOST_MODES[r]
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1605,7 +1617,7 @@ def _doDriftCorrect(*args, **kwargs):
else:
print2err('doDriftCorrect requires 4 parameters, received: ', args)
return False
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1616,7 +1628,7 @@ def _applyDriftCorrect():
return True
else:
return ['EYE_TRACKER_ERROR', 'applyDriftCorrect', r]
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1631,15 +1643,15 @@ def _eyeAvailable(*args, **kwargs):
return EyeTrackerConstants.getName(EyeTrackerConstants.BINOCULAR)
else:
return EyeTrackerConstants.UNDEFINED
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


def _dummyOpen(*args, **kwargs):
try:
r = pylink.getEYELINK().dummy_open()
return r
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1652,7 +1664,7 @@ def _getCalibrationMessage(*args, **kwargs):
else:
r = 'NO_REPLY'
return dict(message=m, result=r)
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1667,7 +1679,7 @@ def _setIPAddress(*args, **kwargs):
'EYE_TRACKER_ERROR',
'setIPAddress',
'Could not Parse IP String']
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1679,7 +1691,7 @@ def _setLockEye(*args, **kwargs):
return r
return ['EYE_TRACKER_ERROR', 'setLockEye',
'One argument is required, bool type.']
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()


Expand All @@ -1689,5 +1701,5 @@ def _setNativeRecordingFileSaveDir(*args):
edfpath = args[0]
print2err('Setting File Save path: ', edfpath)
EyeTracker._local_edf_dir = edfpath
except Exception as e:
except Exception:
printExceptionDetailsToStdErr()

0 comments on commit 713a3f0

Please sign in to comment.