54
54
The options for the dropdown. This can either be a list of values, e.g.
55
55
``['Galileo', 'Brahe', 'Hubble']`` or ``[0, 1, 2]``, a list of
56
56
(label, value) pairs, e.g.
57
- ``[('Galileo', 0), ('Brahe', 1), ('Hubble', 2)]``,
58
- or a dictionary mapping the labels to the values, e.g. ``{'Galileo': 0,
59
- 'Brahe': 1, 'Hubble': 2}``. The labels are the strings that will be
60
- displayed in the UI, representing the actual Python choices, and should
61
- be unique. If this is a dictionary, the order in which they are
62
- displayed is not guaranteed.
57
+ ``[('Galileo', 0), ('Brahe', 1), ('Hubble', 2)]``.
58
+ The labels are the strings that will be displayed in the UI,
59
+ representing the actual Python choices, and should be unique.
60
+ If this is a dictionary, the order in which they are displayed is
61
+ not guaranteed.
63
62
64
63
index: iterable of int
65
64
The indices of the options that are selected.
@@ -106,6 +105,9 @@ def _make_options(x):
106
105
* an iterable of (label, value) pairs
107
106
* an iterable of values, and labels will be generated
108
107
"""
108
+ if isinstance (x , Mapping ):
109
+ raise TypeError ("options must be a list of values or a list of (label, value) tuples" )
110
+
109
111
# only iterate once through the options.
110
112
xlist = tuple (x )
111
113
@@ -126,7 +128,7 @@ def findvalue(array, value, compare = lambda x, y: x == y):
126
128
class _Selection (DescriptionWidget , ValueWidget , CoreWidget ):
127
129
"""Base class for Selection widgets
128
130
129
- ``options`` can be specified as a list of values or list of (label, value)
131
+ ``options`` can be specified as a list of values or a list of (label, value)
130
132
tuples. The labels are the strings that will be displayed in the UI,
131
133
representing the actual Python choices, and should be unique.
132
134
If labels are not specified, they are generated from the values.
@@ -177,7 +179,9 @@ def __init__(self, *args, **kwargs):
177
179
178
180
@validate ('options' )
179
181
def _validate_options (self , proposal ):
180
- proposal .value = tuple (proposal .value )
182
+ # if an iterator is provided, exhaust it
183
+ if isinstance (proposal .value , Iterable ) and not isinstance (proposal .value , Mapping ):
184
+ proposal .value = tuple (proposal .value )
181
185
# throws an error if there is a problem converting to full form
182
186
self ._options_full = _make_options (proposal .value )
183
187
return proposal .value
@@ -283,7 +287,7 @@ class _MultipleSelection(DescriptionWidget, ValueWidget, CoreWidget):
283
287
index = TypedTuple (trait = Int (), help = "Selected indices" ).tag (sync = True )
284
288
285
289
options = Any ((),
286
- help = """Iterable of values, (label, value) pairs, or a mapping of {label: value} pairs that the user can select.
290
+ help = """Iterable of values or (label, value) pairs that the user can select.
287
291
288
292
The labels are the strings that will be displayed in the UI, representing the
289
293
actual Python choices, and should be unique.
0 commit comments