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