Howdy, Stranger!

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

Supported by

Slider widget in Expyriment

Hello,
I would like to build a slider widget to get ratings of images under Expyriment. The idea is to get a score from the subject regarding images on display for ~5sec. The participant has to press a button to slide left and another one to slide right in order to set the cursor in a specific position related to the value of their score. Would it be possible to get a demo snippet of code on how to build this under Expyriment?

Thank you very much in advance.
Best,
Ana Luísa

Comments

  • Hi anapinho,

    not a slider widget, but a similar solution that works with radio buttons:

    #!/bin/env python
    
    """ A radiobutton example in Expyriment."""
    
    __author__ = "Florian Krause <florian@expyriment.org>"
    
    
    from expyriment import control, stimuli, misc
    
    
    control.set_develop_mode(True)
    exp = control.initialize()
    exp.mouse.show_cursor()
    
    question = stimuli.TextScreen("The answer to life, the universe and everything?","")
    question.present()
    question.present() # Twice for double buffering!
    
    answers_pos = [["1", -300], ["2", -200], ["3", -100], ["42", 0], ["7", 100], ["99", 200], ["100", 300]]
    
    answer_canvas = stimuli.Canvas((700, 200))
    answers = []
    buttons = []
    for answer in answers_pos:
        a = stimuli.TextLine(answer[0], position=(answer[1], -30))
        a.plot(answer_canvas)
        b = stimuli.Rectangle((20, 20), line_width = 2, position=(answer[1], 0))
        b.ticked = False
        b.plot(answer_canvas)
        buttons.append(b)
    
    answer_canvas.present(clear=False)
    answer_canvas.present(clear=False)  # Twice for double buffering!
    
    tick = stimuli.Rectangle((10, 10))
    tick.preload()
    
    untick = stimuli.Rectangle((10, 10), colour=exp.background_colour)
    untick.preload()
    
    while True:
        exp.keyboard.check()  # Press ESC to exit
        if exp.mouse.check_button_pressed(0):
            exp.mouse.wait_press(0, wait_for_buttonup=True)
            pos = exp.mouse.position
            for button in buttons:
                if button.overlapping_with_position(pos, mode="surface"):
                    if button.ticked:
                        button.ticked = False
                        untick.position = button.position
                        untick.present(clear=False)
                        untick.present(clear=False)  # Twice for double buffering!
                    else:
                        button.ticked = True
                        tick.position = button.position
                        tick.present(clear=False)
                        tick.present(clear=False)  # Twice for double buffering!
    
    

    You could modify it to work with the keyboard instead of with the mouse.

    Hope this helps!

  • Thank you for this. In the end, I decided for a different solution but I will keep this for the future.

  • Hello anapinho,
    would you be so kind to tell how you did it? I'm facing a very similar problem than you did. Would be super helpful to get some idea :smile:

  • okay I've approached my problem for a willingness-to-pay task for a snack like this:

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    """
    Created on Wed May  9 17:20:15 2018
    
    @author: peterkraemer
    """
    
    from expyriment import control, stimuli
    
    #control.set_develop_mode(True)
    
    exp = control.initialize()
    ######################  STIMULI  ######################
    #   creating elements on screen
    
    # picture
    path_picture =   '/Users/peterkraemer/Desktop/experiment/PICTURES/snack1.bmp'
    picture      =   stimuli.Picture(path_picture, position=(0,200))
    
    # bar
    barLength = 300
    barThick = 10
    posBar=(0,-100)
    bar = stimuli.Rectangle((barLength,barThick),corner_rounding=None,position=posBar)
    bar.preload()
    barEndLeft = stimuli.Rectangle((5,barThick*3),position=((-(barLength+2)/2), posBar[1]))
    barEndLeft.preload()
    barEndRight = stimuli.Rectangle((5,barThick*3),position=(((barLength+2)/2), posBar[1]))
    barEndRight.preload()
    
    # slider
    posSlider = (0,posBar[1]) # initial position of the slider
    
    # sliding function
    def sliding(pos,commit):
        while commit==0:
            # create a composition to show multiple elements at the same time
            composition = stimuli.BlankScreen()
            picture.plot(composition)
            bar.plot(composition)
            barEndLeft.plot(composition)
            barEndRight.plot(composition)
            slider = stimuli.Rectangle((3,30),position=pos, colour = (194, 24, 7))
            slider.plot(composition)
            composition.present()
            # participants can use left and right arrow to adjust slider position & commit with enter
            key, rt = exp.keyboard.wait(process_control_events=True)
            if key == 13:
                commit = 1
                return pos[0]
            elif key == 275:
                pos = (pos[0]+10, pos[1])
                if pos[0] > barLength/2: # fixes upper end of the scale
                    pos = (barLength/2,pos[1])
            elif key == 276:
                pos = (pos[0]-10, pos[1])
                if pos[0] < -barLength/2: # fixes lower end of the scale
                    pos = (-barLength/2,pos[1])
    
    # position - money translation
    scaleMax = 5 # upper end of the scale
    moneyPerPixel=scaleMax/barLength # = CHF/Pixel
    
    ## start ##
    control.start(exp,skip_ready_screen=True)
    
    val = (sliding(posSlider,0)-(-barLength/2))*moneyPerPixel
    print(val)
    
    ## end ##
    control.end()
    

    certainly not the most elegant way but anywayne :#

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