[solved] Implementing Forms with Canvas Objects
Hi all,
Apologies if this issue has already arisen. I've had a look and didn't see this anything that answered this question so am starting a new thread. I'm very new to Opensesame so I suspect the answer to this question will be fairly straightforward.
My experiment requires participants to view a series of objects (e.g. rectangles, circles, text) and respond to these stimuli by pressing a button (from a series of 11) on the screen. I'm managed to use the canvas objects to create my stimuli via the inline script facility. And have also managed to use form objects to create the button series. My problem is that I cannot seem to get the canvas objects to be presented on the same screen as the form objects. For example, when I present the canvas objects via the .show command, these objects will disappear as soon as I execute the form via the form._exec() command. How do I get the canvas objects and the form objects to present simultaneously?
Cheers.
Tim
Comments
Hi Tim,
You cannot draw on forms in the same way that you can with
canvasobjects, so what you want to do (combining form widgets with custom drawing operations) is difficult. Since you're already familiar withinline_scripts, you could consider the following alternative.Step 1: Draw your images using PIL (Python imaging library) and save them as temporary images to the file pool. The following script (to be pasted in the prepare phase of an
inline_scriptitem) shows the general idea, but PIL is very well documented and easy to use.Step 2: Include the just-generated images in a form using the
imageorimage_buttonwidgets. For example (this is OpenSesame script, not Python):Does that help at all?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Sorry for the delayed reply. I was waiting to see if any more issues arose, and nothing has yet! So far so good. Thanks for your help.
Regards,
Tim
Ok, it seems I spoke too soon. I'm trying to use the 'ImageFont.truetype' command to specify font type and size. However, when I use this command, I get the following error:
"ImportError: The _imagingft C module is not installed"
The script runs fine when I don't use that command. However, I'd like to be able to specify font type and size.
Any ideas?
Cheers,
Tim
Hi Tim,
Right, that's because the standard distribution of PIL is not compiled with support for TrueType fonts. What you could try is replace the PIL module (which is a subfolder of OpenSesame) by a PIL version that is compiled with TrueType support. That will require a bit of Googling though—I assume it's possible, but I don't know right away how to do it.
Another option would be to use the
pygamedrawing routines, which support TrueType out of the box. The script below does the same as the script above, but using PyGame instead of PIL. There's no real advantage to using one over the other (except TrueType support, obviously).Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Pygame worked incredibly well. Thanks a lot Sebaastiaan! For anyone else using Pygame, I found this website very useful.
http://www.pygame.org/docs/ref/surface.html