Slider
¶
A class for obtaining ratings, e.g., on a 1-to-7 or categorical scale. This is a lazy-imported class, therefore import using full path from psychopy.visual.slider import Slider when inheriting from it.
Attributes¶
|
A class for obtaining ratings, e.g., on a 1-to-7 or categorical scale. |
Get the current value of rating (or None if no response yet) |
|
Get the RT for most recent rating (or None if no response yet) |
|
The position on the scale where the marker should be. |
|
|
When the rating scale is read only no responses can be made and the scale contrast is reduced |
Set all elements of the Slider (labels, ticks, line) to a contrast |
|
Return a list of the subject's history as (rating, time) tuples. |
|
Instructs the rating scale to check for valid mouse responses. |
|
Resets the slider to its starting state (so that it can be restarted on each trial with a new stimulus) |
Details¶
- class psychopy.visual.Slider(win, ticks=(1, 2, 3, 4, 5), labels=None, startValue=None, pos=(0, 0), size=None, units=None, flip=False, ori=0, style='rating', styleTweaks=[], granularity=0, readOnly=False, labelColor='White', markerColor='Red', lineColor='White', colorSpace='rgb', opacity=None, font='Helvetica Bold', depth=0, name=None, labelHeight=None, labelWrapWidth=None, autoDraw=False, autoLog=True, color=False, fillColor=False, borderColor=False)[source]¶
A class for obtaining ratings, e.g., on a 1-to-7 or categorical scale.
A simpler alternative to RatingScale, to be customised with code rather than with arguments.
A Slider instance is a re-usable visual object having a
draw()
method, with customizable appearance and response options.draw()
displays the rating scale, handles the subject’s mouse or key responses, and updates the display. As soon as a rating is supplied,.rating
will go from
None
to selected itemYou can call the
getRating()
method anytime to get a rating,getRT()
to get the decision time, orgetHistory()
to obtain the entire set of (rating, RT) pairs.For other examples see Coder Demos -> stimuli -> ratingsNew.py.
- Authors:
2018: Jon Peirce
- Parameters:
win (psychopy.visual.Window) – Into which the scale will be rendered
ticks (list or tuple, optional) – A set of values for tick locations. If given a list of numbers then these determine the locations of the ticks (the first and last determine the endpoints and the rest are spaced according to their values between these endpoints.
labels (a list or tuple, optional) – The text to go with each tick (or spaced evenly across the ticks). If you give 3 labels but 5 tick locations then the end and middle ticks will be given labels. If the labels can’t be distributed across the ticks then an error will be raised. If you want an uneven distribution you should include a list matching the length of ticks but with some values set to None
startValue (int or float, optional) – The initial position of the marker on the slider. If not specified, the marker will start at the mid-point of the scale.
pos (tuple, list, or array, optional) – The (x, y) position of the slider on the screen.
size (w,h pair (tuple, array or list)) – The size for the scale defines the area taken up by the line and the ticks. This also controls whether the scale is horizontal or vertical.
units (str, optional) – The units to interpret the pos and size parameters. Can be any of the standard PsychoPy units (e.g., ‘pix’, ‘cm’, ‘norm’).
flip (bool, optional) – If True, the labels will be placed above (for horizontal sliders) or to the right (for vertical sliders) of the slider line. Default is False.
ori (int or float, optional) –
The orientation of the slider in degrees. A value of 0 means no rotation, positive values rotate the slider clockwise.
style : str or list of str, optional
The style of the slider, e.g., ‘rating’, ‘slider’, ‘radio’. Multiple styles can be combined in a list.
styleTweaks : list of str, optional
Additional styling tweaks, e.g., ‘triangleMarker’, ‘labels45’.
granularity (int or float) – The smallest valid increments for the scale. 0 gives a continuous (e.g. “VAS”) scale. 1 gives a traditional likert scale. Something like 0.1 gives a limited fine-grained scale.
readOnly (bool, optional) – If True, the slider is displayed but does not accept input.
labelColor (color, optional) – The color of the labels in the specified color space.
markerColor (color, optional) – The color of the marker in the specified color space.
lineColor (color, optional) – The color of the slider line and ticks in the specified color space.
colorSpace (str, optional) – The color space for defining labelColor, markerColor, and lineColor (e.g., ‘rgb’, ‘rgb255’, ‘hex’).
opacity (float, optional) – The opacity of the slider, ranging from 0 (completely transparent) to 1 (completely opaque).
font (str, optional) – The font used for the labels.
depth (int, optional) – The depth layer for rendering. Layers with lower numbers are rendered first (behind).
name (str, optional) – An optional name for the slider, useful for logging.
labelHeight (float, optional) – The height of the label text. If None, a default value based on the slider size is used.
labelWrapWidth (float, optional) – The maximum width for text labels before wrapping. If None, labels are not wrapped.
autoDraw (bool, optional) – If True, the slider will be automatically drawn every frame.
autoLog (bool, optional) – If True, a log message is automatically generated each time the slider is updated. This can be useful for debugging or analysis.
color (color, optional) – Synonym for labelColor.
fillColor (color, optional) – Synonym for markerColor.
borderColor (color, optional) – Synonym for lineColor.
- _getHitboxParams()[source]¶
Calculates hitbox size and pos from own size and pos
- _getLineParams()[source]¶
Calculates location and size of the line based on own location and size
- _getMarkerParams()[source]¶
Calculates location and size of marker based on own location and size
- _getTickParams()[source]¶
Calculates the locations of the line, tickLines and labels from the rating info
- _granularRating(rating)[source]¶
Handle granularity for the rating
- property borderColor¶
- property categorical¶
(readonly) determines from labels and ticks whether the slider is categorical
- contrast¶
Set all elements of the Slider (labels, ticks, line) to a contrast
- Parameters:
contrast
- draw()[source]¶
Draw the Slider, with all its constituent elements on this frame
- property extent¶
The distance from the leftmost point on the slider to the rightmost point, and from the highest point to the lowest.
- property fillColor¶
Set the fill color for the shape.
- property flip¶
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.
- property foreColor¶
Foreground color of the stimulus
- Value should be one of:
string: to specify a Colors by name. Any of the standard html/X11 color names <http://www.w3schools.com/html/html_colornames.asp> can be used.
- numerically: (scalar or triplet) for DKL, RGB or
other Color spaces. For these, operations are supported.
When color is specified using numbers, it is interpreted with respect to the stimulus’ current colorSpace. If color is given as a single value (scalar) then this will be applied to all 3 channels.
Examples
For whatever stim you have:
stim.color = 'white' stim.color = 'RoyalBlue' # (the case is actually ignored) stim.color = '#DDA0DD' # DDA0DD is hexadecimal for plum stim.color = [1.0, -1.0, -1.0] # if stim.colorSpace='rgb': # a red color in rgb space stim.color = [0.0, 45.0, 1.0] # if stim.colorSpace='dkl': # DKL space with elev=0, azimuth=45 stim.color = [0, 0, 255] # if stim.colorSpace='rgb255': # a blue stimulus using rgb255 space stim.color = 255 # interpreted as (255, 255, 255) # which is white in rgb255.
Operations work as normal for all numeric colorSpaces (e.g. ‘rgb’, ‘hsv’ and ‘rgb255’) but not for strings, like named and hex. For example, assuming that colorSpace=’rgb’:
stim.color += [1, 1, 1] # increment all guns by 1 value stim.color *= -1 # multiply the color by -1 (which in this # space inverts the contrast) stim.color *= [0.5, 0, 1] # decrease red, remove green, keep blue
You can use setColor if you want to set color and colorSpace in one line. These two are equivalent:
stim.setColor((0, 128, 255), 'rgb255') # ... is equivalent to stim.colorSpace = 'rgb255' stim.color = (0, 128, 255)
- getAnchor()¶
- getBackColor()¶
- getBackColorSpace()¶
- getBackRGB()¶
- getBackgroundColor()¶
- getBorderColor()¶
- getBorderColorSpace()¶
- getBorderRGB()¶
- getBorderWidth()¶
- getCategorical()¶
- getColor()¶
- getColorSpace()¶
- getContrast()¶
- getExtent()¶
- getFillColor()¶
- getFillColorSpace()¶
- getFillRGB()¶
- getFlip()¶
- getFlipHoriz()¶
- getFlipVert()¶
- getFontColor()¶
- getForeColor()¶
- getForeColorSpace()¶
- getForeRGB()¶
- getHeight()¶
- getHistory()[source]¶
Return a list of the subject’s history as (rating, time) tuples.
The history can be retrieved at any time, allowing for continuous ratings to be obtained in real-time. Both numerical and categorical choices are stored automatically in the history.
- getHoriz()¶
- getLabelColor()¶
- getLabelHeight()¶
- getLabelWrapWidth()¶
- getLineColor()¶
- getLineColorSpace()¶
- getLineRGB()¶
- getLineWidth()¶
- getMarkerColor()¶
- getMarkerPos()[source]¶
Get the current marker position (or None if no response yet)
- getMouseResponses()[source]¶
Instructs the rating scale to check for valid mouse responses.
This is usually done during the draw() method but can be done by the user as well at any point in time. The rating will be returned but will ALSO automatically be set as the current rating response.
While the mouse button is down we will alter self.markerPos but don’t set a value for self.rating until button comes up
- Return type:
A rating value or None
- getOpacity()¶
- getPos()¶
- getRGB()¶
- getRT()[source]¶
Get the RT for most recent rating (or None if no response yet)
- getRating()[source]¶
Get the current value of rating (or None if no response yet)
- getSize()¶
- getStyle()¶
- getStyleTweaks()¶
- getTicks()¶
- getUnits()¶
- getValue()¶
- getVertices()¶
- getWidth()¶
- getWin()¶
- get_tickL()¶
- property horiz¶
(readonly) determines from self.size whether the scale is horizontal
- knownStyleTweaks = ['labels45', 'triangleMarker']¶
- knownStyles = ['slider', 'rating', 'radio', 'scrollbar', 'choice']¶
- property labelColor¶
Synonym of Slider.foreColor
- property labelHeight¶
- property labelWrapWidth¶
- legacyStyleTweaks = ['whiteOnBlack']¶
- legacyStyles = []¶
- property markerColor¶
Synonym of Slider.fillColor
- markerPos¶
The position on the scale where the marker should be. Note that this does not alter the value of the reported rating, only its visible display. Also note that this position is in scale units, not in coordinates
- property opacity¶
- property pos¶
- property rating¶
- recordRating(rating, rt=None, log=None)[source]¶
Sets the current rating value
- reset()[source]¶
Resets the slider to its starting state (so that it can be restarted on each trial with a new stimulus)
- setBackColorSpace(value, log=None, operation=False, stealth=False)¶
- setBorderColorSpace(value, log=None, operation=False, stealth=False)¶
- setColorSpace(value, log=None, operation=False, stealth=False)¶
- setExtent(value, log=None, operation=False, stealth=False)¶
- setFillColorSpace(value, log=None, operation=False, stealth=False)¶
- setFlip(value, log=None, operation=False, stealth=False)¶
- setFlipHoriz(value, log=None, operation=False, stealth=False)¶
- setFlipVert(value, log=None, operation=False, stealth=False)¶
- setForeColorSpace(value, log=None, operation=False, stealth=False)¶
- setHeight(value, log=None, operation=False, stealth=False)¶
- setLabelColor(value, log=None, operation=False, stealth=False)¶
- setLabelHeight(value, log=None, operation=False, stealth=False)¶
- setLabelWrapWidth(value, log=None, operation=False, stealth=False)¶
- setLineColorSpace(value, log=None, operation=False, stealth=False)¶
- setMarkerColor(value, log=None, operation=False, stealth=False)¶
- setMarkerPos(rating)[source]¶
Set the current marker position (or None if no response yet)
- setOpacity(newOpacity, operation='', log=None)[source]¶
- setOri(newOri, operation='', log=None)[source]¶
- setPos(newPos, operation='', log=None)[source]¶
- setRating(value, log=None, operation=False, stealth=False)¶
- setReadOnly(value=True, log=None)[source]¶
When the rating scale is read only no responses can be made and the scale contrast is reduced
- setSize(newSize, operation='', units=None, log=None)[source]¶
- setStyle(value, log=None, operation=False, stealth=False)¶
- setStyleTweaks(value, log=None, operation=False, stealth=False)¶
- setTicks(value, log=None, operation=False, stealth=False)¶
- setUnits(value, log=None, operation=False, stealth=False)¶
- setValue(value, log=None, operation=False, stealth=False)¶
- setVertices(value, log=None, operation=False, stealth=False)¶
- setWidth(value, log=None, operation=False, stealth=False)¶
- setWin(value, log=None, operation=False, stealth=False)¶
- property size¶
- property style¶
- styleTweaks¶
Sets some predefined style tweaks or use these to create your own.
If you fancy creating and including your own style tweaks that would be great!
- Parameters:
styleTweaks (list of strings) –
Known style tweaks currently include:
’triangleMarker’: the marker is a triangle ‘labels45’: the text is rotated by 45 degrees
Legacy style tweaks include:
’whiteOnBlack’: a sort of color-inverse rating scale
Legacy style tweaks will work if set in code, but are not exposed in Builder as they are redundant
Style tweaks can be combined in a list e.g. [‘labels45’]
- ticks¶
- property units¶
- updateOpacity()[source]¶
- property value¶
Synonymous with .rating