Form
¶
|
A class to add Forms to a psychopy.visual.Window |
The |
|
This determines the coordinates of the vertices for the current stimulus in pixels, accounting for size, ori, pos and units |
|
Placeholder method to update colours when set externally, for example updating the pallette attribute of a textbox. |
|
Placeholder method to update colours when set externally, for example updating the pallette attribute of a textbox |
|
The size (width, height) of the stimulus in the stimulus units |
|
|
Usually you can use 'stim.attribute = value' syntax instead, but use this method if you need to suppress the log message |
|
Set scroll speed of Form. |
|
DEPRECATED: Legacy setter for foreground RGB, instead set obj._foreColor.rgb |
|
Usually you can use 'stim.attribute = value' syntax instead, but use this method if you need to suppress the log message. |
|
Usually you can use 'stim.attribute = value' syntax instead, but use this method if you need to suppress the log message |
|
Hard setter for opacity, allows the suppression of log messages and calls the update method |
|
|
|
DEPRECATED since v1.60.05: Please use the color attribute |
|
Hard setter for foreColor, allows suppression of the log message, simultaneous colorSpace setting and calls update methods. |
|
Hard setter for fillColor, allows suppression of the log message, simultaneous colorSpace setting and calls update methods. |
|
Usually you can use 'stim.attribute = value' syntax instead, but use this method if you need to suppress the log message |
|
DEPRECATED since v1.60.05: Please use the color attribute |
|
Usually you can use 'stim.attribute = value' syntax instead, but use this method if you need to suppress the log message |
|
|
|
Hard setter for fillColor, allows suppression of the log message, simultaneous colorSpace setting and calls update methods. |
|
|
|
Usually you can use 'stim.attribute = value' syntax instead, but use this method if you need to suppress the log message. |
|
Sets autoDraw for Form and any responseCtrl contained within |
The position of the center of the stimulus in the stimulus units |
|
|
Returns True if this stimulus intersects another one. |
The orientation of the stimulus (in degrees). |
|
Determines how visible the stimulus is relative to background. |
|
The name (str) of the object to be using during logged messages about this stim. |
|
Alternative way of setting borderColor. |
|
|
Import items from csv or excel sheet and convert to list of dicts. |
Extracts form questions, response ratings and response times from Form items |
|
Deprecated in version 2020.2. |
|
Sets both itemColor and responseColor to the same value |
|
Color of the form's background |
|
Draw all form elements |
|
DEPRECATED, depth is now controlled simply by drawing order. |
|
A value that is simply multiplied by the color. |
|
|
Returns True if a point x,y is inside the stimulus' border. |
A read-only property to determine if the current form is complete |
|
The name of the color space currently being used |
|
Alternative way of setting foreColor. |
|
Color of the line around the form |
|
Alternative way of setting fillColor |
|
Whether every change in this stimulus should be auto logged. |
|
Determines whether the stimulus should be automatically drawn on every frame flip. |
|
|
Gets the current Form data and inserts into an |
A class to add Forms to a psychopy.visual.Window
The Form allows Psychopy to be used as a questionnaire tool, where participants can be presented with a series of questions requiring responses. Form items, defined as questions and response pairs, are presented simultaneously onscreen with a scrollable viewing window.
Example
survey = Form(win, items=[{}], size=(1.0, 0.7), pos=(0.0, 0.0))
win (psychopy.visual.Window) – The window object to present the form.
items (List of dicts or csv or xlsx file) –
”index”: The item index as a number “itemText”: item question string, “itemWidth”: fraction of the form width 0:1 “type”: type of rating e.g., ‘radio’, ‘rating’, ‘slider’ “responseWidth”: fraction of the form width 0:1, “options”: list of tick labels for options, “layout”: Response object layout e.g., ‘horiz’ or ‘vert’
textHeight (float) – Text height.
itemPadding (float) – Space or padding between form items.
units (str) – units for stimuli - Currently, Form class only operates with ‘height’ units.
randomize (bool) – Randomize order of Form elements
Legacy property for setting the foreground color of a stimulus in RGB, instead use obj._foreColor.rgb
DEPRECATED
DEPRECATED in 1.80.00. This functionality is now handled by _updateVertices() and verticesPix.
DEPRECATED in 1.80.00. This functionality is now handled by _updateVertices() and verticesPix
Draw elements on form within border range.
items (List) – List of TextStim or Slider item from survey
Convert color to RGB while adding contrast. Requires self.rgb, self.colorSpace and self.contrast
Returns the full height of the item to be inserted in the form
Returns text width for item text based on itemWidth and Form width.
DEPRECATED. Return a list of vertices as rendered.
Calculate offset position of items in relation to markerPos. Offset is a proportion of vheight - height, meaning the max offset (when scrollbar.markerPos is 1) is enough to take the bottom element to the bottom of the border.
Offset position of items proportionate to scroll bar
This needs to be done when editable textboxes change their size because everything below them needs to move too
Creates TextBox object for Form class
NOTE: The TextBox 2 in work in progress, and has not been added to Form class yet. :param item: The dict entry for a single item :type item: dict :param pos: position of response object :type pos: tuple
psychopy.visual.TextBox – The TextBox object for response
respHeight – The height of the response object as type float
Switch drawing to the specified window. Calls the window’s _setCurrent() method which handles the switch.
DEPRECATED since 1.80.04 + 1. Use setAttribute() and val2array() instead.
Blocks text beyond border using Aperture
The aperture setting viewable area for forms
Creates border using Rect
The border for the survey
psychopy.visual.Rect
Creates TextStim object containing question
item (dict) – The dict entry for a single item
psychopy.visual.text.TextStim – The textstim object with the question string
questionHeight – The height of the question bounding box as type float
questionWidth – The width of the question bounding box as type float
Makes calls to methods which make Slider or TextBox response objects for Form
Creates Slider object for scrollbar
The Slider object for scroll bar
The user shouldn’t need this method since it gets called after every call to .set() Chooses between using and not using shaders each call.
Sets Stim.verticesPix and ._borderPix from pos, size, ori, flipVert, flipHoriz
Gets the current Form data and inserts into an
ExperimentHandler
object either as rows
or as columns
exp (ExperimentHandler
) –
itemsAs ('rows','cols' (or 'columns')) –
Determines whether the stimulus should be automatically drawn on every frame flip.
Value should be: True or False. You do NOT need to set this on every frame flip!
Whether every change in this stimulus should be auto logged.
Value should be: True or False. Set to False if your stimulus is updating frequently (e.g. updating its position every frame) and you want to avoid swamping the log file with messages that aren’t likely to be useful.
Alternative way of setting fillColor
Deprecated, please use colorSpace to set color space for the entire object.
Legacy property for setting the fill color of a stimulus in RGB, instead use obj._fillColor.rgb
DEPRECATED
Alternative way of setting fillColor
Color of the line around the form
Deprecated, please use colorSpace to set color space for the entire object
Legacy property for setting the border color of a stimulus in RGB, instead use obj._borderColor.rgb
DEPRECATED
Alternative way of setting foreColor.
The name of the color space currently being used
Value should be: a string or None
For strings and hex values this is not needed. If None the default colorSpace for the stimulus is used (defined during initialisation).
Please note that changing colorSpace does not change stimulus parameters. Thus you usually want to specify colorSpace before setting the color. Example:
# A light green text
stim = visual.TextStim(win, 'Color me!',
color=(0, 1, 0), colorSpace='rgb')
# An almost-black text
stim.colorSpace = 'rgb255'
# Make it light green again
stim.color = (128, 255, 128)
A read-only property to determine if the current form is complete
Returns True if a point x,y is inside the stimulus’ border.
two separate args, x and y
one arg (list, tuple or array) containing two vals (x,y)
as a Mouse
.
Returns True if the point is within the area defined either by its border attribute (if one defined), or its vertices attribute if there is no .border. This method handles complex shapes, including concavities and self-crossings.
Note that, if your stimulus uses a mask (such as a Gaussian) then this is not accounted for by the contains method; the extent of the stimulus is determined purely by the size, position (pos), and orientation (ori) settings (and by the vertices for shape stimuli).
See Coder demos: shapeContains.py See Coder demos: shapeContains.py
A value that is simply multiplied by the color.
Operations supported.
Set the contrast of the stimulus, i.e. scales how far the stimulus deviates from the middle grey. You can also use the stimulus opacity to control contrast, but that cannot be negative.
Examples:
stim.contrast = 1.0 # unchanged contrast
stim.contrast = 0.5 # decrease contrast
stim.contrast = 0.0 # uniform, no contrast
stim.contrast = -0.5 # slightly inverted
stim.contrast = -1.0 # totally inverted
Setting contrast outside range -1 to 1 is permitted, but may produce strange results if color values exceeds the monitor limits.:
stim.contrast = 1.2 # increases contrast
stim.contrast = -1.2 # inverts with increased contrast
DEPRECATED, depth is now controlled simply by drawing order.
Color of the form’s background
Deprecated, please use colorSpace to set color space for the entire object.
Legacy property for setting the fill color of a stimulus in RGB, instead use obj._fillColor.rgb
DEPRECATED
1x2 array for flipping vertices along each axis; set as True to flip or False to not flip. If set as a single value, will duplicate across both axes. Accessing the protected attribute (._flip) will give an array of 1s and -1s with which to multiply vertices.
Alternative way of setting foreColor.
Sets both itemColor and responseColor to the same value
Deprecated, please use colorSpace to set color space for the entire object.
Legacy property for setting the foreground color of a stimulus in RGB, instead use obj._foreColor.rgb
DEPRECATED
Extracts form questions, response ratings and response times from Form items
A copy of the data as a list of dicts
Import items from csv or excel sheet and convert to list of dicts. Will also accept a list of dicts.
Note, for csv and excel files, ‘options’ must contain comma separated values, e.g., one, two, three. No parenthesis, or quotation marks required.
items (Excel or CSV file, list of dicts) – Items used to populate the Form
A list of dicts, where each list entry is a dict containing all fields for a single Form item
List of dicts
Color of the text on form items
Alternative way of setting borderColor.
Deprecated, please use colorSpace to set color space for the entire object
Legacy property for setting the border color of a stimulus in RGB, instead use obj._borderColor.rgb
DEPRECATED
Color of the marker on any sliders in this form
The name (str) of the object to be using during logged messages about this stim. If you have multiple stimuli in your experiment this really helps to make sense of log files!
If name = None your stimulus will be called “unnamed <type>”, e.g. visual.TextStim(win) will be called “unnamed TextStim” in the logs.
Determines how visible the stimulus is relative to background.
The value should be a single float ranging 1.0 (opaque) to 0.0 (transparent). Operations are supported. Precisely how this is used depends on the Blend Mode.
The orientation of the stimulus (in degrees).
Should be a single value (scalar). Operations are supported.
Orientation convention is like a clock: 0 is vertical, and positive values rotate clockwise. Beyond 360 and below zero values wrap appropriately.
Returns True if this stimulus intersects another one.
If polygon is another stimulus instance, then the vertices and location of that stimulus will be used as the polygon. Overlap detection is typically very good, but it can fail with very pointy shapes in a crossed-swords configuration.
Note that, if your stimulus uses a mask (such as a Gaussian blob) then this is not accounted for by the overlaps method; the extent of the stimulus is determined purely by the size, pos, and orientation settings (and by the vertices for shape stimuli).
See coder demo, shapeContains.py
The position of the center of the stimulus in the stimulus units
value should be an x,y-pair. Operations are also supported.
Example:
stim.pos = (0.5, 0) # Set slightly to the right of center
stim.pos += (0.5, -1) # Increment pos rightwards and upwards.
Is now (1.0, -1.0)
stim.pos *= 0.2 # Move stim towards the center.
Is now (0.2, -0.2)
Tip: If you need the position of stim in pixels, you can obtain it like this:
from psychopy.tools.monitorunittools import posToPix
posPix = posToPix(stim)
Color of the lines and text on form responses
Width of the scrollbar for this Form, in the spatial units of this Form. Can also be set as a layout.Vector object.
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.
DEPRECATED: Legacy setter for fill RGB, instead set obj._fillColor.rgb
Hard setter for fillColor, allows suppression of the log message, simultaneous colorSpace setting and calls update methods.
DEPRECATED: Legacy setter for border RGB, instead set obj._borderColor.rgb
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message
DEPRECATED since v1.60.05: Please use the color attribute
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message
Hard setter for fillColor, allows suppression of the log message, simultaneous colorSpace setting and calls update methods.
DEPRECATED: Legacy setter for fill RGB, instead set obj._fillColor.rgb
Hard setter for foreColor, allows suppression of the log message, simultaneous colorSpace setting and calls update methods.
DEPRECATED: Legacy setter for foreground RGB, instead set obj._foreColor.rgb
DEPRECATED since v1.60.05: Please use the color attribute
DEPRECATED: Legacy setter for border RGB, instead set obj._borderColor.rgb
Hard setter for opacity, allows the suppression of log messages and calls the update method
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.
DEPRECATED: Legacy setter for foreground RGB, instead set obj._foreColor.rgb
Set scroll speed of Form. Higher multiplier gives smoother, but slower scroll.
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message
The size (width, height) of the stimulus in the stimulus units
Value should be x,y-pair, scalar (applies to both dimensions) or None (resets to default). Operations are supported.
Sizes can be negative (causing a mirror-image reversal) and can extend beyond the window.
Example:
stim.size = 0.8 # Set size to (xsize, ysize) = (0.8, 0.8)
print(stim.size) # Outputs array([0.8, 0.8])
stim.size += (0.5, -0.5) # make wider and flatter: (1.3, 0.3)
Tip: if you can see the actual pixel range this corresponds to by looking at stim._sizeRendered
Placeholder method to update colours when set externally, for example updating the pallette attribute of a textbox
Placeholder method to update colours when set externally, for example updating the pallette attribute of a textbox.
This determines the coordinates of the vertices for the current stimulus in pixels, accounting for size, ori, pos and units
The Window
object in which the
stimulus will be rendered by default. (required)
Example, drawing same stimulus in two different windows and display simultaneously. Assuming that you have two windows and a stimulus (win1, win2 and stim):
stim.win = win1 # stimulus will be drawn in win1
stim.draw() # stimulus is now drawn to win1
stim.win = win2 # stimulus will be drawn in win2
stim.draw() # it is now drawn in win2
win1.flip(waitBlanking=False) # do not wait for next
# monitor update
win2.flip() # wait for vertical blanking.
Note that this just changes default window for stimulus.
You could also specify window-to-draw-to when drawing:
stim.draw(win1)
stim.draw(win2)