StimulusContainer class¶
Maintain several stimuli, and can present them all with a single command. You can also define some of the stimuli as temporarily invisible by setting their “visible” property.
Using this class¶
- Create the container
- Add visual objects to the container using
add()
- Once an object is added to the container, it will have a “visible” property, which you can set at any time.
- Present the container using
present()
. All objects with visible=True will be presented. - Objects added to the container later will appear on top of earlier-added objects.
- You can access objects from the container by writing container[obj_id], where obj_id is the ID
you provided to
add()
. - You can also tell the StimulusContainer to call a function when
present()
is called - to do this, useregister_callback()
Methods and properties:¶
-
class
trajtracker.stimuli.
StimulusContainer
(name=None)¶ -
__init__
(name=None)¶ Constructor
Parameters: name – A name that identifies this container (this is used only to print in log messages)
-
add
(stimulus, stimulus_id=None, visible=True)¶ Add a stimulus to the container.
Parameters: - stimulus – An Expyriment stimulus, or any other object that has a similar present() method
- stimulus_id – Stimulus name. Use it later to set the stimulus as visible/invisible. If not provided or None, an arbitrary ID will be generated.
- visible – See The stimulus ID (as defined in
set_visible()
)
Returns:
-
log_level
¶ Logging level of this object: trajtracker.log_none, log_error (default), log_warn, log_info, log_debug, log_trace
-
offset_event
¶ The time when the object should disappear from screen.
Type: Event
, or None to avoid automatic offset.
-
onset_event
¶ The time when the object should appear on screen.
Type: Event
, or None to avoid automatic onset.
-
present
(clear=True, update=True)¶ Present all visible stimuli in the container Stimuli marked as invisible will not be shown
Parameters: - clear – See in Expyriment <http://docs.expyriment.org/expyriment.stimuli.Rectangle.html#expyriment.stimuli.Rectangle.present>
- update – See in Expyriment <http://docs.expyriment.org/expyriment.stimuli.Rectangle.html#expyriment.stimuli.Rectangle.present>
Returns: The duration (in seconds) this function took to run
-
register_callback
(callback_func, recurring=False, func_id=None)¶ Register a “present callback” - a function that should be called when the StimulusContainer is present()ed
Parameters: - callback_func –
A function or another callable object, which will be called. This function takes these arguments -
- The StimulusContainer object
- a tuple with the IDs of the stimuli that were actually presented (i.e., stimuli that had stim.visible == True)
- The time when present() returned
- recurring – True = invoke the function on each present() call. False = Invoke the function only on the next present(), and then forget this function.
- func_id – A logical ID for a recurring function (it can be used to unregister the function later)
- callback_func –
-
remove
(stimulus_id)¶ Remove a stimulus from the container
Parameters: stimulus_id – The ID to remove Returns: True if removed, False if not found
-
unregister_non_recurring_callbacks
()¶ Clear all non-recurring listeners that were previously registered
-
unregister_recurring_callback
(func_id)¶ Unregister a recurring listener function that was previously registered via
register_callback()
Parameters: func_id – The function ID that was provided to register_callback()
Returns: True if unregistered, False if there is no registered recurring function with the given func_id
-