Slider class¶
A slider is used to set a value on a given scale: you use the mouse to drag a gauge along a given line (or any other stimulus on your choice). The gauge’s physical coordinate is translated to a value on a customizable linear scale.
Main features:
- Vertical / horizontal slider.
- Get the slider value using a numeric scale of your choice.
- Track the number of times the gauge was moved since the trial started.
- Limit the gauge movement (how far it can move, how many times it can move).
- Configurable background stimulus (e.g. a line) and gauge stimulus
Using this class:¶
To configure the slider:
- Create the slider and set the background stimulus (
bgnd_stimulus
) and the gauge stimulus (gauge_stimulus
) - Choose the slider’s
orientation
: vertical or horizontal - Customize the slider scale by setting
min_value
andmax_value
- (Optional) Choose the slider’s
default_value
(the gauge will reset to this value wheneverreset()
is called) - (Optional) Limit the area where finger touches will move the gauge (
set_clickable_area()
,set_drag_area()
) - (Optional) set
slidable_range
to define how far the gauge can move - (Optional) set
max_moves
to limit the number of times the gauge can move. If this number is exceeded, the slider will becomelocked
. - Add
Slider.stimulus
to aStimulusContainer
(or present() it directly)
To use it (e.g., during a trial):
- Set the slider
visible
- Call
reset()
when the trial starts - Call
update()
to inform the slider whether the mouse is clicked or not and about its position. - Obtain the slider value via
current_value
- Check how many times it was moved via
n_moves
Methods and properties:¶
-
class
trajtracker.stimuli.
Slider
(bgnd_stimulus, gauge_stimulus, orientation=<Orientation.Horizontal: 1>, min_value=0, max_value=100, default_value=None, max_moves=None, visible=False, slidable_range=None, position=None)¶ -
__init__
(bgnd_stimulus, gauge_stimulus, orientation=<Orientation.Horizontal: 1>, min_value=0, max_value=100, default_value=None, max_moves=None, visible=False, slidable_range=None, position=None)¶ Constructor
Parameters: - bgnd_stimulus – See
bgnd_stimulus
- gauge_stimulus – See
gauge_stimulus
- orientation – See
orientation
- min_value – See
min_value
- max_value – See
max_value
- default_value – See
default_value
- max_moves – See
max_moves
- visible – See
visible
- slidable_range – See
slidable_range
- position – See
position
- bgnd_stimulus – See
-
bgnd_stimulus
¶ The stimulus serving as the background for this slider.
-
clickable_area
¶ The area that can be clicked in order to start moving the gauge.
-
current_value
¶ The slider’s current value, in numeric units.
Setting this property will move the gauge accordingly. Also, the value will be trimmed to the valid range, setting to None will hide the gauge, and setting to non-None will show it.
-
default_value
¶ The slider’s default value. This determines the initial position of the gauge after
reset()
is called.If set to None, the gauge will only appear once the slider is touched.
Values exceeding
min_value
ormax_value
are cropped.Type: Number
-
drag_area
¶ The area in which the mouse can move to continue moving the gauge.
If the mouse exits this area, it’s considered as if it was unclicked (i.e. the gauge will stop at its present position).
-
gauge_stimulus
¶ The stimulus serving as the gauge that actually slides.
-
locked
¶ Whether the gauge can now move feely (locked = False) or not (locked = True)
-
log_level
¶ Logging level of this object: trajtracker.log_none, log_error (default), log_warn, log_info, log_debug, log_trace
-
max_moves
¶ The maximal number of times the gauge can move after
reset()
was called.If this number is exceeded, the slider is
locked
Value = None means no restriction.
Type: int
-
max_value
¶ The value at the slider’s right/top end
If min_value > max_value, the slider is reversed (i.e., the smaller value is at the right or top)
Type: Number
-
min_value
¶ The value at the slider’s left/bottom end
If min_value > max_value, the slider is reversed (i.e., the smaller value is at the right or top)
Type: Number
-
orientation
¶ The slider’s orientation (horizontal or vertical).
Changing the orientation will not cause
bgnd_stimulus
orgauge_stimulus
to be rotated; it only affects the direction where the gauge can be moved.Type: trajtracker.stimuli.Orientation
-
position
¶ The slider’s position, which is the position of
bgnd_stimulus
Type: tuple (x, y)
-
reset
()¶ Reset the slider (when a new trial starts).
The slider will be reset to its default value. If it was locked, it will be unlocked.
-
set_clickable_area
(area, relative_position=False)¶ Set
clickable_area
: the area that can be clicked in order to start moving the gauge.Parameters: - area – A stimulus. None = use default area (=
bgnd_stimulus
) - relative_position – The area’s position, relative to
bgnd_stimulus
. If this parameter is None, area.position will be used as absolute screen coordinates.
- area – A stimulus. None = use default area (=
-
set_drag_area
(area, relative_position=False)¶ Set
drag_area
: the area in which the mouse can move to continue moving the gauge.Parameters: - area – A stimulus. None = remove this restriction, finger/mouse can move anywhere to continue dragging the gauge.
- relative_position – The area’s position, relative to
bgnd_stimulus
. If this parameter is None, area.position will be used as absolute screen coordinates.
-
size
¶ Get the slider’s size, which is the size of
bgnd_stimulus
Type: tuple (width, height)
-
slidable_range
¶ The range on which the gauge can slide (in the relevant direction according to
orientation
). Specified in pixels, relatively to the stimulus position.None means that the range is determined by the size of
bgnd_stimulus
Type: tuple with two integers (min, max)
-
stimulus
¶ The slider object (background + gauge)
-
update
(clicked, xy)¶ Update the slider according to mouse movement
Note: Unlike other stimulus objects in TrajTracker, here you should call the update() function also when the mouse is unclicked.
Parameters: - clicked – Whether the mouse is presently clicked or not
- xy – The coordinate to which the gauge is being dragged (x, y). This parameter is ignored in some situations, e.g., when clicked=False, when slider is locked, etc.
-
visible
¶ Whether the slider is now visible or not.
Note that even if the slider is visible, the gauge may sometimes be hidden.
-