PyGaze Framework¶
Code documentation¶
EventHandler¶
-
class
msrresearch_helpers.pygaze_framework.
EventHandler
(keylist=[], time=500, name='EventHandler')¶ Bases:
threading.Thread
This class shall be used to detect button press and AOI/fixation events etc.
Parameters: -
class
BlinkDetector
(tracker, name='BlinkDetector')¶ Bases:
threading.Thread
A class to detect blinks
Parameters: tracker (pygaze_framework.OurTracker object) – Eyetracker to detect blinks
-
class
EventHandler.
Fixation_Detector
(aoi_pos, aoi_size, aoi_event, tracker, aoi_tol=0, aoi_type='rectangle', name='GazeEvent')¶ Bases:
threading.Thread
An object to detect fixations on a given AOI.
Parameters: - aoi_pos –
- aoi_size –
- aoi_event –
-
class
EventHandler.
JADetector
(tracker, name='JADetector')¶ Bases:
threading.Thread
A class to detect joint attention by agent and participant
Parameters: tracker (pygaze_framework.OurTracker object) – Eyetracker to detect blinks
-
class
EventHandler.
MyEvent
¶ An extension of
threading.Event
with the possibility to pass information from the thread setting the event to all threads waiting for the event to be raised.See also
-
clear
()¶ Resets the inner flag to
False
-
is_set
()¶ Returns
True
if and only if the inner flag of the Event object is True.
-
set
(msg=None)¶ Sets the internal flag to
True
and lets the threads waiting resume.Parameters: msg (object) – Anything, which should be given to all waiting threads
-
-
EventHandler.
create_aoi_from_coordinates
(name, position, size, aoi_tolerance=0, aoi_type='rectangle')¶ Method to create AOI and Fixation_Detector from given coordinates
Parameters:
-
EventHandler.
create_aoi_from_image
(name, image, aoi_tolerance=0.0, aoitype='rectangle')¶ Method to create AOI and Fixation_Detector on image
Parameters: - name (str) – Name of AOI
- image – Image to which AOI is created
-
EventHandler.
create_events
(keylist)¶ Create events for buttons presses
Parameters: keylist –
-
EventHandler.
start_fixation_detectors
()¶ Method to start all fixations detectors for all AOIs
-
EventHandler.
wait_for_either_key
(keylist)¶ A function to wait for one of a given list of keys to be pressed.
Todo
wait_for_either_key()
rewrite this function to work withMyEvent
-
class
ScreenHandler¶
-
class
msrresearch_helpers.pygaze_framework.
ScreenHandler
(event_handler=None, agent_dir=None, agent_size=None, agent_pos=None, agent_dict=None, tar_dir=None, tar_size=None, tar_dict=None, resize_proportional=True)¶ This class should be used to handle all screen related issues.
Parameters: - event_handler (A pygaze_framework EventHandler object) – Event handler
- agent_dir (use os.path.join method) – directory where all images of agent are located
- agent_size (list) – Size of agent in pixels
- agent_pos (tuple) – Postion of agent on screen
- agent_dict (dict) – A dictionary containing translation from names used in this framework and the filenames of the images of the agent
- tar_dir (use os.path.join method) – directory containing all objects which will be presented on the screen
- tar_size (tuple) – Size of targets in pixels
- tar_dict (dict) – dictionary containing translation between internal use and file names
- resize_proportional (boolian) – KP
-
class
Image
(file_name, position=(0, 0), size=None, scale_factor=1)¶ A class to store images.
In order to make a interaction with images as easy as possible, this class the possibility to store all necessary information of an image to have easy access to them. This is especially intended to be used with the four images relevant functions of Screen_Handler.
Parameters: - file_name – The filename of the image
- position (tuple, list) – A tuple or a list of the x and y coordinate of the image.
- size (tuple, list) – The size of the image. If None, the original size of the image will be used.
- scale_factor (float) – The factor to rescale the imige
-
get_ulc_pos
()¶ Returns the position of the upper left corner.
Returns: position of the upper left corner
-
move
(new_position)¶ Move the image to a new location on the screen.
Parameters: new_position (list, tuble) – the new absolute position on the screen. Todo
move()
Implement relative movement.
-
resize
(new_size, proportional=True)¶ A function to resize or rescale the image.
Whether to resize or rescale the image is defined by the type of new_size: If it is list or tuple, the image will be resized, if it is float or int, it will be rescaled.
Parameters: - new_size (list, tuple, int, float) – The target size or scaling factor.
- proportional (bool) – Whether the aspect ratio of the image should be kept while resizing. If True, the image will be scaled to fit completely within the rectangle drawn by new_size. Irrelevant for rescaling.
-
ScreenHandler.
draw_agent_on_target_screen
(agent, tracker=None)¶ Function to draw current agent on screen
Parameters: - agent (str) – Name of agent to be drawn
- tracker (
OurTracker
) – The eyetracker used in the experiment
-
ScreenHandler.
draw_image
(screen, name, position=None, new_size=None, resize_proportional=None, draw_all=False)¶ Add image to the screen to be shown with
show()
.Parameters: - screen (
pygaze.libscreen.Screen
) – the screen, the image should be drawn on - name (str) – name of image
- position (list, tuple) – position where the image should be drawn. If None, the image will be drawn the in the image stored position
- new_size (list, tuple, int, float) – new size to resize the image. If None, the image will not be resized
- draw_all (bool) – add the image to the separat screen for images which should be drawn with every redraw of the screen.
Todo
draw_image()
If I understand the code correctly, there is at the moment no way to combine a draw_all=False and draw_all=False call of this function. This should be investigated in if it’s true fixed.- screen (
-
ScreenHandler.
draw_text
(text, screen, color=None, position=None, fontsize=12, font='mono')¶ Draw text on the screen.
Parameters: - text (str) – the text to be drawn
- color (str, list, tuple) – the color of the text to be drawn. By default this is the foreground color.
- position (list, tuple) – the position of the to be drawn text. By default it will be drawn in the center of the screen.
- fontsize (int) – font size of the text. By default 12.
- font (str) – font in which the text should be drawn.
Todo
draw_text()
This needs to be updatet to the new way of drawing stuff.
-
ScreenHandler.
give_stim_tacker_signal
(screen)¶ Method that will create a little black square for stim tracking using a Tobii stim_tracker_square, if also a white sqare is used, bugs in blinking appear...
-
ScreenHandler.
make_all_screens
(objectpicker, tar_dict, neutral_agent, agent_aoi_pos)¶ Method to create all possible screens that could be shown in a single block of an experiment
Parameters:
-
ScreenHandler.
register_draw_always
(image)¶ Register images, to be drawn always. OBSOLETE?
The image will be added to separat Screen object to be drawn every time the screen is redrawn.
Parameters: image (str) – name of the previously stored image.
-
ScreenHandler.
show
(screen, color='green', tracker=None)¶ Show the screen, to which the images and texts are added by :py:func`darw_image` and
draw_text()
. This needs to be done in order to get the screen to the display.Parameters: - screen (psychopy screen) – psychopy screen to be shown
- show_gaze_pos (boolian) – If Set to True a fixation cross will be shown a current gaze position
- color – Color of fixation cross
-
ScreenHandler.
show_updated_avatar
(clear=False, draw_all=False, tracker=None)¶ A new
show()
function, which I need to fully understand to write a documentation.Parameters: - clear (bool) – clear the screen after moving it to the display. By default True.
- draw_all (bool) – draw the screen with all the objects to be drawn always. By default False.
- tracker (OurTracker) – An
OurTracker
object. If given the current gaze position will be drawn. By default None.
-
ScreenHandler.
store_image
(name, file_name, position=(0, 0), size=None, scale_factor=1)¶ Store images, which should be drawn later on.
In order to make the redrawing of images as easy as possible, images aren’t drawn directly to the screen, but instead are stored in a dictionary as
Image
objects.Parameters: - name (str) – name of the image to be stored. With this name the image can also be retrieved.
- file_name (str) – directory and file name of the image.
- position (list, tuple) – Position, where the image should be drawn.
- size (list, tuple) – new size tor resize the image. If None is given, it will use the default size of the image
- scale (int, float) – scale to rescale the image. If none is given, it will not be rescaled
OurTracker¶
-
class
msrresearch_helpers.pygaze_framework.
OurTracker
(disp, log_name, date_str)¶ A class for binding the eyetracker into the paradigm
Automatically connects to the eyetracker and runs calibration mode :param disp: Display used for psychopy interaction :type disp: A psychopy display object :param log_name: Filename of logfile produced by pygaze.eyetracker.EyeTracker.start_recording() :type log_name: str :param date_str: Date string to rename log file :type date_str: str
Logger¶
Todo List¶
Todo
wait_for_either_key()
rewrite this function to work with MyEvent
(The original entry is located in D:\Git\documentation\msrresearch_helpers\pygaze_framework.py:docstring of msrresearch_helpers.pygaze_framework.EventHandler.wait_for_either_key, line 3.)
Todo
move()
Implement relative movement.
(The original entry is located in D:\Git\documentation\msrresearch_helpers\pygaze_framework.py:docstring of msrresearch_helpers.pygaze_framework.ScreenHandler.Image.move, line 6.)
Todo
draw_image()
If I understand the code correctly, there is at the moment no way to combine a draw_all=False and draw_all=False call of this function. This should be investigated in if it’s true fixed.
(The original entry is located in D:\Git\documentation\msrresearch_helpers\pygaze_framework.py:docstring of msrresearch_helpers.pygaze_framework.ScreenHandler.draw_image, line 14.)
Todo
draw_text()
This needs to be updatet to the new way of drawing stuff.
(The original entry is located in D:\Git\documentation\msrresearch_helpers\pygaze_framework.py:docstring of msrresearch_helpers.pygaze_framework.ScreenHandler.draw_text, line 14.)