open-cogsci / OpenSesame

Graphical experiment builder for the social sciences
http://osdoc.cogsci.nl/
GNU General Public License v3.0
234 stars 111 forks source link

Mouse get_click(): Timout keyword throws error in Python #809

Closed mariansauter closed 5 months ago

mariansauter commented 5 months ago

The error references the line in which I try to collect mouseclicks with

button, (click_x, click_y), timestamp = my_mouse.get_click(timeout=3000)

Error

Traceback (most recent call last):
  File "<stimulus_display.run>", line 41, in <module>
TypeError: cannot unpack non-iterable NoneType object

This happens in a python inline script regardless of the selected backend. Collecting clicks works fine without timeout keyword.

esdalmaijer commented 5 months ago

Hi Marian,

Could it be that the error is actually in the unpacking you do in (click_x, click_y)? I think the function might be returning None instead of a coordinate upon a timeout. The timeout keyword you added will have made this behaviour obvious, but isn't to blame directly.

I'd recommend changing it to the following:

button, click_pos, timestamp = my_mouse.get_click(timeout=3000)
if click_pos is None:
    click_x = None
    click_y = None
else:
    click_x, click_y = click_pos

Cheers, Edwin

mariansauter commented 5 months ago

Yes of course. I don't know how I didn't see that. Thanks Edwin.