Skip to content

Commit

Permalink
Fix a regression in jupyter-widgets#1513 with creating selection rang…
Browse files Browse the repository at this point in the history
…e sliders.

The following was broken:

from ipywidgets import SelectionRangeSlider
s=SelectionRangeSlider(options=[1])
  • Loading branch information
jasongrout committed Jul 18, 2017
1 parent 587b1b6 commit d1c018e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ipywidgets/widgets/widget_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _validate_options(self, proposal):

@observe('options')
def _propagate_options(self, change):
"Set the values and labels, and unselect any option if we aren't initializing"
"Set the values and labels, and select the first option if we aren't initializing"
options = self._options_full
self.set_trait('_options_labels', tuple(i[0] for i in options))
self._options_values = tuple(i[1] for i in options)
Expand Down Expand Up @@ -391,6 +391,15 @@ def _validate_options(self, proposal):
raise TraitError("Option list must be nonempty")
return proposal.value

@observe('options')
def _propagate_options(self, change):
"Select the first option"
options = self._options_full
self.set_trait('_options_labels', tuple(i[0] for i in options))
self._options_values = tuple(i[1] for i in options)
if self._initializing_traits_ is not True:
self.index = (0, 0)

@register
class SelectionSlider(_SelectionNonempty):
"""Slider to select a single item from a list or dictionary."""
Expand All @@ -415,13 +424,6 @@ class SelectionRangeSlider(_MultipleSelectionNonempty):
label = Tuple(help="Min and max selected labels")
index = Tuple((0,0), help="Min and max selected indices").tag(sync=True)

@observe('options')
def _propagate_options(self, change):
"Unselect any option"
if self._initializing_traits_ is not True:
self.index = (0, 0)
self.set_trait('_options_labels', tuple(i[0] for i in change.new))
self._options_values = tuple(i[1] for i in change.new)

@validate('index')
def _validate_index(self, proposal):
Expand Down

0 comments on commit d1c018e

Please sign in to comment.