Show More
@@ -71,6 +71,10 b' class _SelectionWidget(DOMWidget):' | |||
|
71 | 71 | self.value_names = list(new.keys()) |
|
72 | 72 | finally: |
|
73 | 73 | self._in_values_changed = False |
|
74 | ||
|
75 | # ensure that the chosen value is one of the choices | |
|
76 | if self.value not in new.values(): | |
|
77 | self.value = next(iter(new.values())) | |
|
74 | 78 | |
|
75 | 79 | def _value_names_changed(self, name, old, new): |
|
76 | 80 | if not self._in_values_changed: |
@@ -80,13 +84,13 b' class _SelectionWidget(DOMWidget):' | |||
|
80 | 84 | """Called when value has been changed""" |
|
81 | 85 | if self.value_lock.acquire(False): |
|
82 | 86 | try: |
|
83 | # Make sure the value is one of the options | |
|
87 | # Reverse dictionary lookup for the value name | |
|
84 | 88 | for k,v in self.values.items(): |
|
85 | 89 | if new == v: |
|
86 | 90 | # set the selected value name |
|
87 | 91 | self.value_name = k |
|
88 | 92 | return |
|
89 |
raise |
|
|
93 | raise KeyError(new) | |
|
90 | 94 | finally: |
|
91 | 95 | self.value_lock.release() |
|
92 | 96 | |
@@ -94,10 +98,7 b' class _SelectionWidget(DOMWidget):' | |||
|
94 | 98 | """Called when the value name has been changed (typically by the frontend).""" |
|
95 | 99 | if self.value_lock.acquire(False): |
|
96 | 100 | try: |
|
97 |
|
|
|
98 | self.value = self.values[new] | |
|
99 | else: | |
|
100 | self.value = None | |
|
101 | self.value = self.values[new] | |
|
101 | 102 | finally: |
|
102 | 103 | self.value_lock.release() |
|
103 | 104 |
General Comments 0
You need to be logged in to leave comments.
Login now