Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] canvas.image and Setting Mouse Position

edited July 2012 in OpenSesame

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

  • edited 9:44PM
    I tried using the pygame function mouse.set_pos([x,y]), but get the following error:

    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:

    import pygame
    pygame.mouse.set_pos((exp.get('width')/2,exp.get('height')/2))
    As far as I can tell, the canvas.image() function requires an absolute file path and does not use the file pool.

    You can use exp.get_file(), as shown here: http://osdoc.cogsci.nl/python-inline-code/experiment-functions

    Cheers!

  • edited 9:44PM

    Thanks! Both suggestions worked great!

    John

Sign In or Register to comment.