##// END OF EJS Templates
Add widget migration doc.
Jonathan Frederic -
Show More
@@ -0,0 +1,316
1 Upgrading Notebooks
2 -------------------
3
4 1. The first thing you'll notice when upgrading an IPython 2.0 widget
5 notebook to IPython 3.0 is the "Notebook converted" dialog. Click
6 "ok".
7 2. All of the widgets distributed with IPython have been renamed. The
8 "Widget" suffix was removed from the end of the class name. i.e.
9 ``ButtonWidget`` is now ``Button``.
10 3. ``ContainerWidget`` was renamed to ``Box``.
11 4. ``PopupWidget`` was removed from IPython. If you use the
12 ``PopupWidget``, try using a ``Box`` widget instead. If your notebook
13 can't live without the popup functionality, subclass the ``Box``
14 widget (both in Python and JS) and use JQuery UI's ``draggable()``
15 and ``resizable()`` methods to mimic the behavior.
16 5. ``add_class`` and ``remove_class`` were removed. More often than not
17 a new attribute exists on the widget that allows you to achieve the
18 same explicitly. i.e. the ``Button`` widget now has a
19 ``button_style`` attribute which you can set to 'primary', 'success',
20 'info', 'warning', 'danger', or '' instead of using ``add_class`` to
21 add the bootstrap class. ``VBox`` and ``HBox`` classes (flexible
22 ``Box`` subclasses) were added that allow you to avoid using
23 ``add_class`` and ``remove_class`` to make flexible box model
24 layouts. As a last resort, if you can't find a built in attribute for
25 the class you want to use, a new ``_dom_classes`` list trait was
26 added, which combines ``add_class`` and ``remove_class`` into one
27 stateful list.
28 6. ``set_css`` and ``get_css`` were removed in favor of explicit style
29 attributes - ``visible``, ``width``, ``height``, ``padding``,
30 ``margin``, ``color``, ``background_color``, ``border_color``,
31 ``border_width``, ``border_radius``, ``border_style``,
32 ``font_style``, ``font_weight``, ``font_size``, and ``font_family``
33 are a few. If you can't find a trait to see the css attribute you
34 need, you can, in order of preference, (A) subclass to create your
35 own custom widget, (B) use CSS and the ``_dom_classes`` trait to set
36 ``_dom_classes``, or (C) use the ``_css`` dictionary to set CSS
37 styling like ``set_css`` and ``get_css``.
38
39 Upgrading Custom Widgets
40 ------------------------
41
42 Javascript
43 ~~~~~~~~~~
44
45 1. If you are distributing your widget and decide to use the deferred
46 loading technique (preferred), you can remove all references to the
47 WidgetManager and the register model/view calls (see the Python
48 section below for more information).
49 2. In 2.0 require.js was used incorrectly, that has been fixed and now
50 loading works more like Python's import. Requiring
51 ``widgets/js/widget`` doesn't import the ``WidgetManager`` class,
52 instead it imports a dictionary that exposes the classes within that
53 module:
54
55 .. code:: javascript
56
57 {
58 'WidgetModel': WidgetModel,
59 'WidgetView': WidgetView,
60 'DOMWidgetView': DOMWidgetView,
61 'ViewList': ViewList,
62 }
63
64 If you decide to continue to use the widget registry (by registering
65 your widgets with the manager), you can import a dictionary with a
66 handle to the WidgetManager class by requiring
67 ``widgets/js/manager``. Doing so will import:
68
69 .. code:: javascript
70
71 {'WidgetManager': WidgetManager}
72
73 3. Don't rely on the ``IPython`` namespace for anything. To inherit from
74 the DOMWidgetView, WidgetView, or WidgetModel, require
75 ``widgets/js/widget`` as ``widget``. If you were inheriting from
76 DOMWidgetView, and the code looked like this:
77
78 .. code:: javascript
79
80 IPython.DOMWidgetView.extend({...})
81
82 It would become this:
83
84 .. code:: javascript
85
86 widget.DOMWidgetView.extend({...})
87
88 4. Custom models are encouraged. When possible, it's recommended to move
89 your code into a custom model, so actions are performed 1 time,
90 instead of N times where N is the number of displayed views.
91
92 Python
93 ~~~~~~
94
95 Generally, custom widget Python code can remain unchanged. If you
96 distribute your custom widget, you may be using ``display`` and
97 ``Javascript`` to publish the widget's Javascript to the front-end. That
98 is no longer the recommended way of distributing widget Javascript.
99 Instead have the user install the Javascript to his/her nbextension
100 directory or their profile's static directory. Then use the new
101 ``_view_module`` and ``_model_module`` traitlets in combination with
102 ``_view_name`` and ``_model_name`` to instruct require.js on how to load
103 the widget's Javascript. The Javascript is then loaded when the widget
104 is used for the first time.
105
106 Details
107 -------
108
109 Asynchronous
110 ~~~~~~~~~~~~
111
112 In the IPython 2.x series the only way to register custom widget views
113 and models was to use the registry in the widget manager. Unfortunately,
114 using this method made packing custom widgets difficult. The widget
115 maintainer had to either use the rich display framework to push the
116 widget's Javascript to the notebook or instruct the users to install the
117 Javascript by hand in a custom profile. With the first method, the
118 maintainer would have to be careful about when the Javascript was pushed
119 to the font-end. If the Javascript was pushed on Python widget
120 ``import``, the widgets wouldn't work after page refresh. This is
121 because refreshing the page does not restart the kernel, and the Python
122 ``import`` statement only runs once in a given kernel instance (unless
123 you reload the Python modules, which isn't straight forward). This meant
124 the maintainer would have to have a separate ``push_js()`` method that
125 the user would have to call after importing the widget's Python code.
126
127 Our solution was to add support for loading widget views and models
128 using require.js paths. Thus the comm and widget frameworks now support
129 lazy loading. To do so, everything had to be converted to asynchronous
130 code. HTML5 promises are used to accomplish that
131 (`#6818 <https://github.com/ipython/ipython/pull/6818>`__,
132 `#6914 <https://github.com/ipython/ipython/pull/6914>`__).
133
134 Symmetry
135 ~~~~~~~~
136
137 In IPython 3.0, widgets can be instantiated from the front-end
138 (`#6664 <https://github.com/ipython/ipython/pull/6664>`__). On top of
139 this, a widget persistence API was added
140 (`#7163 <https://github.com/ipython/ipython/pull/7163>`__,
141 `#7227 <https://github.com/ipython/ipython/pull/7227>`__). With the
142 widget persistence API, you can persist your widget instances using
143 Javascript. This makes it easy to persist your widgets to your notebook
144 document (with a small amount of custom JS). By default, the widgets are
145 persisted to your web browsers local storage which makes them reappear
146 when your refresh the page.
147
148 Smaller Changes
149 ~~~~~~~~~~~~~~~
150
151 - Latex math is supported in widget ``description``\ s
152 (`#5937 <https://github.com/ipython/ipython/pull/5937>`__).
153 - Widgets can be display more than once within a single container
154 widget (`#5963 <https://github.com/ipython/ipython/pull/5963>`__,
155 `#6990 <https://github.com/ipython/ipython/pull/6990>`__).
156 - ``FloatRangeSlider`` and ``IntRangeSlider`` were added
157 (`#6050 <https://github.com/ipython/ipython/pull/6050>`__).
158 - "Widget" was removed from the ends of all of the widget class names
159 (`#6125 <https://github.com/ipython/ipython/pull/6125>`__).
160 - ``ContainerWidget`` was renamed to ``Box``
161 (`#6125 <https://github.com/ipython/ipython/pull/6125>`__).
162 - ``HBox`` and ``VBox`` widgets were added
163 (`#6125 <https://github.com/ipython/ipython/pull/6125>`__).
164 - ``add\_class`` and ``remove\_class`` were removed in favor of a
165 ``_dom_classes`` list
166 (`#6235 <https://github.com/ipython/ipython/pull/6235>`__).
167 - ``get\_css`` and ``set\_css`` were removed in favor of explicit
168 traits for widget styling
169 (`#6235 <https://github.com/ipython/ipython/pull/6235>`__).
170 - ``jslink`` and ``jsdlink`` were added
171 (`#6454 <https://github.com/ipython/ipython/pull/6454>`__,
172 `#7468 <https://github.com/ipython/ipython/pull/7468>`__).
173 - An ``Output`` widget was added, which allows you to ``print`` and
174 ``display`` within widgets
175 (`#6670 <https://github.com/ipython/ipython/pull/6670>`__).
176 - ``PopupWidget`` was removed
177 (`#7341 <https://github.com/ipython/ipython/pull/7341>`__).
178 - A visual cue was added for widgets with 'dead' comms
179 (`#7227 <https://github.com/ipython/ipython/pull/7227>`__).
180 - A ``SelectMultiple`` widget was added (a ``Select`` widget that
181 allows multiple things to be selected at once)
182 (`#6890 <https://github.com/ipython/ipython/pull/6890>`__).
183 - A class was added to help manage children views
184 (`#6990 <https://github.com/ipython/ipython/pull/6990>`__).
185 - A warning was added that shows on widget import because it's expected
186 that the API will change again by IPython 4.0. This warning can be
187 supressed (`#7107 <https://github.com/ipython/ipython/pull/7107>`__,
188 `#7200 <https://github.com/ipython/ipython/pull/7200>`__,
189 `#7201 <https://github.com/ipython/ipython/pull/7201>`__,
190 `#7204 <https://github.com/ipython/ipython/pull/7204>`__).
191
192 Comm and Widget PR Index
193 ------------------------
194
195 | Here is a chronological list of PRs affecting the widget and comm
196 frameworks for IPython 3.0. Note that later PRs may revert changes
197 made in earlier PRs:
198 | - Add placeholder attribute to text widgets
199 `#5652 <https://github.com/ipython/ipython/pull/5652>`__
200 | - Add latex support in widget labels,
201 `#5937 <https://github.com/ipython/ipython/pull/5937>`__
202 | - Allow widgets to display more than once within container widgets.
203 `#5963 <https://github.com/ipython/ipython/pull/5963>`__
204 | - use require.js,
205 `#5980 <https://github.com/ipython/ipython/pull/5980>`__
206 | - Range widgets
207 `#6050 <https://github.com/ipython/ipython/pull/6050>`__
208 | - Interact on\_demand option
209 `#6051 <https://github.com/ipython/ipython/pull/6051>`__
210 | - Allow text input on slider widgets
211 `#6106 <https://github.com/ipython/ipython/pull/6106>`__
212 | - support binary buffers in comm messages
213 `#6110 <https://github.com/ipython/ipython/pull/6110>`__
214 | - Embrace the flexible box model in the widgets
215 `#6125 <https://github.com/ipython/ipython/pull/6125>`__
216 | - Widget trait serialization
217 `#6128 <https://github.com/ipython/ipython/pull/6128>`__
218 | - Make Container widgets take children as the first positional
219 argument `#6153 <https://github.com/ipython/ipython/pull/6153>`__
220 | - once-displayed
221 `#6168 <https://github.com/ipython/ipython/pull/6168>`__
222 | - Validate slider value, when limits change
223 `#6171 <https://github.com/ipython/ipython/pull/6171>`__
224 | - Unregistering comms in Comm Manager
225 `#6216 <https://github.com/ipython/ipython/pull/6216>`__
226 | - Add EventfulList and EventfulDict trait types.
227 `#6228 <https://github.com/ipython/ipython/pull/6228>`__
228 | - Remove add/remove\_class and set/get\_css.
229 `#6235 <https://github.com/ipython/ipython/pull/6235>`__
230 | - avoid unregistering widget model twice
231 `#6250 <https://github.com/ipython/ipython/pull/6250>`__
232 | - Widget property lock should compare json states, not python states
233 `#6332 <https://github.com/ipython/ipython/pull/6332>`__
234 | - Strip the IPY\_MODEL\_ prefix from widget IDs before referencing
235 them. `#6377 <https://github.com/ipython/ipython/pull/6377>`__
236 | - "event" is not defined error in Firefox
237 `#6437 <https://github.com/ipython/ipython/pull/6437>`__
238 | - Javascript link
239 `#6454 <https://github.com/ipython/ipython/pull/6454>`__
240 | - Bulk update of widget attributes
241 `#6463 <https://github.com/ipython/ipython/pull/6463>`__
242 | - Creating a widget registry on the Python side.
243 `#6493 <https://github.com/ipython/ipython/pull/6493>`__
244 | - Allow widget views to be loaded from require modules
245 `#6494 <https://github.com/ipython/ipython/pull/6494>`__
246 | - Fix Issue #6530
247 `#6532 <https://github.com/ipython/ipython/pull/6532>`__
248 | - Make comm manager (mostly) independent of InteractiveShell
249 `#6540 <https://github.com/ipython/ipython/pull/6540>`__
250 | - Add semantic classes to top-level containers for single widgets
251 `#6609 <https://github.com/ipython/ipython/pull/6609>`__
252 | - Selection Widgets: forcing 'value' to be in 'values'
253 `#6617 <https://github.com/ipython/ipython/pull/6617>`__
254 | - Allow widgets to be constructed from Javascript
255 `#6664 <https://github.com/ipython/ipython/pull/6664>`__
256 | - Output widget
257 `#6670 <https://github.com/ipython/ipython/pull/6670>`__
258 | - Minor change in widgets.less to fix alignment issue
259 `#6681 <https://github.com/ipython/ipython/pull/6681>`__
260 | - Make Selection widgets respect values order.
261 `#6747 <https://github.com/ipython/ipython/pull/6747>`__
262 | - Widget persistence API
263 `#6789 <https://github.com/ipython/ipython/pull/6789>`__
264 | - Add promises to the widget framework.
265 `#6818 <https://github.com/ipython/ipython/pull/6818>`__
266 | - SelectMultiple widget
267 `#6890 <https://github.com/ipython/ipython/pull/6890>`__
268 | - Tooltip on toggle button
269 `#6923 <https://github.com/ipython/ipython/pull/6923>`__
270 | - Allow empty text box \*while typing\* for numeric widgets
271 `#6943 <https://github.com/ipython/ipython/pull/6943>`__
272 | - Ignore failure of widget MathJax typesetting
273 `#6948 <https://github.com/ipython/ipython/pull/6948>`__
274 | - Refactor the do\_diff and manual child view lists into a separate
275 ViewList object
276 `#6990 <https://github.com/ipython/ipython/pull/6990>`__
277 | - Add warning to widget namespace import.
278 `#7107 <https://github.com/ipython/ipython/pull/7107>`__
279 | - lazy load widgets
280 `#7120 <https://github.com/ipython/ipython/pull/7120>`__
281 | - Fix padding of widgets.
282 `#7139 <https://github.com/ipython/ipython/pull/7139>`__
283 | - Persist widgets across page refresh
284 `#7163 <https://github.com/ipython/ipython/pull/7163>`__
285 | - Make the widget experimental error a real python warning
286 `#7200 <https://github.com/ipython/ipython/pull/7200>`__
287 | - Make the widget error message shorter and more understandable.
288 `#7201 <https://github.com/ipython/ipython/pull/7201>`__
289 | - Make the widget warning brief and easy to filter
290 `#7204 <https://github.com/ipython/ipython/pull/7204>`__
291 | - Add visual cue for widgets with dead comms
292 `#7227 <https://github.com/ipython/ipython/pull/7227>`__
293 | - Widget values as positional arguments
294 `#7260 <https://github.com/ipython/ipython/pull/7260>`__
295 | - Remove the popup widget
296 `#7341 <https://github.com/ipython/ipython/pull/7341>`__
297 | - document and validate link, dlink
298 `#7468 <https://github.com/ipython/ipython/pull/7468>`__
299 | - Document interact 5637
300 `#7525 <https://github.com/ipython/ipython/pull/7525>`__
301 | - Update some broken examples of using widgets
302 `#7547 <https://github.com/ipython/ipython/pull/7547>`__
303 | - Use Output widget with Interact
304 `#7554 <https://github.com/ipython/ipython/pull/7554>`__
305 | - don't send empty execute\_result messages
306 `#7560 <https://github.com/ipython/ipython/pull/7560>`__
307 | - Validation on the python side
308 `#7602 <https://github.com/ipython/ipython/pull/7602>`__
309 | - only show prompt overlay if there's a prompt
310 `#7661 <https://github.com/ipython/ipython/pull/7661>`__
311 | - Allow predictate to be used for comparison in selection widgets
312 `#7674 <https://github.com/ipython/ipython/pull/7674>`__
313 | - Fix widget view persistence.
314 `#7680 <https://github.com/ipython/ipython/pull/7680>`__
315 | - Revert "Use Output widget with Interact"
316 `#7703 <https://github.com/ipython/ipython/pull/7703>`__
@@ -66,6 +66,12 characters. Python 3 allows unicode identifiers, and IPython 3 makes it easier
66 to type those, using a feature from Julia. Type a backslash followed by a LaTeX
66 to type those, using a feature from Julia. Type a backslash followed by a LaTeX
67 style short name, such as ``\alpha``. Press tab, and it will turn into α.
67 style short name, such as ``\alpha``. Press tab, and it will turn into α.
68
68
69 Widget migration guide
70 ----------------------
71 The widget framework has a lot of backwards incompatible changes. For information about migrating widget notebooks and custom widgets to 3.0 refere to the `widget migration guide`_.
72
73 .. _widget migration guide: ./version3_widget_migration.rst
74
69 Other new features
75 Other new features
70 ------------------
76 ------------------
71
77
General Comments 0
You need to be logged in to leave comments. Login now