Howdy, Stranger!

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

Supported by

Building a slider with latest version of OpenSesame

edited April 2016 in OpenSesame

Hi,
I know that there have been a lot of questions about this but I still haven't been able to find a solution that works the best with my program. I am trying to create a program where users can use a slider or a rating scale to show how much they agree with a statement. All of the sliders that I have tried to use have not shown up on my screen correctly (they always shown up on the bottom right side of my screen instead of the center). I've followed all of the steps of moving the slider files into the 'plug-in' folder of OpenSesame and moving some other files into the 'multiple-choice' folder but I'm still having these issues. I was wondering if this is an issue with the fact that the sliders are from 2011/2012 or if there is another issue happening.

Thanks!

Comments

  • edited 10:23PM

    Hi,

    In OpenSesame 2.9 and before, coordinates were relative to the top-left of the display in inline script, and relative to the display center in sketchpad items. This was clearly inconsistent, so in OpenSesame 3.0, coordinates are by default relative to the display center in all cases.

    So this is why the slider appears at the bottom right--it assumes that 0,0 is the top-left. To fix this, you can either:

    • Change the code so that it assumes display-center as 0,0; or
    • Disable the 'Uniform coordinates' option in the General-properties tab (to revert back to the old behavior).

    Does that help? If want a more specific answer, you'll need to provide some more concrete information about what approach you're trying exactly.

    Cheers,
    Sebastiaan

  • edited April 2016

    Thanks for your response,

    I'm still a little confused, because I can't seem to find a part of the code that says 'display-center' and i cant find a general-properties tab in the version of OpenSesame that I'm using.

    If I were to use this inline code for a slider that I you posted on an earlier forum post, what would I change to center the slider?

    from openexp.canvas import canvas
    from openexp.mouse import mouse
    my_canvas = canvas(self.experiment)
    my_mouse = mouse(self.experiment, timeout=20)
    
    # Set slider dimensions
    slider_w = 500
    slider_h = 10
    slider_x = self.get("width")/2-slider_w/2
    slider_y = self.get("height")/2-slider_h/2
    
    while True:
    
        # 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))
    
        my_canvas.clear()
        # Draw some text (this can be anything)
        my_canvas.text("Question goes here", y=slider_y-100) 
        my_canvas.text("Click to accept ...", y=slider_y+100) 
        # Draw the slider frame
        my_canvas.rect(slider_x, slider_y, slider_w, slider_h)
        # Draw the slider fill
        my_canvas.rect(slider_x, slider_y, slider_fill, slider_h, fill=True)                
        # Draw the mouse cursor
        my_canvas.arrow(x+5, y+10, x, y)
        my_canvas.show()
    
        # Poll the mouse for buttonclicks
        button, position, timestamp = my_mouse.get_click(timeout = 20)
        if button != None:
            break
    
    slider_percent = 100.0*slider_fill/slider_w     
    self.experiment.set("slider_percent", slider_percent)
    
  • edited 10:23PM

    Sorry that didn't show up as expected (I'm clearly not used to using this at all), this is what I meant: http://img.cogsci.nl/?q=570c59d642639

  • edited 10:23PM

    i cant find a general-properties tab in the version of OpenSesame that I'm using.

    It's the tab that you see when you click on the top-level item in the overview area, where you can change the name, resolution, etc.

    I can't seem to find a part of the code that says 'display-center.

    It's this part:

    slider_x = self.get("width")/2-slider_w/2
    slider_y = self.get("height")/2-slider_h/2
    

    It determines the position of the slider relative to the width/2 and height/2, that is, relative to the center (when 0,0 is the top-left.)

    The following is a slight update of the script above. This will work on OpenSesame >= 3, and assumes that Uniform coordinates is enabled (it is by default for new experiments).

    my_canvas = canvas()
    my_mouse = mouse(timeout=20)
    
    # Set slider dimensions. This assumes that 0,0 is the display center, which is
    # the default in OpenSesame >= 3.
    slider_w = 500
    slider_h = 10
    slider_x = -slider_w/2
    slider_y = -slider_h/2
    
    while True:
    
        # 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))
    
        my_canvas.clear()
        # Draw some text (this can be anything)
        my_canvas.text("Question goes here", y=slider_y-100) 
        my_canvas.text("Click to accept ...", y=slider_y+100) 
        # Draw the slider frame
        my_canvas.rect(slider_x, slider_y, slider_w, slider_h)
        # Draw the slider fill
        my_canvas.rect(slider_x, slider_y, slider_fill, slider_h, fill=True)                
        # Draw the mouse cursor
        my_canvas.arrow(x+5, y+10, x, y)
        my_canvas.show()
    
        # Poll the mouse for buttonclicks
        button, position, timestamp = my_mouse.get_click()
        if button is not None:
            break
    
    # Set the slider response as an experimental variable
    var.slider_percent = 100.0*slider_fill/slider_w     
    

    Cheers!
    Sebastiaan

  • edited 10:23PM

    Thank you!!

  • Hi Guys,

    I have a similar question but couldn't directly figure out what to do exactly.
    So basically this is my code (i didn't set up a custom form but I just used a sketchpad)

    So basically: "draw textline center=1 color=black font_bold=no font_family=mono font_italic=no font_size=24 html=yes show_if=always text="1 2 3 4 5 6 7" x=564 y=0 z_index=0"

    Is where I set a 1-7 scale. Then people can use the keyboard to answer by pressing whatever number from 1-7.
    I now want to change this to a 0-100 slider where people can use a mouse to give the input.

    I feel like this should be relatively straightforward but it's not obvious to me how to fix it. My python is very limited haha so I googled around and arrived at this point

  • Hi @sebastiaan thanks :) !
    I checked with a colleague and basically found out which is also clear from your post that you need to do some real python coding to make it work rather than to have a sneaky way to do it quickly in sketchpad.
    Though I really like your solution where you can basically code the slider first and then integrate it into the sketchpad :) So thanks a lot!

Sign In or Register to comment.