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