Howdy, Stranger!

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

Supported by

[solved] closing a form after a specific duration

edited February 2014 in OpenSesame

Hi Opensesame fellows,

Is there a straight forward way to close a form after a fixed duration, if a response has not been entered?
I've had a bit of a search on the site and the forum, but haven't found anything - apologies if I've missed something and this has been dealt with before.

To clarify, participants get 20 seconds to fill in a text box in a form - if they press enter before, the experiment proceeds, but if they haven;t pressed enter after 20 seconds, the experiment proceeds anyway.

I've had a couple of ideas, but they arent working so far.
Any advice very gratefully received.

Best wishes,

Neon

Comments

  • edited 1:28AM

    OK, so moving on, is there a way to use a parallel plugin with an inline script item to close the form? Does this sound reasonable, before I start fiddling with code?

    Again, many thanks in advance for any responses.

    Neon

  • edited February 2014

    I don't know if there's a set way of doing this using forms, but you could always use the following code. It's a DIY text input:

    # import the relevant libraries
    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    
    # define the timeout
    TIMEOUT = 20000 # ms
    # define the text wrapping width
    MAXWIDTH = 500 # pixels; or None to wrap text at screen edge
    
    # create a Canvas object
    cv = canvas(exp)
    
    # create a Keyboard object
    kb = keyboard(exp, keylist=None, timeout=1)
    
    # response variable, to store text in
    typed = ''
    
    # get starting time
    t0 = self.time()
    
    # run while there is no reason to stop
    stop = False
    while not stop:
        # check if there is a new keypress
        key, presstime = kb.get_key()
    
        # process the keypress if there is one
        if key != None:
            # if the key is the Enter key, stop
            if key in ['return','enter']:
                stop = True
            # if the key is backspace, delete the last letter of the response
            # (but only if there is a last letter!)
            elif key =='backspace' and len(typed) > 0:
                typed = typed[:-1]
            # if the key is the space key, add an empty space
            elif key == 'space':
                typed += ' '
            # if the key is something else, add this to the typed response
            else:
                typed += key
    
        # show the newly typed response
        # (first clear the canvas, to remove its previous contents)
        cv.clear()
        cv.text(typed, max_width=MAXWIDTH)
        t1 = cv.show()
    
        # check if the response time has elapsed
        if t1 - t0 >= TIMEOUT:
            stop = True
    
    # save some variables for later use
    exp.set("response", typed)
    exp.set("response_time", t1-t0)
    
    

    P.S.: This does allow for weird keypresses; if you want to constrict people to using only a certain set of keys (e.g. only vowels), please use the keylist keyword argument when the Keyboard object is created, e.g.:

    kb = keyboard(exp, keylist=['a','e','i','o','u','return','enter','space','backspace']
    

    Good luck!

  • edited February 2014

    Hi Neon,

    There is no timeout functionality in forms. Once a user engages with a form, you have to wait until the interaction is finished, i.e. until the user has clicked a button or some other widget that closes the form.

    So for now, the only options would be either Edwin's script, or the text_input plug-in, which is deprecated, but does offer timeout functionality.

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.