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:37AM

    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:37AM

    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:37AM

    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:37AM

    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.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games