Howdy, Stranger!

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

Supported by

[solved] Rating slider data logging

edited March 2014 in OpenSesame

Hi all,

I have modified a rating slider that was shared by Sebastiaan in another post. http://forum.cogsci.nl/index.php?p=/discussion/40/solved-implementing-a-slider/p1 . I want three sliders to appear on the same screen and I wish to collect responses one after the other. (Ideally, I would like to include accept and reset buttons as well). Although stimuli presentation is now modified to look just as I want, I am having trouble with response collection. Right now, all the three sliders are active and the program does not exit after 3 clicks. Here is the script http://pastebin.com/embed_js.php?i=UsmvUwYF

Any pointers and suggestions will be appreciated.

Thanks,
Asma

Comments

  • edited March 2014

    Hi Asma,

    If you want to have three sliders running sequentially, you will have to make sure they do not run at the same time. The script below should run through three sliders, storing their filling percentage one by one.

    # import everything we need
    from openexp.canvas import canvas
    from openexp.mouse import mouse
    
    # create the instances we need
    my_canvas = canvas(self.experiment)
    my_mouse = mouse(self.experiment, timeout=20)
    
    # slider dimensions
    slider_w = 500
    slider_h = 10
    slider_x = self.get("width")/2 - slider_w/2
    # three different y-coordinates, one for each slider
    slider_y = [self.get("height")/4, 2*self.get("height")/4, 3*self.get("height")/4]
    
    # variable names to store the slider fillings in
    names = ["slider_1", "slider_2", "slider_3"]
    
    # questions to put above the sliders
    questions = ["question 1", "question 2", "question 3"]
    
    # loop through all three slider positions, to draw the empty slider canvas
    for i in range(len(slider_y)):
        # draw some text (this can be anything)
        my_canvas.text(questions[i], y=slider_y[i]-100)
        # draw the slider frame
        my_canvas.rect(slider_x, slider_y[i], slider_w, slider_h)
    
    # add a text below the bottom slider, telling participants to click to accept
    my_canvas.text("Click to accept ...", y=slider_y[-1]+100) 
    
    # loop through all three sliders, waiting for input
    for i in range(len(slider_y)):
    
        # keep showing the interactive slider until a click has been made
        clicked = False
        while not clicked:
    
            # determine the slider fill based on the mouse position
            pos, time = my_mouse.get_pos()
            x, y = pos
            slider_fill = min(slider_w, max(0, x-slider_x))
    
            # draw an empty rect within the slider frame, effectively resetting it
            my_canvas.rect(slider_x+1, slider_y[i]+1, slider_w-2, slider_h-2, fill=True, color=self.get("background"))
            # draw the slider fill
            my_canvas.rect(slider_x+1, slider_y[i]+1, slider_fill-2, slider_h-2, fill=True)
            # show the updated canvas
            my_canvas.show()
    
            # Poll the mouse for buttonclicks
            button, position, timestamp = my_mouse.get_click(timeout = 20)
            if button != None:
                clicked = True
    
        # save the slider's filling
        slider_percent = 100.0*slider_fill/slider_w     
        self.experiment.set(names[i], slider_percent)
    

    Good luck!

  • edited 2:28PM

    Thanks so much Edwin! It works perfectly.

Sign In or Register to comment.