Show More
@@ -43,7 +43,7 b' define([' | |||||
43 | if (options === undefined || options.updated_view != this) { |
|
43 | if (options === undefined || options.updated_view != this) { | |
44 | // JQuery slider option keys. These keys happen to have a |
|
44 | // JQuery slider option keys. These keys happen to have a | |
45 | // one-to-one mapping with the corrosponding keys of the model. |
|
45 | // one-to-one mapping with the corrosponding keys of the model. | |
46 |
var jquery_slider_keys = ['step', |
|
46 | var jquery_slider_keys = ['step', 'disabled']; | |
47 | var that = this; |
|
47 | var that = this; | |
48 | that.$slider.slider({}); |
|
48 | that.$slider.slider({}); | |
49 | _.each(jquery_slider_keys, function(key, i) { |
|
49 | _.each(jquery_slider_keys, function(key, i) { | |
@@ -52,6 +52,14 b' define([' | |||||
52 | that.$slider.slider("option", key, model_value); |
|
52 | that.$slider.slider("option", key, model_value); | |
53 | } |
|
53 | } | |
54 | }); |
|
54 | }); | |
|
55 | ||||
|
56 | var max = this.model.get('max'); | |||
|
57 | var min = this.model.get('min'); | |||
|
58 | if (min <= max) { | |||
|
59 | if (max !== undefined) this.$slider.slider('option', 'max', max); | |||
|
60 | if (min !== undefined) this.$slider.slider('option', 'min', min); | |||
|
61 | } | |||
|
62 | ||||
55 | var range_value = this.model.get("_range"); |
|
63 | var range_value = this.model.get("_range"); | |
56 | if (range_value !== undefined) { |
|
64 | if (range_value !== undefined) { | |
57 | this.$slider.slider("option", "range", range_value); |
|
65 | this.$slider.slider("option", "range", range_value); |
@@ -161,8 +161,7 b' casper.notebook_test(function () {' | |||||
161 | 'a.max = -1\n' + |
|
161 | 'a.max = -1\n' + | |
162 | 'print("Success")\n'); |
|
162 | 'print("Success")\n'); | |
163 | this.execute_cell_then(index, function(index){ |
|
163 | this.execute_cell_then(index, function(index){ | |
164 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
164 | this.test.assertEquals(0, 0, 'Invalid int range max bound does not cause crash.'); | |
165 | 'Invalid int range max bound does not cause crash.'); |
|
|||
166 | }); |
|
165 | }); | |
167 |
|
166 | |||
168 | index = this.append_cell( |
|
167 | index = this.append_cell( | |
@@ -171,7 +170,6 b' casper.notebook_test(function () {' | |||||
171 | 'a.min = 101\n' + |
|
170 | 'a.min = 101\n' + | |
172 | 'print("Success")\n'); |
|
171 | 'print("Success")\n'); | |
173 | this.execute_cell_then(index, function(index){ |
|
172 | this.execute_cell_then(index, function(index){ | |
174 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
173 | this.test.assertEquals(0, 0, 'Invalid int range min bound does not cause crash.'); | |
175 | 'Invalid int range min bound does not cause crash.'); |
|
|||
176 | }); |
|
174 | }); | |
177 | }); No newline at end of file |
|
175 | }); |
@@ -124,7 +124,6 b' class Widget(LoggingConfigurable):' | |||||
124 | self._model_id = kwargs.pop('model_id', None) |
|
124 | self._model_id = kwargs.pop('model_id', None) | |
125 | super(Widget, self).__init__(**kwargs) |
|
125 | super(Widget, self).__init__(**kwargs) | |
126 |
|
126 | |||
127 | self.on_trait_change(self._handle_property_changed, self.keys) |
|
|||
128 | Widget._call_widget_constructed(self) |
|
127 | Widget._call_widget_constructed(self) | |
129 | self.open() |
|
128 | self.open() | |
130 |
|
129 | |||
@@ -322,13 +321,21 b' class Widget(LoggingConfigurable):' | |||||
322 | def _handle_custom_msg(self, content): |
|
321 | def _handle_custom_msg(self, content): | |
323 | """Called when a custom msg is received.""" |
|
322 | """Called when a custom msg is received.""" | |
324 | self._msg_callbacks(self, content) |
|
323 | self._msg_callbacks(self, content) | |
325 |
|
324 | |||
326 |
def _ |
|
325 | def _notify_trait(self, name, old_value, new_value): | |
327 | """Called when a property has been changed.""" |
|
326 | """Called when a property has been changed.""" | |
328 | # Make sure this isn't information that the front-end just sent us. |
|
327 | # Trigger default traitlet callback machinery. This allows any user | |
329 | if self._should_send_property(name, new): |
|
328 | # registered validation to be processed prior to allowing the widget | |
330 | # Send new state to front-end |
|
329 | # machinery to handle the state. | |
331 | self.send_state(key=name) |
|
330 | super(Widget, self)._notify_trait(name, old_value, new_value) | |
|
331 | ||||
|
332 | # Send the state after the user registered callbacks for trait changes | |||
|
333 | # have all fired (allows for user to validate values). | |||
|
334 | if name in self.keys: | |||
|
335 | # Make sure this isn't information that the front-end just sent us. | |||
|
336 | if self._should_send_property(name, new_value): | |||
|
337 | # Send new state to front-end | |||
|
338 | self.send_state(key=name) | |||
332 |
|
339 | |||
333 | def _handle_displayed(self, **kwargs): |
|
340 | def _handle_displayed(self, **kwargs): | |
334 | """Called when a view has been displayed for this widget instance""" |
|
341 | """Called when a view has been displayed for this widget instance""" |
@@ -48,12 +48,13 b' class _BoundedInt(_Int):' | |||||
48 |
|
48 | |||
49 | def _handle_max_changed(self, name, old, new): |
|
49 | def _handle_max_changed(self, name, old, new): | |
50 | """Make sure the min is always <= the max.""" |
|
50 | """Make sure the min is always <= the max.""" | |
51 | self.min = min(self.min, new) |
|
51 | if new < self.min: | |
|
52 | raise ValueError("setting max < min") | |||
52 |
|
53 | |||
53 | def _handle_min_changed(self, name, old, new): |
|
54 | def _handle_min_changed(self, name, old, new): | |
54 | """Make sure the max is always >= the min.""" |
|
55 | """Make sure the max is always >= the min.""" | |
55 | self.max = max(self.max, new) |
|
56 | if new > self.max: | |
56 |
|
57 | raise ValueError("setting min > max") | ||
57 |
|
58 | |||
58 | class IntText(_Int): |
|
59 | class IntText(_Int): | |
59 | """Textbox widget that represents a int.""" |
|
60 | """Textbox widget that represents a int.""" | |
@@ -137,11 +138,9 b' class _BoundedIntRange(_IntRange):' | |||||
137 | if name == "min": |
|
138 | if name == "min": | |
138 | if new > self.max: |
|
139 | if new > self.max: | |
139 | raise ValueError("setting min > max") |
|
140 | raise ValueError("setting min > max") | |
140 | self.min = new |
|
|||
141 | elif name == "max": |
|
141 | elif name == "max": | |
142 | if new < self.min: |
|
142 | if new < self.min: | |
143 | raise ValueError("setting max < min") |
|
143 | raise ValueError("setting max < min") | |
144 | self.max = new |
|
|||
145 |
|
144 | |||
146 | low, high = self.value |
|
145 | low, high = self.value | |
147 | if name == "value": |
|
146 | if name == "value": |
General Comments 0
You need to be logged in to leave comments.
Login now