[solved] canvas.image and Setting Mouse Position
Hello,
I am creating an experiment in which participants see a set of four pictures while hearing instructions to place a red or a blue square above or below some of the pictures via mouse clicks. I have a working experiment, but some of the details are not quite right. I can display the mouse and collect the clicks with no problem, but I don't see a way to set the mouse cursor starting location on each trial to the center of the display. I tried using the pygame function mouse.set_pos([x,y]), but get the following error:
experiment.run(): experiment started at Tue Jul 10 08:26:51 2012 Traceback (most recent call last): File "libopensesame\inline_script.pyo", line 121, in run File "", line 4, in AttributeError: legacy instance has no attribute 'set_pos'
I really need the mouse to start from the same position on every trial. Is there a way to do this?
Also, to make this work I had to display the images via canvas.image() because in order to get the mouse cursor (I'm using canvas.arrow) to refresh I have to use canvas.clear(), which if I understand correctly, also clears any images I've display via a sketchpad. As far as I can tell, the canvas.image() function requires an absolute file path and does not use the file pool. Have I misunderstood this? Do you have any suggestions about how I might avoid the absolute path so I can move this between machines without changing the path?
Thanks,
John
Comments
That's because a mouse object is not the same as the PyGame mouse class, and doesn't have a set_pos() function. It is a layer on top of the selected back-end, which in your case is probably PyGame.
What you could do is just bypass the mouse object and call pygame directly. You will no longer be able to switch to the psycho backend if you do this, but as long as the legacy back-end is selected it's fine:
You can use exp.get_file(), as shown here: http://osdoc.cogsci.nl/python-inline-code/experiment-functions
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks! Both suggestions worked great!
John