Select one text input (out of 2) and insert text, without having to keep mouse button pressed

Hi all,

OS (e.g. Win10): MacOS Mojave
PsychoPy version (e.g. 1.84.x): 2020.1.2
Standard Standalone? (y/n) Yes
What are you trying to achieve?:
I am building an experiment in builder, for which I would like to check the visual angle of the participants. Participants can type the length of the line they see on the screen and the distance they are away from the screen (I have used the demo in this link: demos / textInput · GitLab). We then perform a backwards calculation with my own visual angle of the distance they need to sit from the screen given my own visual angle. I have drawn a shape around each text input to be able to select. However, I am not able to click the shape and then type the text. I have to keep the left mousebutton pressed to be able to type the text. It works, but is not very user-friendly. Is it possible to select 1 out of 2 text inputs with a single mouse click and then type a response in the selected box?

What did you try to make it work?:
I have the following code at the Each Frame tab:

# -*- coding: utf-8 -*-
import math

keys = event.getKeys()
#print(keys)
if 'escape' in keys:
    core.quit()
#if 'return' in keys:
#    continueRoutine = False

Line_box.draw()
Distance_box.draw()

if mouse_VA.isPressedIn(Line_box):
    Line_box.lineWidth = 5
    Line_box.lineColor = 'Red'
    Distance_box.lineWidth = None
    Distance_box.lineColor = None
    if len(keys):
        if 'escape' in keys:
            text_Line.text = ''
        elif 'right' in keys:
            text_Line.text = ''
        elif 'left' in keys:
            text_Line.text = ''
        elif 'space' in keys:
            text_Line.text = text_Line.text + ' '
        elif 'backspace' in keys:
            text_Line.text = text_Line.text[:-1]
        elif 'lshift' in keys or 'rshift' in keys:
            modify = True
        elif 'return' in keys:
            text_Line.text = text_Line.text
        else:
            if modify:
                text_Line.text = text_Line.text + keys[0].upper()
                modify = False
            else:
                text_Line.text = text_Line.text + keys[0]
elif mouse_VA.isPressedIn(Distance_box):
        Line_box.lineWidth = None
        Line_box.lineColor = None
        Distance_box.lineWidth = 5
        Distance_box.lineColor = 'Red'
        if len(keys):
            if 'escape' in keys:
                text_Distance.text = ''
            elif 'right' in keys:
                text_Distance.text = ''
            elif 'left' in keys:
                text_Distance.text = ''
            elif 'space' in keys:
                text_Distance.text = text_Distance.text + ''
            elif 'backspace' in keys:
                text_Distance.text = text_Distance.text[:-1]
            elif 'lshift' in keys or 'rshift' in keys:
                modify = True
            elif 'return' in keys:
                text_Distance.text = text_Distance.text
            else:
                if modify:
                    text_Distance.text = text_Distance.text + keys[0].upper()
                    modify = False
                else:
                    text_Distance.text = text_Distance.text + keys[0]

if text_Line.text == '':
    Imagesize = 1
if text_Distance.text == '':
    D = 1
else:
    Imagesize = int(text_Line.text) # size of the line in millimeters is 70
    #print(Imagesize)
    D = int(text_Distance.text) # my arm's length in millimeters is 630
    #print(D)
    theta1 = 0.11099701049143366 # Visual angle theta = 2*math.atan(Imagesize/(2*D))
    Dest = round((Imagesize/(math.tan(theta1/2)))/2,0)
    #print(Dest)
    if D == Dest:
        msg = "You are at the right distance from the screen. Please, press 'enter' to proceed. "
        if 'return' in keys:
            continueRoutine = False
    elif D >= Dest:
        Dif = (D-Dest)/10
        msg1 = "Please, move " 
        msg2 = " cm closer and measure your distance again"
        msg = msg1 + str(int(round(Dif,0))) + msg2
    elif Dest >= D:
        Dif = (Dest-D)/10
        msg1 = "Please, move " 
        msg2 = " cm away and measure your distance again"
        msg = msg1 + str(int(round(Dif,0))) + msg2

What specifically went wrong when you tried that?:
I have tried inserting a while-loop under if mouse_VA.isPressedIn(Line_box): and elif mouse_VA.isPressedIn(Distance_box):, but I was not able to type in any text after this.

Do you have any suggestions as to what I have done wrong with the while loop or what might better solutions?
I have attached my check of participants visual angle below, in case it helps.

Thanks in advance.

Kind regards,

Ellen

Visual_Angle.psyexp (30.0 KB)

This sounds like something the new TextBox component can handle! That will allow you to create an editable text input with a box around it by setting the fillColor and borderColor attributes

Dear TParsons,

The textbox does help: I am able to select either textbox and type the text I want. However, it is important for me to be able to capture the typed text. This way I can plug it into a formula to determine whether participants are close to the screen.

I have installed psychopy 2020.2.4 for this textbox. I used the following line of code to try to get the typed text:

t = Line_box.getDisplayedText()

When I try to run my routine, I only get the participant-session dialogue box followed by a grey screen that disappears after a few seconds. The runner Stdout does not give any error messages (this is a known issue: No error messages or logging output in Stdout ), so I have no idea as to how to debug this.
Could you please, give me some pointers as to how I can capture text typed in my textboxes?
Thanks in advance.

Ellen