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