##// END OF EJS Templates
forcing value to be in values
Sylvain Corlay -
Show More
@@ -50,7 +50,7 b' class _Selection(DOMWidget):'
50 50 disabled = Bool(False, help="Enable or disable user changes", sync=True)
51 51 description = Unicode(help="Description of the value this widget represents", sync=True)
52 52
53
53
54 54 def __init__(self, *args, **kwargs):
55 55 self.value_lock = Lock()
56 56 self._in_values_changed = False
@@ -65,6 +65,7 b' class _Selection(DOMWidget):'
65 65 # the setting of self.values right now, before anything else runs
66 66 self.values = kwargs.pop('values')
67 67 DOMWidget.__init__(self, *args, **kwargs)
68 self._value_in_values()
68 69
69 70 def _values_changed(self, name, old, new):
70 71 """Handles when the values dict has been changed.
@@ -76,10 +77,13 b' class _Selection(DOMWidget):'
76 77 self.value_names = list(new.keys())
77 78 finally:
78 79 self._in_values_changed = False
79
80 self._value_in_values()
81
82 def _value_in_values(self):
80 83 # ensure that the chosen value is one of the choices
81 if self.value not in new.values():
82 self.value = next(iter(new.values()))
84 if self.values:
85 if self.value not in self.values.values():
86 self.value = next(iter(self.values.values()))
83 87
84 88 def _value_names_changed(self, name, old, new):
85 89 if not self._in_values_changed:
General Comments 0
You need to be logged in to leave comments. Login now