Using forms in Psychopy backend
Hello everyone,
I have trying to design my experiment in open sesame whereby I request the subject to enter personnel info before starting the trial ( name, age, sex etc), followed by gap overlap task so it needs to be fairly accurate so I am using psychopy backend. But while using this backend if I try to add the consent form as well as a custom form, the experiment hangs and I have to quit the experiment. Also, in general I tried running the in-built consent form in expyriment backend but I was facing the same issue. It is only working in legacy backend.
I hope my problem is clear. Can anybody suggest a possible workaround?
Is it possible to draw same custom form in psychopy through inline script instead of using the widgets?
Thank you in advance
Comments
Hi,
I'm not sure what causes your problem, but it is certainly possible to create a form by means of an inline_script rather than the widgets. This will require a bit of coding however. You'll have to manually program a text bar in which people can input text, and this text also needs to be made visible as the participant types.
I do have some code that takes care of this here:
You just have to define the variable startpoint, which represents the x-coordinate at which the first letter needs to appear. All the other info and instructions you want to have on your form can be added with the canvas.text() function (see also http://osdoc.cogsci.nl/3.1/manual/python/canvas/#function-canvas46text40text-centertrue-xnone-ynone-max95widthnone-4242style95args41).
Cheers,
Josh
Thanks Josh,
I tried running the above code in psychopy backend but when I run the code all I see is a blank screen. I think I am able to enter the text input but it is not visible. Am I missing something?
For reference, I am posting the inline script I am using:
from openexp.keyboard import keyboard
from openexp.canvas import canvas
my_keyboard = keyboard(exp, timeout=None)
input_canvas = canvas(exp)
startpoint = input_canvas.xcenter()
answered = False
letters = 0
resp = ''
while answered == False:
key, timestamp = my_keyboard.get_key()
if key == 'backspace':
if len(resp)>0:
startpoint -= input_canvas.text_size('w')[0]
input_canvas.rect(x=startpoint-input_canvas.text_size('x')[0]*0.5,y=input_canvas.ycenter()+30,\
w=input_canvas.text_size('w')[0], h = 30, fill=True)
input_canvas.show()
resp = resp[0:-1]
elif key == 'return':
answered = True
elif key != None and key != 'left' and key != 'right' and len(resp)<6:
input_canvas.rect(x=startpoint,y=input_canvas.ycenter()+30,\
w=input_canvas.text_size('w')[0], h = 30, fill=False)
input_canvas.text(key,center=True, x=startpoint,y=input_canvas.ycenter()+45, color='white')
startpoint += input_canvas.text_size('w')[0]
input_canvas.show()
resp += key
I was able to figure out that I was defining the coordinates of rect and text in a format supported by earlier version of open sesame by taking the top left coordinate, because of which they were being drawn outside of the screen. By changing it, relative to the center coordinates I was able to get the result.
Thanks for the help!
No problem!
Josh