Skip to content

Commit c7bd329

Browse files
authored
Merge pull request #2834 from ibdafna/drag_behaviour
Add dragging behaviour properties to sliders
2 parents 986a038 + 3aae838 commit c7bd329

File tree

9 files changed

+53
-6
lines changed

9 files changed

+53
-6
lines changed

docs/source/examples/Output Widget.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"\n",
351351
"This always prints in the currently active cell, not the cell that started the background thread.\n",
352352
"\n",
353-
"This can lead to surprising behaviour in output widgets. During the time in which output is captured by the output widget, *any* output generated in the notebook, regardless of thread, will go into the output widget.\n",
353+
"This can lead to surprising behavior in output widgets. During the time in which output is captured by the output widget, *any* output generated in the notebook, regardless of thread, will go into the output widget.\n",
354354
"\n",
355355
"The best way to avoid surprises is to *never* use an output widget's context manager in a context where multiple threads generate output. Instead, we can pass an output widget to the function executing in a thread, and use `append_display_data()`, `append_stdout()`, or `append_stderr()` methods to append displayable output to the output widget."
356356
]

docs/source/examples/Widget Styling.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
"\n",
337337
"#### align-items\n",
338338
"\n",
339-
"`align-items` can be one of `flex-start`, `flex-end`, `center`, `baseline`, `stretch`. This defines the default behaviour for how flex items are laid out along the cross axis on the current line. Think of it as the justify-content version for the cross-axis (perpendicular to the main-axis).\n",
339+
"`align-items` can be one of `flex-start`, `flex-end`, `center`, `baseline`, `stretch`. This defines the default behavior for how flex items are laid out along the cross axis on the current line. Think of it as the justify-content version for the cross-axis (perpendicular to the main-axis).\n",
340340
" ![Items](./images/align-items.svg)\n",
341341
" \n",
342342
"#### align-content\n",

ipywidgets/widgets/widget_float.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class FloatSlider(_BoundedFloat):
159159
default is 'horizontal', orientation of the slider
160160
readout : {True, False}
161161
default is True, display the current value of the slider next to it
162+
behavior : str
163+
slider handle and connector dragging behavior. Default is 'drag-tap'.
162164
readout_format : str
163165
default is '.2f', specifier for the format function used to represent
164166
slider value for human consumption, modeled after Python 3's format
@@ -174,8 +176,9 @@ class FloatSlider(_BoundedFloat):
174176
'.2f', help="Format for the readout").tag(sync=True)
175177
continuous_update = Bool(True, help="Update the value of the widget as the user is holding the slider.").tag(sync=True)
176178
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True)
177-
178179
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization)
180+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
181+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)
179182

180183

181184
@register
@@ -200,6 +203,8 @@ class FloatLogSlider(_BoundedLogFloat):
200203
default is 'horizontal', orientation of the slider
201204
readout : {True, False}
202205
default is True, display the current value of the slider next to it
206+
behavior : str
207+
slider handle and connector dragging behavior. Default is 'drag-tap'.
203208
readout_format : str
204209
default is '.3g', specifier for the format function used to represent
205210
slider value for human consumption, modeled after Python 3's format
@@ -216,8 +221,9 @@ class FloatLogSlider(_BoundedLogFloat):
216221
continuous_update = Bool(True, help="Update the value of the widget as the user is holding the slider.").tag(sync=True)
217222
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True)
218223
base = CFloat(10., help="Base for the logarithm").tag(sync=True)
219-
220224
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization)
225+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
226+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)
221227

222228

223229
@register
@@ -343,6 +349,8 @@ class FloatRangeSlider(_BoundedFloatRange):
343349
default is 'horizontal'
344350
readout : {True, False}
345351
default is True, display the current value of the slider next to it
352+
behavior : str
353+
slider handle and connector dragging behavior. Default is 'drag-tap'.
346354
readout_format : str
347355
default is '.2f', specifier for the format function used to represent
348356
slider value for human consumption, modeled after Python 3's format
@@ -358,5 +366,6 @@ class FloatRangeSlider(_BoundedFloatRange):
358366
'.2f', help="Format for the readout").tag(sync=True)
359367
continuous_update = Bool(True, help="Update the value of the widget as the user is sliding the slider.").tag(sync=True)
360368
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True)
361-
362369
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization)
370+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
371+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)

ipywidgets/widgets/widget_int.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
The upper limit for the value.
3535
step: integer
3636
The step between allowed values.
37+
behavior : str
38+
slider handle and connector dragging behavior. Default is 'drag-tap'.
3739
"""
3840

3941
def _int_doc(cls):
@@ -165,8 +167,9 @@ class IntSlider(_BoundedInt):
165167
'd', help="Format for the readout").tag(sync=True)
166168
continuous_update = Bool(True, help="Update the value of the widget as the user is holding the slider.").tag(sync=True)
167169
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True)
168-
169170
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization)
171+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
172+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)
170173

171174

172175
@register
@@ -289,6 +292,20 @@ class IntRangeSlider(_BoundedIntRange):
289292
The lowest allowed value for `lower`
290293
max : int
291294
The highest allowed value for `upper`
295+
step : int
296+
step of the trackbar
297+
description : str
298+
name of the slider
299+
orientation : {'horizontal', 'vertical'}
300+
default is 'horizontal'
301+
readout : {True, False}
302+
default is True, display the current value of the slider next to it
303+
behavior : str
304+
slider handle and connector dragging behavior. Default is 'drag-tap'.
305+
readout_format : str
306+
default is '.2f', specifier for the format function used to represent
307+
slider value for human consumption, modeled after Python 3's format
308+
specification mini-language (PEP 3101).
292309
"""
293310
_view_name = Unicode('IntRangeSliderView').tag(sync=True)
294311
_model_name = Unicode('IntRangeSliderModel').tag(sync=True)
@@ -301,3 +318,5 @@ class IntRangeSlider(_BoundedIntRange):
301318
continuous_update = Bool(True, help="Update the value of the widget as the user is sliding the slider.").tag(sync=True)
302319
style = InstanceDict(SliderStyle, help="Slider style customizations.").tag(sync=True, **widget_serialization)
303320
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True)
321+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
322+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)

ipywidgets/widgets/widget_selection.py

+4
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ class SelectionSlider(_SelectionNonempty):
573573
help="Display the current selected label next to the slider").tag(sync=True)
574574
continuous_update = Bool(True,
575575
help="Update the value of the widget as the user is holding the slider.").tag(sync=True)
576+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
577+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)
576578

577579
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization)
578580

@@ -627,3 +629,5 @@ def _validate_index(self, proposal):
627629
help="Update the value of the widget as the user is holding the slider.").tag(sync=True)
628630

629631
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization)
632+
behavior = CaselessStrEnum(values=['drag-tap', 'drag-snap', 'tap', 'drag', 'snap'],
633+
default_value='drag-tap', help="Slider dragging behavior.").tag(sync=True)

packages/controls/src/widget_float.ts

+3
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ export class FloatLogSliderView extends BaseIntSliderView {
147147

148148
createSlider(): void {
149149
const orientation = this.model.get('orientation');
150+
const behavior = this.model.get('behavior');
151+
150152
noUiSlider.create(this.$slider, {
151153
start: this.logCalc(this.model.get('value')),
154+
behaviour: behavior,
152155
range: {
153156
min: this.model.get('min'),
154157
max: this.model.get('max'),

packages/controls/src/widget_int.ts

+3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,12 @@ export abstract class BaseIntSliderView extends DescriptionView {
203203
*/
204204
createSlider(): void {
205205
const orientation = this.model.get('orientation');
206+
const behavior = this.model.get('behavior');
207+
206208
noUiSlider.create(this.$slider, {
207209
start: this.model.get('value'),
208210
connect: true,
211+
behaviour: behavior,
209212
range: {
210213
min: this.model.get('min'),
211214
max: this.model.get('max'),

packages/controls/src/widget_selection.ts

+2
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,12 @@ export class SelectionSliderView extends DescriptionView {
746746
const min = 0;
747747
const max = labels.length - 1;
748748
const orientation = this.model.get('orientation');
749+
const behavior = this.model.get('behavior');
749750

750751
noUiSlider.create(this.$slider, {
751752
start: this.model.get('index'),
752753
connect: true,
754+
behaviour: behavior,
753755
range: {
754756
min: min,
755757
max: max,

packages/schema/jupyterwidgetmodels.latest.md

+7
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ Attribute | Type | Default | Help
509509
`_view_module_version` | string | `'2.0.0'` |
510510
`_view_name` | string | `'FloatLogSliderView'` |
511511
`base` | number (float) | `10.0` | Base for the logarithm
512+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
512513
`continuous_update` | boolean | `true` | Update the value of the widget as the user is holding the slider.
513514
`description` | string | `''` | Description of the control.
514515
`description_allow_html` | boolean | `false` | Accept HTML in the description.
@@ -559,6 +560,7 @@ Attribute | Type | Default | Help
559560
`_view_module` | string | `'@jupyter-widgets/controls'` |
560561
`_view_module_version` | string | `'2.0.0'` |
561562
`_view_name` | string | `'FloatRangeSliderView'` |
563+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
562564
`continuous_update` | boolean | `true` | Update the value of the widget as the user is sliding the slider.
563565
`description` | string | `''` | Description of the control.
564566
`description_allow_html` | boolean | `false` | Accept HTML in the description.
@@ -586,6 +588,7 @@ Attribute | Type | Default | Help
586588
`_view_module` | string | `'@jupyter-widgets/controls'` |
587589
`_view_module_version` | string | `'2.0.0'` |
588590
`_view_name` | string | `'FloatSliderView'` |
591+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
589592
`continuous_update` | boolean | `true` | Update the value of the widget as the user is holding the slider.
590593
`description` | string | `''` | Description of the control.
591594
`description_allow_html` | boolean | `false` | Accept HTML in the description.
@@ -807,6 +810,7 @@ Attribute | Type | Default | Help
807810
`_view_module` | string | `'@jupyter-widgets/controls'` |
808811
`_view_module_version` | string | `'2.0.0'` |
809812
`_view_name` | string | `'IntRangeSliderView'` |
813+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
810814
`continuous_update` | boolean | `true` | Update the value of the widget as the user is sliding the slider.
811815
`description` | string | `''` | Description of the control.
812816
`description_allow_html` | boolean | `false` | Accept HTML in the description.
@@ -834,6 +838,7 @@ Attribute | Type | Default | Help
834838
`_view_module` | string | `'@jupyter-widgets/controls'` |
835839
`_view_module_version` | string | `'2.0.0'` |
836840
`_view_name` | string | `'IntSliderView'` |
841+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
837842
`continuous_update` | boolean | `true` | Update the value of the widget as the user is holding the slider.
838843
`description` | string | `''` | Description of the control.
839844
`description_allow_html` | boolean | `false` | Accept HTML in the description.
@@ -1112,6 +1117,7 @@ Attribute | Type | Default | Help
11121117
`_view_module` | string | `'@jupyter-widgets/controls'` |
11131118
`_view_module_version` | string | `'2.0.0'` |
11141119
`_view_name` | string | `'SelectionRangeSliderView'` |
1120+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
11151121
`continuous_update` | boolean | `true` | Update the value of the widget as the user is holding the slider.
11161122
`description` | string | `''` | Description of the control.
11171123
`description_allow_html` | boolean | `false` | Accept HTML in the description.
@@ -1136,6 +1142,7 @@ Attribute | Type | Default | Help
11361142
`_view_module` | string | `'@jupyter-widgets/controls'` |
11371143
`_view_module_version` | string | `'2.0.0'` |
11381144
`_view_name` | string | `'SelectionSliderView'` |
1145+
`behavior` | string (one of `'drag-tap'`, `'drag-snap'`, `'tap'`, `'drag'`, `'snap'`) | `'drag-tap'` | Slider dragging behavior.
11391146
`continuous_update` | boolean | `true` | Update the value of the widget as the user is holding the slider.
11401147
`description` | string | `''` | Description of the control.
11411148
`description_allow_html` | boolean | `false` | Accept HTML in the description.

0 commit comments

Comments
 (0)