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