Skip to content

Commit

Permalink
working tagframe
Browse files Browse the repository at this point in the history
  • Loading branch information
domstoppable committed Sep 2, 2024
1 parent a2d802c commit af9c8c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion psychopy_eyetracker_pupil_labs/pupil_labs/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions psychopy_eyetracker_pupil_labs/pupil_labs/neon/eyetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
16 changes: 11 additions & 5 deletions psychopy_eyetracker_pupil_labs/pupil_labs/stimuli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af9c8c6

Please sign in to comment.