pyglet vs pygame for TextStims...

513 views
Skip to first unread message

Jon Roberts

unread,
Feb 26, 2010, 11:59:26 AM2/26/10
to psychopy-users
I am working on a project that requires both multiline text stimuli
and single word stimuli with underlining.

It appears that neither pygame nor pyglet support underlining so I
believe I have to draw that myself with a 2 vertex shapeStim. To do
this I need to know the width of the word on the screen. In pyglet,
the TextStim width property gives only the wrapping width for the
rectangle in which the TextStim is displayed. If I switch to pygame, I
get the width value I need to use to do the underline drawing, but
pygame does not seem to support multiline text stimuli, so it looks
like I will need to draw the lines of the multiline stimulus
individually.

Am I missing something, or does anyone have any better ideas? Also,
are there disadvantages to using pygame instead of pyglet?

Thanks

Jon Roberts
Computer Lab for Instruction in Psychological Research
Department of Psychology and Neuroscience
University of Colorado at Boulder

Jon Peirce

unread,
Mar 1, 2010, 5:31:55 AM3/1/10
to psychop...@googlegroups.com
yes, right now pyglet supports multiline text and not pygame. That might change one day but isn't a priority.

Jon

This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

Jon Peirce

unread,
Mar 1, 2010, 5:47:28 AM3/1/10
to psychop...@googlegroups.com
actually it would also be a trivial addition to implement underlining for text stimuli in either backend, but this would be underlining the entire stimulus, not just a single word or something.

Jon

Jonathan O. Roberts

unread,
Mar 1, 2010, 11:05:46 AM3/1/10
to psychop...@googlegroups.com
That works for my current task...

Is pyglet preferable to pygame in general - better performance, etc.?

Using pyglet, I didn't see a way to get the width of the textStim itself, just the width or the word-wrapping rectangle...

thanks...
-Jon Roberts

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To post to this group, send email to psychop...@googlegroups.com.
To unsubscribe from this group, send email to psychopy-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/psychopy-users?hl=en.

Jon Peirce

unread,
Mar 3, 2010, 7:33:27 AM3/3/10
to psychop...@googlegroups.com

Jonathan O. Roberts wrote:
That works for my current task...

Is pyglet preferable to pygame in general - better performance, etc.?
No, I don't think so. In fact, for text, I think pygame might render faster than pyglet. The advantage of pyglet is its ability to handle multiple windows and monitors and the fact that it can play movies. If you have a single screen and don't need movies then pygame might be a better choice. I should add this to the docs I guess.


Using pyglet, I didn't see a way to get the width of the textStim itself, just the width or the word-wrapping rectangle...

Text width comes simply from font height and the aspect ratio of the font. Otherwise letters will get stretched in some odd ways.

thanks...
-Jon Roberts

On Mar 1, 2010, at 3:47 AM, Jon Peirce wrote:

actually it would also be a trivial addition to implement underlining for text stimuli in either backend, but this would be underlining the entire stimulus, not just a single word or something.

Jon



Henrik Singmann

unread,
Mar 5, 2010, 9:16:08 AM3/5/10
to psychop...@googlegroups.com
Hello,

I am new to PsychoPy, and currently trying to get a rather simple
Simon experiment to running (actually, I am a little sad that there is
no demo implementation of a simple experiment with different trial
types, blocks, collecting responses and stuff, so if somebody got a
simple thing like this I would really like to take a look at and would
share what i got when it is ready).

As I finally got the trial-handling part, I am trying to implement the
presentation of the stimuli. Following the advise below I started
playing around with a pygame window. However, using either PatchStim
or ShapeStim does not work as expected. Especially, the sizes of the
objects are in no relation to the expected sizes. I just see a tiny
little spot in the center of th screen instead of a spot with 1cm
diameter. However, when changing the winType to 'pyglet' everything
looks fine (i.e., I measured it at my monitor and the sizes match).
It would be great if anyone could help me to dissolve this dissonance,
otherwise I just ignore the below menionted advise to use pygame.

Below you find the minimal code I used.

Greetings,

Henrik

PS: I adjusted the values in the monitor center dialogue to the actual ones.


from psychopy import *

myWin = visual.Window((800,800),monitor='testMonitor', units ='cm',
rgb=-1.0, winType='pygame')

bar = visual.ShapeStim(myWin,
lineRGB=[1,1,1],
lineWidth=2.0,
fillRGB=[1,1,1],
vertices=[[-0.2,0.5],[0.2,0.5],
[0.2,-0.5], [-0.2,-0.5]],
closeShape=True,
pos=[3,0])

fixSpot = visual.PatchStim(myWin,tex="none", units='cm',
mask="circle", size=[1,1],rgb=1)

bar.draw()
fixSpot.draw()
myWin.flip()
core.wait(20)


2010/3/3 Jon Peirce <jonatha...@nottingham.ac.uk>:

Jon Peirce

unread,
Mar 5, 2010, 10:19:00 AM3/5/10
to psychop...@googlegroups.com
You're quite right. The measurements are way out for pygame right now. I wonder if there have been changes to the pygame library itself that has altered window scaling, because these definitely did /used/ to work fine :-$ . I'm afraid the reality is that I don't use the pygame backend for my own work, so I guess it's fallen into disrepair.

Michael MacAskill and Daniel Myall were planning to overhaul the calculation of vertex positions and I'm inclined to wait for them to finish before investigating this problem too deeply.

In the meantime, yes, just use pyglet backend. The difference mentioned below is relatively small and only relates to people that need to render large number of text stimuli.

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