psychopy.org | Reference | Downloads | Github

TextBox displays only part of text

#1

Hi everyone,

I’m currently running the latest psychopy standalone testing version for mac (1.84.0 64bit) on an iMac with OSX 10.11.
I upgraded to the testing version from 1.83.4 after running into the “packaging” package issue. I’m primarily using this set-up for coding and testing, not for running any experiments.

I’m in the process of writing up a simple version of a planned EEG experiment using the Coder. As part of the experiment I want to visually present an “answer array” with six fields/boxes presenting different text answer option for the subjects to select.
I assumed that using visual.TextBox to assemble my answer array would be the easiest option. As a starting point, I ran the demo script textbox_simple.py and also wrote my own simple script adapting the demo script for testing purposes.
In both cases I run into the problem of text not being properly drawn inside the box. Some parts of the text are not drawn at all while other parts are not aligned with the box. I’m attaching a screenshot to illustrate the problem when running the demo code textbox_simple.py as well as my own code. To troubleshoot, I’ve played around with various parameters of TextBox but couldn’t get the text to be displayed properly. What am I missing?

Any help regarding this issue is greatly appreciated.

from psychopy import visual, core, event


window=visual.Window(size=(800,600),
                        units='norm',
                        fullscr=False, allowGUI=True,
                        screen=0, monitor='testMonitor'
                        )


textbox1=visual.TextBox(window=window, 
                         text='OptionA',
                         font_size=32,
                         font_color=[1,1,1], 
                         size=(.3,.3),
                         border_color=[1,1,1,1],
                         pos=(0.15,0.3), 
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         units='norm',
                         )

textbox2=visual.TextBox(window=window, 
                         text='OptionB',
                         font_size=32,
                         font_color=[1,1,1], 
                         size=(.3,.3),
                         border_color=[1,1,1,1],
                         pos=(-0.15,0.3), 
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         units='norm',
                         )

textbox3=visual.TextBox(window=window, 
                         text='OptionC',
                         font_size=32,
                         font_color=[1,1,1], 
                         size=(.3,.3),
                         border_color=[1,1,1,1],
                         pos=(0.15,0.0), 
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         units='norm',
                         )
                         
textbox4=visual.TextBox(window=window, 
                         text='OptionD',
                         font_size=32,
                         font_color=[1,1,1], 
                         size=(.3,.3),
                         border_color=[1,1,1,1],
                         pos=(-0.15,0.0), 
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         units='norm',
                         )

textbox5=visual.TextBox(window=window, 
                         text='OptionE',
                         font_size=32,
                         font_color=[1,1,1], 
                         size=(.3,.3),
                         border_color=[1,1,1,1],
                         pos=(0.15,-0.3), 
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         units='norm',
                         )

textbox6=visual.TextBox(window=window, 
                         text='OptionF',
                         font_size=32,
                         font_color=[1,1,1], 
                         size=(.3,.3),
                         border_color=[1,1,1,1],
                         pos=(-0.15,-0.3), 
                         grid_horz_justification='center',
                         grid_vert_justification='center',
                         units='norm',
                         )



textbox1.draw()
textbox2.draw()
textbox3.draw()
textbox3.draw()
textbox4.draw()
textbox5.draw()
textbox6.draw()

demo_start=window.flip()     

event.clearEvents()
last_attrib_change_time=demo_start
while True:
    if core.getTime()-last_attrib_change_time> 2.5:
        last_attrib_change_time=core.getTime()

   textbox1.draw()
   textbox2.draw()
   textbox3.draw()
   textbox3.draw()
   textbox4.draw()
   textbox5.draw()
   textbox6.draw()

   # Update the display to show any stim changes
   flip_time=window.flip()

   # End the test when a keyboard event is detected
    #
    kb_events=event.getKeys(keyList = ['l', 'r'])
    if kb_events:
        break

core.quit()

#2

Since I couldn’t upload two screenshots at the same time, here is a screenshot illustrating the same issue when running my own code:

#3

Agreed. TextBox seems currently broken! @sol any idea what’s going on? Is it a problem with window units not being used correctly? The TextBox demo is also not rendering all the text at the moment.

#4

I tried running the textbox_simple.py demo using the latest psychopy master source and it seems to run OK for me. I’m running on Windows 7.

I also tried the example code you posted. Unchanged, I get this:

Which shows expected behaviour, the required text area is > the specified textbox size, so some letters are not displayed.

If I change the font size for each textbox stim to 18, then everything fits and I get:

Which looks as I would expect. What happens if you change the font size to 18 or so?

Why the demo is not working for me but not you (and Jon) I am not sure. Possibilities:

  1. screen resolution differences between our monitors. My monitor res. was 1920 x 1080. What is yours?
  2. OS X vs. Windows. textbox is rendered using opengl code, so I think if this is the cause it must be from some difference in the opengl setup when running OS X vs. Windows (if there is any).

Keep in mind is that TextBoxStim uses the provided size arg to set the size of the textbox area; it is not changed based on the number of characters in the specified text. If the required text area (based on number of characters and font size) is too large to fit in the textbox area, then the text that does not fit will (should) not be drawn.

Internally, TextBox takes the size arg and calculates the number of rows and columns of letters that can fit within the textbox area. You can see this textbox letter grid by setting the ‘grid_stroke_width’ and ‘grid_color’ kwargs when creating a textbox:

# draw a red line around each possible letter area,
# 50% transparent, with a width of 1 pix
visual.TextBox( # other textbox args....,
               grid_color=[1,-1,-1,0.5], 
               grid_stroke_width=1
               )

Instead of using the ‘size’ arg, use the ‘textgrid_shape’ arg, if you would rather define the textbox ‘size’ using a specified number of letter rows and columns. For example, if I change the second textbox stim in the textbox_simple.py demo to the following, the textgrid is displayed and the textbox ‘size’ is calculated based on textgrid_shape=[20, 4] (4 rows of 20 characters each) :

textbox2=visual.TextBox(window=window,
                         text='This TextBox illustrates many of the different UX elements.', 
                         font_size=32,
                         font_color=[1, 1, 1],
                         background_color=[-1, -1, -1, 1],
                         border_color=[-1, -1, 1, 1],
                         border_stroke_width=4,
                         grid_color=[1, -1, -1, 0.5],
                         grid_stroke_width=1,
                         textgrid_shape=[20, 4], # 20 cols (20 chars wide)
                                                 # by 4 rows (4 lines of text)
                         pos=(0.0, -0.25)
                         )

the above textbox looks like this on Windows 7:

Hope this helps some. If it turns out that the issue seems to be OS X related (vs. a screen resolution + text size interaction) let me know and I will try to debug the code on OS X (when, I do not know). ;(

Thanks,

Sol

#5

I just tested on OSX 10.11 with screen of 1440x900 (not a fancy retina display or anything) and got the same results as Sarah.

Yes, I thought about that part but if I change the text size to 18 and set the box to be much bigger it still only sets “Opti” :confused:

If I change the demo to use your code above I get this:

NB cool thing about the forum: you can paste an image from the clipboard into your post and (somehow) it does the right thing with it! :slight_smile:

#6

Hi Sol, hi Jon,

thank you very much for the quick reply and additional information - this is very helpful indeed.

I’ve re-run my own code and the demo code using different smaller font sizes but this doesn’t solve the problem. Same for switching to textgrid_shape to replace the size parameter. I’ve also played with using different screen resolutions (starting with my screen’s actual resolution of 2560x1440) but this doesn’t appear to be the source of the problem either.

At least it is good news in a way that it runs okay on Windows as I will ultimately be running my experiment using Windows but wanted to be able to do most of the coding and pre-testing on a mac.

Thanks for your efforts,
Sarah

#7

And switching the units to ‘pix’ doesn’t resolve the misalignment :frowning:

#9

Hello there,
3 years later with an up-to-today full update of my librairies, I have the same issues as this topic.

With this code, I have

from psychopy import visual
from psychopy import core

# create window
win = visual.Window()

# Create textstim
text = visual.TextBox(win,
                        text='This is my text',
                        font_size= 12,
                        font_color=[-1,-1,1], \
                        size=(1,1),
                        pos=(0.0,0.25),
                        grid_horz_justification='center',
                        units='norm')

text.draw()

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],  border_stroke_width=4, background_color=[-1,-1,-1], \
grid_color=[1,-1,-1,0.5], grid_stroke_width=1, textgrid_shape=[20,2], pos=(0.0,-.5),\
grid_horz_justification='center', grid_vert_justification='center' )
textboxloaded.draw()

textbox2=visual.TextBox(window=win,
                         text='This TextBox illustrates many of the different UX elements.',
                         font_size=32,
                         font_color=[1, 1, 1],
                         background_color=[-1, -1, -1, 1],
                         border_color=[-1, -1, 1, 1],
                         border_stroke_width=4,
                         grid_color=[1, -1, -1, 0.5],
                         grid_stroke_width=1,
                         textgrid_shape=[20, 4], # 20 cols (20 chars wide)
                                                 # by 4 rows (4 lines of text)
                         pos=(0.0, -0.25)
                         )
textbox2.draw()
win.flip()
core.wait(2000)

And I have this result :

#10

anyone knows about that ?

#11

I guess it is broken on macOS but not Windows? Latest demos seem OK on Windows 10 (other than the spelling mistake). :wink:

Are you using a Retina display? Wondering if that could be the issue.