Show More
@@ -1477,6 +1477,12 b' h6:hover .anchor-link {' | |||
|
1477 | 1477 | .widget_item .dropdown-menu li a { |
|
1478 | 1478 | color: inherit; |
|
1479 | 1479 | } |
|
1480 | .widget-valid { | |
|
1481 | margin-top: 9px; | |
|
1482 | margin-bottom: 10px; | |
|
1483 | margin-left: 3px; | |
|
1484 | margin-right: 3px; | |
|
1485 | } | |
|
1480 | 1486 | .widget-hbox { |
|
1481 | 1487 | /* Horizontal widgets */ |
|
1482 | 1488 | /* Old browsers */ |
@@ -10269,6 +10269,12 b' h6:hover .anchor-link {' | |||
|
10269 | 10269 | .widget_item .dropdown-menu li a { |
|
10270 | 10270 | color: inherit; |
|
10271 | 10271 | } |
|
10272 | .widget-valid { | |
|
10273 | margin-top: 9px; | |
|
10274 | margin-bottom: 10px; | |
|
10275 | margin-left: 3px; | |
|
10276 | margin-right: 3px; | |
|
10277 | } | |
|
10272 | 10278 | .widget-hbox { |
|
10273 | 10279 | /* Horizontal widgets */ |
|
10274 | 10280 | /* Old browsers */ |
@@ -41,19 +41,19 b' define([' | |||
|
41 | 41 | /** |
|
42 | 42 | * Handles when the checkbox is clicked. |
|
43 | 43 | * |
|
44 |
* Calling model.set will trigger all of the other views of the |
|
|
44 | * Calling model.set will trigger all of the other views of the | |
|
45 | 45 | * model to update. |
|
46 | 46 | */ |
|
47 | 47 | var value = this.model.get('value'); |
|
48 | 48 | this.model.set('value', ! value, {updated_view: this}); |
|
49 | 49 | this.touch(); |
|
50 | 50 | }, |
|
51 | ||
|
51 | ||
|
52 | 52 | update : function(options){ |
|
53 | 53 | /** |
|
54 | 54 | * Update the contents of this view |
|
55 | 55 | * |
|
56 |
* Called when the model is changed. |
|
|
56 | * Called when the model is changed. The model may have been | |
|
57 | 57 | * changed by another view or by a state update from the back-end. |
|
58 | 58 | */ |
|
59 | 59 | this.$checkbox.prop('checked', this.model.get('value')); |
@@ -71,7 +71,6 b' define([' | |||
|
71 | 71 | } |
|
72 | 72 | return CheckboxView.__super__.update.apply(this); |
|
73 | 73 | }, |
|
74 | ||
|
75 | 74 | }); |
|
76 | 75 | |
|
77 | 76 | |
@@ -107,12 +106,12 b' define([' | |||
|
107 | 106 | }; |
|
108 | 107 | this.update_mapped_classes(class_map, 'button_style', previous_trait_value); |
|
109 | 108 | }, |
|
110 | ||
|
109 | ||
|
111 | 110 | update : function(options){ |
|
112 | 111 | /** |
|
113 | 112 | * Update the contents of this view |
|
114 | 113 | * |
|
115 |
* Called when the model is changed. The model may have been |
|
|
114 | * Called when the model is changed. The model may have been | |
|
116 | 115 | * changed by another view or by a state update from the back-end. |
|
117 | 116 | */ |
|
118 | 117 | if (this.model.get('value')) { |
@@ -136,12 +135,12 b' define([' | |||
|
136 | 135 | } |
|
137 | 136 | return ToggleButtonView.__super__.update.apply(this); |
|
138 | 137 | }, |
|
139 | ||
|
140 |
handle_click: function(e) { |
|
|
138 | ||
|
139 | handle_click: function(e) { | |
|
141 | 140 | /** |
|
142 | 141 | * Handles and validates user input. |
|
143 | 142 | * |
|
144 |
* Calling model.set will trigger all of the other views of the |
|
|
143 | * Calling model.set will trigger all of the other views of the | |
|
145 | 144 | * model to update. |
|
146 | 145 | */ |
|
147 | 146 | var value = this.model.get('value'); |
@@ -150,8 +149,41 b' define([' | |||
|
150 | 149 | }, |
|
151 | 150 | }); |
|
152 | 151 | |
|
152 | ||
|
153 | var ValidView = widget.DOMWidgetView.extend({ | |
|
154 | render: function() { | |
|
155 | /** | |
|
156 | * Called when view is rendered. | |
|
157 | */ | |
|
158 | this.$el.addClass("fa widget-valid"); | |
|
159 | this.model.on("change:value", this.update, this); | |
|
160 | this.update(); | |
|
161 | }, | |
|
162 | update: function() { | |
|
163 | /** | |
|
164 | * Update the contents of this view | |
|
165 | * | |
|
166 | * Called when the model is changed. The model may have been | |
|
167 | * changed by another view or by a state update from the back-end. | |
|
168 | */ | |
|
169 | if (this.model.get("value")) { | |
|
170 | this.$el.removeClass("fa-close").addClass("fa-check"); | |
|
171 | this.after_displayed(function() { | |
|
172 | this.$el.css("color", "green"); | |
|
173 | }, this); | |
|
174 | } else { | |
|
175 | this.$el.removeClass("fa-check").addClass("fa-close"); | |
|
176 | this.after_displayed(function() { | |
|
177 | this.$el.css("color", "red"); | |
|
178 | }, this); | |
|
179 | } | |
|
180 | } | |
|
181 | }); | |
|
182 | ||
|
183 | ||
|
153 | 184 | return { |
|
154 | 185 | 'CheckboxView': CheckboxView, |
|
155 | 186 | 'ToggleButtonView': ToggleButtonView, |
|
187 | 'ValidView': ValidView, | |
|
156 | 188 | }; |
|
157 | 189 | }); |
@@ -209,6 +209,13 b'' | |||
|
209 | 209 | color: inherit; |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | .widget-valid { | |
|
213 | margin-top: 9px; | |
|
214 | margin-bottom: 10px; | |
|
215 | margin-left: 3px; | |
|
216 | margin-right: 3px; | |
|
217 | } | |
|
218 | ||
|
212 | 219 | .widget-hbox { |
|
213 | 220 | /* Horizontal widgets */ |
|
214 | 221 | .hbox(); |
@@ -2,7 +2,7 b' from .widget import Widget, DOMWidget, CallbackDispatcher, register' | |||
|
2 | 2 | |
|
3 | 3 | from .trait_types import Color |
|
4 | 4 | |
|
5 | from .widget_bool import Checkbox, ToggleButton | |
|
5 | from .widget_bool import Checkbox, ToggleButton, Valid | |
|
6 | 6 | from .widget_button import Button |
|
7 | 7 | from .widget_box import Box, FlexBox, HBox, VBox |
|
8 | 8 | from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress, FloatRangeSlider |
@@ -60,17 +60,29 b' class ToggleButton(_Bool):' | |||
|
60 | 60 | icon: str |
|
61 | 61 | font-awesome icon name |
|
62 | 62 | """ |
|
63 | ||
|
64 | 63 | _view_name = Unicode('ToggleButtonView', sync=True) |
|
65 | 64 | tooltip = Unicode(help="Tooltip caption of the toggle button.", sync=True) |
|
66 | 65 | icon = Unicode('', help= "Font-awesome icon.", sync=True) |
|
67 | 66 | |
|
68 | 67 | button_style = CaselessStrEnum( |
|
69 |
values=['primary', 'success', 'info', 'warning', 'danger', ''], |
|
|
68 | values=['primary', 'success', 'info', 'warning', 'danger', ''], | |
|
70 | 69 | default_value='', allow_none=True, sync=True, help="""Use a |
|
71 | 70 | predefined styling for the button.""") |
|
72 | 71 | |
|
73 | 72 | |
|
73 | @register('IPython.Valid') | |
|
74 | class Valid(_Bool): | |
|
75 | ||
|
76 | """Displays a boolean `value` in the form of a green check (True / valid) | |
|
77 | or a red cross (False / invalid). | |
|
78 | ||
|
79 | Parameters | |
|
80 | ---------- | |
|
81 | value: {True,False} | |
|
82 | value of the Valid widget | |
|
83 | """ | |
|
84 | _view_name = Unicode('ValidView', sync=True) | |
|
85 | ||
|
74 | 86 | # Remove in IPython 4.0 |
|
75 | 87 | CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget') |
|
76 | 88 | ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget') |
General Comments 0
You need to be logged in to leave comments.
Login now