Show More
@@ -55,6 +55,7 b' class _Selection(DOMWidget):' | |||||
55 | def __init__(self, *args, **kwargs): |
|
55 | def __init__(self, *args, **kwargs): | |
56 | self.value_lock = Lock() |
|
56 | self.value_lock = Lock() | |
57 | self.options_lock = Lock() |
|
57 | self.options_lock = Lock() | |
|
58 | self.equals = kwargs.pop('equals', lambda x, y: x == y) | |||
58 | self.on_trait_change(self._options_readonly_changed, ['_options_dict', '_options_labels', '_options_values', '_options']) |
|
59 | self.on_trait_change(self._options_readonly_changed, ['_options_dict', '_options_labels', '_options_values', '_options']) | |
59 | if 'options' in kwargs: |
|
60 | if 'options' in kwargs: | |
60 | self.options = kwargs.pop('options') |
|
61 | self.options = kwargs.pop('options') | |
@@ -105,13 +106,14 b' class _Selection(DOMWidget):' | |||||
105 | def _options_readonly_changed(self, name, old, new): |
|
106 | def _options_readonly_changed(self, name, old, new): | |
106 | if not self.options_lock.locked(): |
|
107 | if not self.options_lock.locked(): | |
107 | raise TraitError("`.%s` is a read-only trait. Use the `.options` tuple instead." % name) |
|
108 | raise TraitError("`.%s` is a read-only trait. Use the `.options` tuple instead." % name) | |
|
109 | ||||
108 | def _value_changed(self, name, old, new): |
|
110 | def _value_changed(self, name, old, new): | |
109 | """Called when value has been changed""" |
|
111 | """Called when value has been changed""" | |
110 | if self.value_lock.acquire(False): |
|
112 | if self.value_lock.acquire(False): | |
111 | try: |
|
113 | try: | |
112 | # Reverse dictionary lookup for the value name |
|
114 | # Reverse dictionary lookup for the value name | |
113 | for k, v in self._options_dict.items(): |
|
115 | for k, v in self._options_dict.items(): | |
114 |
if new |
|
116 | if self.equals(new, v): | |
115 | # set the selected value name |
|
117 | # set the selected value name | |
116 | self.selected_label = k |
|
118 | self.selected_label = k | |
117 | return |
|
119 | return |
General Comments 0
You need to be logged in to leave comments.
Login now