Global fontsize

550 views
Skip to first unread message

Horea Christian

unread,
Mar 14, 2013, 11:58:51 PM3/14/13
to psychop...@googlegroups.com
Hello, is there any way to globally define my font size (for text being displayed in my visual.Window) ? I found the visual.TextStim.setSize argument, but I'd rather set the size for all the text stimuli I create at the beginning. 

Cheers,

Jeremy Gray

unread,
Mar 15, 2013, 11:35:17 AM3/15/13
to psychop...@googlegroups.com
You can define the size when you create the text stim, no need to call
.setSize() separately. So you could have your own variable, and always
create your text stim using that variable

textHeight = 0.12
...
t1 = visual.TextStim(win, text='abc', height= textHeight)
t2 = visual.TextStim(win, text='def', height= textHeight)
> --
> You received this message because you are subscribed to the Google Groups
> "psychopy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psychopy-user...@googlegroups.com.
> To post to this group, send email to psychop...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/psychopy-users/-/u8XfEm_1Bj0J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Sol Simpson

unread,
Mar 15, 2013, 2:05:36 PM3/15/13
to psychop...@googlegroups.com
Along the same lines as Jeremy suggested, you could also extend the TextStim class and set any
'constant' params in the __init__ of the subclass you are creating. This way you do not need to keep
entering arg values that are constant each time you create the stim resource.

A simple example...

######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 ###########################
Reply all
Reply to author
Forward
0 new messages