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