Show More
@@ -60,7 +60,7 b' define([' | |||
|
60 | 60 | this.$droplabel.text(selected_item_text); |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | var items = this.model.get('value_names'); | |
|
63 | var items = this.model.get('_value_names'); | |
|
64 | 64 | var $replace_droplist = $('<ul />') |
|
65 | 65 | .addClass('dropdown-menu'); |
|
66 | 66 | // Copy the style |
@@ -170,7 +170,7 b' define([' | |||
|
170 | 170 | // changed by another view or by a state update from the back-end. |
|
171 | 171 | if (options === undefined || options.updated_view != this) { |
|
172 | 172 | // Add missing items to the DOM. |
|
173 | var items = this.model.get('value_names'); | |
|
173 | var items = this.model.get('_value_names'); | |
|
174 | 174 | var disabled = this.model.get('disabled'); |
|
175 | 175 | var that = this; |
|
176 | 176 | _.each(items, function(item, index) { |
@@ -275,7 +275,7 b' define([' | |||
|
275 | 275 | // changed by another view or by a state update from the back-end. |
|
276 | 276 | if (options === undefined || options.updated_view != this) { |
|
277 | 277 | // Add missing items to the DOM. |
|
278 | var items = this.model.get('value_names'); | |
|
278 | var items = this.model.get('_value_names'); | |
|
279 | 279 | var disabled = this.model.get('disabled'); |
|
280 | 280 | var that = this; |
|
281 | 281 | var item_html; |
@@ -400,7 +400,7 b' define([' | |||
|
400 | 400 | // changed by another view or by a state update from the back-end. |
|
401 | 401 | if (options === undefined || options.updated_view != this) { |
|
402 | 402 | // Add missing items to the DOM. |
|
403 | var items = this.model.get('value_names'); | |
|
403 | var items = this.model.get('_value_names'); | |
|
404 | 404 | var that = this; |
|
405 | 405 | _.each(items, function(item, index) { |
|
406 | 406 | var item_query = 'option[value_name="' + item + '"]'; |
@@ -42,12 +42,12 b' class _Selection(DOMWidget):' | |||
|
42 | 42 | The keys of this list are the strings that will be displayed in the UI, |
|
43 | 43 | representing the actual Python choices. |
|
44 | 44 | |
|
45 | The keys of this list are also available as value_names. | |
|
45 | The keys of this list are also available as _value_names. | |
|
46 | 46 | """) |
|
47 | 47 | |
|
48 | values_dict = Dict() | |
|
49 | value_names = Tuple(sync=True) | |
|
50 | value_values = Tuple() | |
|
48 | _values_dict = Dict() | |
|
49 | _value_names = Tuple(sync=True) | |
|
50 | _value_values = Tuple() | |
|
51 | 51 | |
|
52 | 52 | disabled = Bool(False, help="Enable or disable user changes", sync=True) |
|
53 | 53 | description = Unicode(help="Description of the value this widget represents", sync=True) |
@@ -55,7 +55,7 b' class _Selection(DOMWidget):' | |||
|
55 | 55 | def __init__(self, *args, **kwargs): |
|
56 | 56 | self.value_lock = Lock() |
|
57 | 57 | self.values_lock = Lock() |
|
58 | self.on_trait_change(self._values_readonly_changed, ['values_dict', 'value_names', 'value_values', '_values']) | |
|
58 | self.on_trait_change(self._values_readonly_changed, ['_values_dict', '_value_names', '_value_values', '_values']) | |
|
59 | 59 | if 'values' in kwargs: |
|
60 | 60 | self.values = kwargs.pop('values') |
|
61 | 61 | DOMWidget.__init__(self, *args, **kwargs) |
@@ -88,18 +88,18 b' class _Selection(DOMWidget):' | |||
|
88 | 88 | self.values = new |
|
89 | 89 | |
|
90 | 90 | values = self._make_values(new) |
|
91 | self.values_dict = {i[0]: i[1] for i in values} | |
|
92 | self.value_names = [i[0] for i in values] | |
|
93 | self.value_values = [i[1] for i in values] | |
|
91 | self._values_dict = {i[0]: i[1] for i in values} | |
|
92 | self._value_names = [i[0] for i in values] | |
|
93 | self._value_values = [i[1] for i in values] | |
|
94 | 94 | self._value_in_values() |
|
95 | 95 | finally: |
|
96 | 96 | self.values_lock.release() |
|
97 | 97 | |
|
98 | 98 | def _value_in_values(self): |
|
99 | 99 | # ensure that the chosen value is one of the choices |
|
100 | if self.value_values: | |
|
101 | if self.value not in self.value_values: | |
|
102 | self.value = next(iter(self.value_values)) | |
|
100 | if self._value_values: | |
|
101 | if self.value not in self._value_values: | |
|
102 | self.value = next(iter(self._value_values)) | |
|
103 | 103 | |
|
104 | 104 | def _values_readonly_changed(self, name, old, new): |
|
105 | 105 | if not self.values_lock.locked(): |
@@ -110,7 +110,7 b' class _Selection(DOMWidget):' | |||
|
110 | 110 | if self.value_lock.acquire(False): |
|
111 | 111 | try: |
|
112 | 112 | # Reverse dictionary lookup for the value name |
|
113 | for k,v in self.values_dict.items(): | |
|
113 | for k,v in self._values_dict.items(): | |
|
114 | 114 | if new == v: |
|
115 | 115 | # set the selected value name |
|
116 | 116 | self.value_name = k |
@@ -125,7 +125,7 b' class _Selection(DOMWidget):' | |||
|
125 | 125 | """Called when the value name has been changed (typically by the frontend).""" |
|
126 | 126 | if self.value_lock.acquire(False): |
|
127 | 127 | try: |
|
128 | self.value = self.values_dict[new] | |
|
128 | self.value = self._values_dict[new] | |
|
129 | 129 | finally: |
|
130 | 130 | self.value_lock.release() |
|
131 | 131 |
General Comments 0
You need to be logged in to leave comments.
Login now