Interaction with text stimuli

296 views
Skip to first unread message

Thomas K.M.

unread,
Nov 5, 2012, 6:42:51 AM11/5/12
to psychop...@googlegroups.com
Regarding stimuli consisting of sentences or whole paragraphs, what are the possibilities (for the subject) for interacting with the text?
I'm thinking in terms of mouse-clicking words or positions in the text.

I know this might be easier to implement either analogically (pen & paper) or with another program, but I would like to use PsychoPy, and I would like to keep subjects from returning to previous text.

Best,
Thomas

Jeremy Gray

unread,
Nov 5, 2012, 7:33:26 AM11/5/12
to psychop...@googlegroups.com
Unfortunately the possibilities are pretty limited at this point, unless you are willing to write your own code. I could imagine a way to do it by a) picking a specific font and font size (the key thing is to have a known and constant character width, so you'd want a mono-spaced font like Courier), and b) arranging your presentation to avoid wrapping long lines. Then you can convert mouse x,y coordinates to text positions, with the y value selecting the line of text, and the x value selecting the character within the line, which you could then map onto words.

To do this for PsychoPy more generally would be quite fussy, given the many degrees of freedom in the font & font spacing, font style (bold is often wider), font size, and the automatic word-wrapping that pyglet does. Except for the word wrapping, it might not be too bad with only mono-spaced fonts (or a specific font). Text is already quite slow to render, and this would presumably make it even slower.

--Jeremy



--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/KVvi6YWVgBIJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Thomas K.M.

unread,
Nov 5, 2012, 6:39:59 PM11/5/12
to psychop...@googlegroups.com
Thanks for the info, Jeremy.
Yeah, I was expecting something like that :)
I was even thinking about "one sentence"-presentations with a rating scale underneath.

Another idea could be eye-tracking in combination with a keypress to indicate timing. So the subject would focus on the point of interest and then press a key to mark the time to look for in the eye-tracking data. Don't know if the eye-tracking is precise enough...

Jeremy Gray

unread,
Nov 5, 2012, 7:35:23 PM11/5/12
to psychop...@googlegroups.com
maybe you could just record the mouse position of a click and the sentence on that trial, and then later (off line) reconstruct what the word was by having someone view the sentence on the screen again, and plot the (previous) mouse position. then the person would record the word (or character position). inelegant and labor intensive, but it would work... maybe less work than setting up eye tracking.


To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/rCKzW8tBxrEJ.

Thomas K.M.

unread,
Nov 8, 2012, 9:18:00 AM11/8/12
to psychop...@googlegroups.com
Would it help to have the text as an image?
I'm thinking that the mouse position could be mapped onto the image as color spots afterwards.

Jeremy Gray

unread,
Nov 8, 2012, 9:47:58 AM11/8/12
to psychop...@googlegroups.com
I think that would work too, probably much the same (show the original stim, show where the subject clicked, manually record the word or letter that was clicked).


To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/R-wUP2QWkn0J.

Thomas K.M.

unread,
Nov 8, 2012, 10:43:17 AM11/8/12
to psychop...@googlegroups.com
Okay, this probably isn't possible, but it would be a cool feature:
F.ex. if stimuli is a paragraph of text. The subject then clicks places of interest, and circles are drawn on those positions. Then via "rect" and "BufferImageStim" we take a screenshot of the text with the circles on and then SAVE that as an image file to look at later.

Jeremy Gray

unread,
Nov 8, 2012, 11:02:45 AM11/8/12
to psychop...@googlegroups.com
this is definitely possibly, and could be done through scripting, basically doing exactly what you say. It might even be possible through the Builder, with some code components, but it would be pushing the Builder beyond what it was designed for.

I am not sure how widely useful it would be, so I don't think its a high priority for adding as an out of the box feature. improved text handling more generally would be worthwhile.


To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/SSb9q8GgIlcJ.

Thomas K.M.

unread,
Nov 8, 2012, 6:14:00 PM11/8/12
to psychop...@googlegroups.com
So I can actually save the screen at any time during an experiment - as an outside image file?
I'm not a coder, but I'm reading about Python at the moment and I think I might be able to figure out the stuff about putting the circles on when the subject clicks, and probably also the "rect" and "BufferImageStim" stuff.
How would I save to an external image file?

Michael MacAskill

unread,
Nov 8, 2012, 9:26:11 PM11/8/12
to psychop...@googlegroups.com

On 9 Nov, 2012, at 12:14, Thomas K.M. <thomas....@gmail.com> wrote:

> So I can actually save the screen at any time during an experiment - as an outside image file?
> I'm not a coder, but I'm reading about Python at the moment and I think I might be able to figure out the stuff about putting the circles on when the subject clicks, and probably also the "rect" and "BufferImageStim" stuff.
> How would I save to an external image file?

The easiest thing to do is the getMovieFrame() method of the Window class. From the API docs (amended slightly:


win.getMovieFrame()
Capture the current Window as an image. This can be done at any time (usually after a .flip() command).
Frames are stored in memory until a .saveMovieFrames(filename) command is issued. You can issue getMovieFrame() as often as you like and then save them all in one go when finished.


The BufferImageStim class seems to allow more flexibility (I haven't actually used it), in that you can capture just a part of the screen rather than the whole thing. But I guess you then have to do more of the heavy lifting to store and then save them all to disk, rather than just using the simple .saveMovieFrames(filename) function.

Cheers,

Mike

Thomas K.M.

unread,
Nov 9, 2012, 4:51:25 AM11/9/12
to psychop...@googlegroups.com
Thanks Mike. Will check it out.

Thomas K.M.

unread,
Nov 22, 2012, 11:11:28 AM11/22/12
to psychop...@googlegroups.com
As it is now, every frame it will check if buttons != [0,0,0] and then draw a circle if the mouse has been clicked. This has the side effect that it will continue to draw as long as the mouse button is pressed down. I'm also drawing the time of the click next to the circle, and if the click is extended over the change from one second to the next, those two time numbers - f.ex. 5 and 6 will be drawn on top of eachother. Depending on the numbers it can become unintelligible.

Is there a way to draw only on the click - maybe by checking if button was pressed at the frame immediately before?

Michael MacAskill

unread,
Nov 22, 2012, 3:39:13 PM11/22/12
to psychop...@googlegroups.com

On 23 Nov, 2012, at 05:11, Thomas K.M. <thomas....@gmail.com> wrote:

> As it is now, every frame it will check if buttons != [0,0,0] and then draw a circle if the mouse has been clicked. This has the side effect that it will continue to draw as long as the mouse button is pressed down. I'm also drawing the time of the click next to the circle, and if the click is extended over the change from one second to the next, those two time numbers - f.ex. 5 and 6 will be drawn on top of eachother. Depending on the numbers it can become unintelligible.
>
> Is there a way to draw only on the click - maybe by checking if button was pressed at the frame immediately before?

Yes. In pseudo-code:

if buttons == [0,0,0]: # don't draw anything
mouseClickedBefore = False
else: # something was clicked, so do drawing, but only once
if not mouseClickedBefore:
# do your drawing stuff, then
win.flip()
mouseClickedBefore = True


Cheers,

Mike

Thomas K.M.

unread,
Nov 22, 2012, 4:31:28 PM11/22/12
to psychop...@googlegroups.com
I love pseudo-code.
Beautiful, Mike.

Cheers back at ya.

Michael MacAskill

unread,
Nov 22, 2012, 4:47:36 PM11/22/12
to psychop...@googlegroups.com

On 23 Nov, 2012, at 10:31, Thomas K.M. <thomas....@gmail.com> wrote:

> Beautiful, Mike.
Although not so beautiful that it didn't have a (potential) bug. The code should be preceded by a standalone statement to initially define the mouseClickedBefore variable:

mouseClickedBefore = False

(to avoid an error in a case where the mouse is clicked on the very first frame).


Cheers,

Mike



--
Michael R. MacAskill, PhD michael....@nzbri.org
Research Director,
New Zealand Brain Research Institute

66 Stewart St http://www.nzbri.org/macaskill
Christchurch 8011 Ph: +64 3 3786 072
NEW ZEALAND Fax: +64 3 3786 080










Reply all
Reply to author
Forward
0 new messages