Howdy, Stranger!

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

Supported by

Text input without mouseclick + key restrictions for text input

edited January 25 in OpenSesame

Hello,
I am planning an experiment with a text input and have a few problems I can't overcome. A short summary for the procedure:
People receive two statements about objects (e.g. The apple left of the pear; The Banana is right of the pear). After reading the statments they shall write the first letter of each oject in one text file.
Lets say the solution is Apple Pear Banana. They have to type A P B.

Now.. there are always two correct possibilities (revision_ro and revision_lo) and all other are wrong. I want the two correct onces to be coded sperately because it serves important information. I made a python script like this:

from libopensesame import widgets
form = widgets.form(exp)
text_input = widgets.text_input(form, stub = 'Schreibe hier..  ', center=True, frame = True, var='user_input',
        return_accepts=True)


form.set_widget(text_input, (0,0))
form._exec(focus_widget=None)

if var.user_input == var.revision_lo:
        var.correctness = 1
elif var.user_input == var.revision_ro: 
        var.correctness = 2 
else:
        var.correctness = 0
print(var.user_input)
print(var.revision_lo)
print(var.revision_ro)
print(var.correctness)

This script works, but:
1. Participants always have to click into the text field before they can start writing. Is there a way to change this? Because of this my reaction times vary way to much
2. is there a way to restrict the input keys? I only want them to type letters like A P B. No numbers, or other stuff

Greetings,
Andreas

Comments

  • Hi Andreas,

    Participants always have to click into the text field before they can start writing. Is there a way to change this?

    Yes, you can specify a focus_widget in form.exec_(). So in your case that would be:

    form._exec(focus_widget=text_input)
    

    is there a way to restrict the input keys? I only want them to type letters like A P B. No numbers, or other stuff

    Not in OpenSesame 3.1 and earlier. But you can do this in OpenSesame 3.2, which is now in prerelease (but almost ready for stable release). So I would grab the latest 3.2.0 prerelease, and take a look at the new form-validation options:

    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

  • Sebastiaan! Thanks alot! This was way easier than I thought :) Maybe you can help me out with another issue:

    My experiment runs on two screens (sometimes the stuff shows up on the left screen, sometimes on the right). I set the experiment to 3840x1080p and I can define the coordinates for pictures etc. in the script tab. But I dont know how to do it for my python inline script (see above). It should appear 50% of the time on the left and 50% on the right screen. If this is too complicated.. It would be ok to duplicate it.. so the same text input shows on both screens, but you only need to fill out one (without mirroring the screen via windows)

    Cheers,
    Andreas

  • Ok I'm facing another problem with the filter ..
    Participants should be allowed to type only ABC as letters and if they make mistakes they can use "backspace" to delete the letter. If they are finished they should press "return" to confirm.

    If I set:

    def filter_letters(ch):
    
        """Allows only letters"""
    
        return ch in u'abc backspace return' 
    

    They can also type "r, s, n, etc." because this letters are included in "return" and "backspace"... Is there a way to fix this? :)

    Another point.. The Focus works great, but: The cursor always appears.. Is there a way to hide the mouse cursor?

    Sorry but I am totally new to python :(

    Greetings,
    Andreas

  • They can also type "r, s, n, etc." because this letters are included in "return" and "backspace"... Is there a way to fix this? :)

    You're providing a string, which is effectively a list of individual characters. The backspace and return keys are not individual characters, but rather multicharacter strings themselves. So you need to check against a list of keys, like so:

    def filter_letters(ch):
    
        return ch in ['a', 'b', 'c', 'backspace', 'return']
    

    Another point.. The Focus works great, but: The cursor always appears.. Is there a way to hide the mouse cursor?

    You can if you really want to, but this requires monkey-patching the internals of OpenSesame to override
    showing the cursor at all. So it's not something that I would recommend.

    Below you see how you can do this. But this disables the mouse cursor in general, not just for the form!

    def invisible_get_click(get_click):
    
        def inner(self, **resp_args):
    
            if 'visible' in resp_args:
                del resp_args['visible']
            return get_click(self, **resp_args)
    
        return inner
    
    
    # Get the backend-specific class of the Mouse object, and monkey-patch it by
    # replacing get_click() and show_cursor(). The former needs is decorated with a
    # function that strips the visible argument. The latter is just replaced by a
    # dummy function.
    mouse_class = Mouse().__class__
    mouse_class.get_click = invisible_get_click(mouse_class.get_click)
    mouse_class.show_cursor = lambda show: None
    

    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.