ExampleVisualStim

To import ExampleVisualStim, you can either use:

from psychopy_plugin_template.hardware.exampleVisualStim import ExampleVisualStim
or, any time after psychopy.plugins.activatePlugins has been called::

from psychopy.hardware import ExampleVisualStim

class psychopy_plugin_template.visual.exampleVisualStim.ExampleVisualStim(win, units=None, name='', autoLog=None)[source]

Blank visual stim to showcase how to make a new visual stim. Should be deleted before publishing your plugin.

Parameters:
  • win (psychopy.visual.Window) – Window to draw stimulus to

  • units (str) – Spatial unit space in which to specify size, pos, etc. for stimulus.

  • name (str) – Arbitrary name by which to refer to stimulus

  • autoLog (bool) – Whether to automatically log any changes to stimulus’ attributes

property anchor
autoDraw

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!

autoLog

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.

depth

DEPRECATED, depth is now controlled simply by drawing order.

draw()[source]

Your stimulus class needs to define a draw function - otherwise you’ll hit a NotImplementedError at the first win flip!

exampleAttribute

Example attribute to show how to use the attributeSetter decorator.

Parameters:

value (any) – Whatever value you want to set

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 flipHoriz
property flipVert
getAnchor()
getAutoDraw()
getAutoLog()
getDepth()
getExampleAttribute()
getFlip()
getFlipHoriz()
getFlipVert()
getHeight()
getName()
getOpacity()
getOri()
getPos()
getSize()
getUnits()
getVertices()
getWidth()
getWin()
property height
name

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.

property opacity

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 blendMode.

ori

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.

property pos

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)
setAnchor(value, log=None)
setAutoDraw(value, log=None)

Sets autoDraw. Usually you can use ‘stim.attribute = value’ syntax instead, but use this method to suppress the log message.

setAutoLog(value=True, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.

setDepth(newDepth, operation='', log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setExampleAttribute(value, log=True)[source]

If an attribute can be set each frame/repeat from Builder, there needs to be a function called set<attribute name in PascalCase> as this will be called from the generated code.

Parameters:
  • value (any) – Whatever value you want to set

  • log (bool, optional) – Whether or not to log setting this attribute - will be True for set each repeat and False for set each frame

setFlip(value, log=None, operation=False, stealth=False)
setFlipHoriz(value, log=None, operation=False, stealth=False)
setFlipVert(value, log=None, operation=False, stealth=False)
setHeight(value, log=None, operation=False, stealth=False)
setName(value, log=None, operation=False, stealth=False)
setOpacity(newOpacity, operation='', log=None)

Hard setter for opacity, allows the suppression of log messages and calls the update method

setOri(newOri, operation='', log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setPos(newPos, operation='', log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.

setSize(newSize, operation='', units=None, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setUnits(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

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

property units
updateOpacity()

Placeholder method to update colours when set externally, for example updating the pallette attribute of a textbox.

property vertices
property width
property win

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)

Back to top