Is it possible to make a slider object only interactable by dragging the marker?

Originally, a slider can be rated by clicking any tick on it with its marker moved to corresponding position. Is it possible to make a slider only interactable by dragging the marker and prevent it from being rated by clicking the ticks?

Hi @Spenserark_Bottest, you can, it just means overwriting the click handling method of the slider. The following will work for a slider named “slider”. Add a code component and use the following in relevant tabs

# Begin Experiment
def dragOnly():
    click = bool(slider.mouse.getPressed()[0])
    xy = slider.mouse.getPos()

    if click:
        # Update current but don't set Rating (mouse is still down)
        # Dragging has to start inside a "valid" area (i.e., on the
        # slider), but may continue even if the mouse moves away from
        # the slider, as long as the mouse button is not released.
        if (slider.validArea.contains(slider.mouse, units=slider.units) and slider.markerPos is None):
            slider.markerPos = slider._posToRating(xy)  # updates marker
            slider._dragging = True
        elif (slider.marker.contains(slider.mouse, units=slider.units) or
                slider._dragging):
            slider.markerPos = slider._posToRating(xy)  # updates marker
            slider._dragging = True
    else:  # mouse is up - check if it *just* came up
        if slider._dragging:
            slider._dragging = False
            if slider.markerPos is not None:
                slider.recordRating(slider.markerPos)
            return slider.markerPos
        else:
            # is up and was already up - move along
            return None

    slider._mouseStateXY = xy

# Override slider method
slider.getMouseResponses = dragOnly
1 Like

Thank you for your help!

Hi,

Is it possible to move the marker CONTINUOUSLY simply by moving the mouse (without clicking and dragging), OR press and hold keys, and record the continuous ratings?

Thanks,
Mengsi

1 Like

Hi! Thank you so much for your method. It worked well. I am wondering if there is a way to pass an argument to modify different sliders? For example: slider_new.getMouseResponses = dragOnly(slider_new). I tried but it gave me an error of “self.getMouseResponses()
TypeError: ‘NoneType’ object is not callable”

Thank you very much!

Hi @lingwei, is that the code you used to overwrite the method? If so, it would not work as you assigned the return value of the dragOnly function to the method because you called the function when you assigned it. Try the following instead

slider_new.getMouseResponses = dragOnly 

However, with this approach you will have to change the name of the slider in the function to slider_new