######START OF your custom classes 'module' called visualsExtended.py ########
# Or whatever name you want to give it that does not conflict with the psychopy namespace.
# This file must be saved either in your experiment script dir or python path)
from psychopy import visual
class FixedHeightTextStim(visual.TextStim):
"""
FixedHeightTextStim class extends the psychopy.visual.TextStim class
and sets a default height value that will be used automatically by the class
*unless* a 'height' kwarg is given in the classes constructor.
Any named parameter that is valid for psychopy.visual.TextStim can also be
used in this extended version of the class.
"""
# default text height to be used for all instances of the text class.
_TEXT_HEIGHT=48
def __init__(self,**kwargs):
# Set any default param values you want for your text stim extension
kwargs.setdefault('height',FixedHeightTextStim._TEXT_HEIGHT)
# call the parent classes init
visual.TextStim.__init__(self,**kwargs)
######################### END of visualsExtended.py file ######################
New file....
############## START of your 'experiment' script file #########################
# example 'experiment script' using a subclassed psychopy.visual stim object.
from psychopy import core,visual
from visualsExtended import FixedHeightTextStim
# create the psychopy window
window = visual.Window((1920,1080), units='pix', fullscr=True, allowGUI=False, screen=0)
# create a fixed height text stim
a_text_stim=FixedHeightTextStim(win=window, text='This is some text.',
pos = [0,0], color=[-1,0,-1], colorSpace='rgb',
alignHoriz='center',alignVert='center', wrapWidth=1080)
#draw the stim
a_text_stim.draw()
#flip the win
window.flip()
# show it for ~ 3 seconds
core.wait(3.0)
print 'Done.'
############## END of your 'experiment' script file ###########################