Horizontal Alignment

313 views
Skip to first unread message

Sabrina Finke

unread,
May 18, 2016, 7:12:10 AM5/18/16
to psychopy-users
Hi,

While programming a priming paradigm, I have come across the problem of horizontal alignment.
What I would need is a strict left alignment of the prime and target, but alignHoriz only allows an anchoring of the text stimuli.

A few years ago (in 2012) someone asked whether it was possible to choose a strict left alignment of a text, but it this option wasn't available then.

Has a "full" alignment version been implemented since then?

Thanks,
Sabrina

Michael MacAskill

unread,
May 18, 2016, 5:30:12 PM5/18/16
to psychop...@googlegroups.com
Dear Sabrina,

Try the textbox stimulus, a newer alternative to the TextStim. It might give you the control you need (there are some examples under the Coder Demos menu).

Regards,

Michael
--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Sabrina Finke

unread,
May 24, 2016, 6:28:11 AM5/24/16
to psychopy-users
Dear Michael,

Thanks a lot for your answer!
I'm sure the TextBox stimulus offers the features I need.
Unfortunately, there is no entry in the PsychoPy Reference Manual (API) yet, so it is a bit difficult for me to adjust my paradigm as I don't know exactly which arguments TextBox uses.
Do you know if there is a good documentation somewhere?

Regards,
Sabrina
Te Whare Wānanga o Otāgo, Otautahi        Ph:   +64 3 3786 072
Auto Generated Inline Image 1

Michael MacAskill

unread,
May 24, 2016, 5:54:22 PM5/24/16
to psychop...@googlegroups.com
Dear Sabrina,

Yes, it looks like the documentation for that class is not being automatically collated into the online docs. 

Below is what is contained in the source code, and you should also check out the textbox demos under the Coder Demos menu.

Regards,

Michael


class TextBox(object):
    """
    Similar to the visual.TextStim component, TextBox can be used to display
    text within a psychopy window. TextBox and TextStim each have different
    strengths and weaknesses. You should select the most appropriate text
    component type based on how it will be used within the experiment.

    NOTE: As of PsychoPy 1.79, TextBox should be considered experimental.
    The two TextBox demo scripts provided have been tested on
    all PsychoPy supported OS's and run without exceptions. However there are
    very likely bugs in the existing TextBox code and the TextBox API will
    be further enhanced and improved (i.e. changed) over the next couple months.

    TextBox Features:
    ~~~~~~~~~~~~~~~~~

    * Text character placement is very well defined, useful when the exact
      positioning of each letter needs to be known.

    * The text string that is displayed can be changed ( setText() ) and
      drawn ( win.draw() ) **very** quickly. See the TextBox vs. TextStim
      comparison table for details.

    * Built-in font manager; providing easy access to the font family names
      and styles that are available on the computer being used.

    * TextBox is a composite stimulus type, with the following graphical
      elements:
         - TextBox Border / Outline
         - TextBox Fill Area
         - Text Grid Cell Lines
         - Text Glyphs
      Attributes for each of the TextBox graphical elements can be changed
      to control many aspects of how the TextBox is displayed.

    * When using 'rgb' or 'rgb255' color spaces, colors can be specified as
      a list/tuple of 3 elements (red, green, blue), or with four elements
      (reg, green, blue, alpha) which allows different elements of the
      TextBox to use different opacity settings if desired. For colors that
      include the alpha channel value, it will be applied instead of the
      opacity setting of the TextBox, effectively overriding the stimulus
      defined opacity for that part of the textbox graphics. Colors that
      do not include an alpha channel use the opacity setting as normal.

    * Text Line Spacing can be controlled.

    Textbox Limitations:
    ~~~~~~~~~~~~~~~~~~~~

    * Only Monospace Fonts are supported.

    * TextBox component is not a completely **standard** psychopy visual
      stim and has the following functional difference:
          - TextBox attributes are never accessed directly; get* and set*
            methods are always used (this will be changed to use class
            properies in the future).
          - Setting an attribute of a TextBox only supports value replacement,
            ( textbox.setFontColor([1.0,1.0,1.0]) ) and does not support
            specifying operators.

    * Some key word arguments supported by other stimulus types in general,
      or by TextStim itself, are not supported by TextBox. See the TextBox
      class definition for the arguments that are supported.

    * When a new font, style, and size are used it takes about 1 second to
      load and process the font. This is a one time delay for a given
      font name, style, and size. After first being loaded,
      the same font style can be used or re-applied to multiple TextBox
      components with no significant delay.

    * Auto logging or auto drawing is not currently supported.

    TextStim and TextBox Comparison
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ============================ ============= ===========
    Feature                      TextBox       TextStim
    ============================ ============= ===========
    Change text + redraw time^   1.513 msec    28.537 msec
    No change + redraw time^     0.240 msec    0.931 msec
    Initial Creation time^       0.927 msec    0.194 msec
    MonoSpace Font Support       Yes           Yes
    Non MonoSpace Font Support   No            Yes
    Adjustable Line Spacing      Yes           No
    Precise Text Pos. Info       Yes           No
    Auto logging Support         No            Yes
    Rotation Support             No            Yes
    Word Wrapping Support        Yes           Yes
    ============================ ============= ===========

    ^ Times are in msec.usec format. Tested using the textstim_vs_textbox.py
      demo script provided with the PsychoPy distribution. Results are
      dependent on text length, video card, and OS. Displayed results are
      based on 120 character string with an average of 24 words. Test computer
      used Windows 7 64 bit, PsychoPy 1.79, with a i7 3.4 Ghz CPU, 8 GB RAM,
      and NVIDIA 480 GTX 2GB graphics card.

    Example TextBox Usage:
    ~~~~~~~~~~~~~~~~~~~~~~~

        from psychopy import visual

        win=visual.Window((....)

        # A Textbox stim that will look similar to a TextStim component
        #

        textstimlike=visual.TextBox(
                                    window=win,
                                    text="This textbox looks most like a textstim.",
                                    font_size=18,
                                    font_color=[-1,-1,1],
                                    color_space='rgb',
                                    size=(1.8,.1),
                                    pos=(0.0,.5),
                                    units='norm'
                                   )

        # A Textbox stim that uses more of the supported graphical features
        #
        textboxloaded=visual.TextBox(
                         window=win
                         text='TextBox showing all supported graphical elements',
                         font_size=32,
                         font_color=[1,1,1],
                         border_color=[-1,-1,1], # draw a blue border around stim
                         border_stroke_width=4, # border width of 4 pix.
                         background_color=[-1,-1,-1], # fill the stim background
                         grid_color=[1,-1,-1,0.5], # draw a red line around each
                                                   # possible letter area,
                                                   # 50% transparent
                         grid_stroke_width=1,      # with a width of 1 pix
                         textgrid_shape=[20,2], # specify area of text box
                                                # by the number of cols x
                                                # number of rows of text to support
                                                # instead of by a screen
                                                # units width x height.
                         pos=(0.0,-.5),
                         # If the text string length < num rows * num cols in
                         # textgrid_shape, how should text be justified?
                         #
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         )

        textstimlike.draw()
        textboxloaded.draw()
        win.flip()

    """



On 24/05/2016, at 22:28, Sabrina Finke <sabrin...@gmail.com> wrote:

Dear Michael, 

Thanks a lot for your answer!
I'm sure the TextBox stimulus offers the features I need. 
Unfortunately, there is no entry in the PsychoPy Reference Manual (API) yet, so it is a bit difficult for me to adjust my paradigm as I don't know exactly which arguments TextBox uses.
Do you know if there is a good documentation somewhere?

Regards,
Sabrina

-- 
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph:   +64 3 3786 072

Jon

unread,
May 26, 2016, 8:12:11 AM5/26/16
to psychopy-users
I've now added the TextBox documentation (weitten by Sol) to the online reference:

best wishes
Jon
Reply all
Reply to author
Forward
0 new messages