Show More
@@ -40,7 +40,7 class _SelectionWidget(DOMWidget): | |||
|
40 | 40 | The keys of this dictionary are also available as value_names. |
|
41 | 41 | """) |
|
42 | 42 | value_name = Unicode(help="The name of the selected value", sync=True) |
|
43 |
value_names = List(Unicode, help=""" |
|
|
43 | value_names = List(Unicode, help="""Read-only list of names for each value. | |
|
44 | 44 | |
|
45 | 45 | If values is specified as a list, this is the string representation of each element. |
|
46 | 46 | Otherwise, it is the keys of the values dictionary. |
@@ -52,6 +52,7 class _SelectionWidget(DOMWidget): | |||
|
52 | 52 | |
|
53 | 53 | def __init__(self, *args, **kwargs): |
|
54 | 54 | self.value_lock = Lock() |
|
55 | self._in_values_changed = False | |
|
55 | 56 | if 'values' in kwargs: |
|
56 | 57 | values = kwargs['values'] |
|
57 | 58 | # convert list values to an dict of {str(v):v} |
@@ -65,11 +66,15 class _SelectionWidget(DOMWidget): | |||
|
65 | 66 | |
|
66 | 67 | Setting values implies setting value names from the keys of the dict. |
|
67 | 68 | """ |
|
68 |
self. |
|
|
69 | self._in_values_changed = True | |
|
70 | try: | |
|
71 | self.value_names = list(new.keys()) | |
|
72 | finally: | |
|
73 | self._in_values_changed = False | |
|
69 | 74 | |
|
70 | 75 | def _value_names_changed(self, name, old, new): |
|
71 |
if |
|
|
72 | raise TraitError("Expected %i value names, got %i." % (len(self.values), len(new))) | |
|
76 | if not self._in_values_changed: | |
|
77 | raise TraitError("value_names is a read-only proxy to values.keys(). Use the values dict instead.") | |
|
73 | 78 | |
|
74 | 79 | def _value_changed(self, name, old, new): |
|
75 | 80 | """Called when value has been changed""" |
General Comments 0
You need to be logged in to leave comments.
Login now