From af9c8c60f61477be0095f4f011205ee62305d946 Mon Sep 17 00:00:00 2001 From: Dominic Canare Date: Mon, 2 Sep 2024 19:13:20 -0400 Subject: [PATCH] working tagframe --- .../pupil_labs/components.py | 2 +- .../pupil_labs/neon/eyetracker.py | 9 ++++++--- .../pupil_labs/stimuli.py | 16 +++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/psychopy_eyetracker_pupil_labs/pupil_labs/components.py b/psychopy_eyetracker_pupil_labs/pupil_labs/components.py index 0fe1f29..113e95e 100644 --- a/psychopy_eyetracker_pupil_labs/pupil_labs/components.py +++ b/psychopy_eyetracker_pupil_labs/pupil_labs/components.py @@ -93,7 +93,7 @@ def writeRoutineStartCode(self, buff): for component in tag_comps: inits = getInitVals(component.params, 'PsychoPy') - code += " str({inits[name]}.marker_id): {inits[name]}.get_marker_verts(),\n".format(inits=inits) + code += " str({inits[name]}.marker_id): {inits[name]}.marker_verts,\n".format(inits=inits) code += " }\n" code += " win_size_pix = convertToPix(np.array([2, 2]), [0, 0], 'norm', win)\n" diff --git a/psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py b/psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py index c35afb0..de42ee8 100644 --- a/psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py +++ b/psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py @@ -4,13 +4,12 @@ # Distributed under the terms of the GNU General Public License (GPL). import logging from typing import Optional, Dict, Tuple, Union -import json from psychopy.iohub.constants import EyeTrackerConstants from psychopy.iohub.devices import Computer, Device from psychopy.iohub.devices.eyetracker import EyeTrackerDevice from psychopy.iohub.errors import printExceptionDetailsToStdErr -from psychopy.iohub.constants import EventConstants, EyeTrackerConstants +from psychopy.iohub.constants import EventConstants from pupil_labs.realtime_api.simple import Device as CompanionDevice from pupil_labs.real_time_screen_gaze.gaze_mapper import GazeMapper @@ -191,7 +190,11 @@ def setRecordingState(self, should_be_recording: bool) -> bool: if should_be_recording: self._device.recording_start() else: - self._device.recording_stop_and_save() + try: + self._device.recording_stop_and_save() + except Exception as exc: + logging.error(f"Failed to stop recording: {exc}") + printExceptionDetailsToStdErr() self._actively_recording = should_be_recording diff --git a/psychopy_eyetracker_pupil_labs/pupil_labs/stimuli.py b/psychopy_eyetracker_pupil_labs/pupil_labs/stimuli.py index 304de80..b498e27 100644 --- a/psychopy_eyetracker_pupil_labs/pupil_labs/stimuli.py +++ b/psychopy_eyetracker_pupil_labs/pupil_labs/stimuli.py @@ -19,7 +19,8 @@ def __init__(self, marker_id=0, contrast=1.0, *args, **kwargs): super().__init__(image=marker_data, *args, **kwargs) - def get_marker_verts(self): + @property + def marker_verts(self): vertices_in_pixels = self._vertices.pix size_with_margin = ( abs(vertices_in_pixels[1][0] - vertices_in_pixels[0][0]), @@ -83,11 +84,16 @@ def __init__(self, h_count=3, v_count=3, marker_ids=None, marker_size=0.125, mar top_left = [v + marker_padding for v in top_left] bottom_right = [v - marker_padding for v in bottom_right] - self.marker_verts[marker_id] = ( - top_left, - (bottom_right[0], top_left[1]), - bottom_right, + top_left[0] -= win_size_pix[0] / 2 + top_left[1] -= win_size_pix[1] / 2 + bottom_right[0] -= win_size_pix[0] / 2 + bottom_right[1] -= win_size_pix[1] / 2 + + self.marker_verts[str(marker_id)] = ( (top_left[0], bottom_right[1]), + bottom_right, + (bottom_right[0], top_left[1]), + top_left, ) # Convert to psychopy color space