##// END OF EJS Templates
review pass on widget examples
MinRK -
Show More
@@ -46,7 +46,7 b''
46 "cell_type": "markdown",
46 "cell_type": "markdown",
47 "metadata": {},
47 "metadata": {},
48 "source": [
48 "source": [
49 "The IPython notebook comes preloaded with basic widgets that represent common data types. These widgets are\n",
49 "IPython comes with basic widgets that represent common interactive controls. These widgets are\n",
50 "\n",
50 "\n",
51 "- CheckBoxWidget\n",
51 "- CheckBoxWidget\n",
52 "- ToggleButtonWidget\n",
52 "- ToggleButtonWidget\n",
@@ -67,10 +67,10 b''
67 "- LatexWidget\n",
67 "- LatexWidget\n",
68 "- TextAreaWidget\n",
68 "- TextAreaWidget\n",
69 "- TextBoxWidget\n",
69 "- TextBoxWidget\n",
70 "- ButtonWidget\n",
70 "\n",
71 "\n",
71 "A few special widgets are also included, that can be used to capture events and change how other widgets are displayed. These widgets are\n",
72 "A few special widgets are also included, that can be used to capture events and change how other widgets are displayed. These widgets are\n",
72 "\n",
73 "\n",
73 "- ButtonWidget\n",
74 "- ContainerWidget\n",
74 "- ContainerWidget\n",
75 "- PopupWidget\n",
75 "- PopupWidget\n",
76 "- AccordionWidget\n",
76 "- AccordionWidget\n",
@@ -128,7 +128,7 b''
128 "cell_type": "markdown",
128 "cell_type": "markdown",
129 "metadata": {},
129 "metadata": {},
130 "source": [
130 "source": [
131 "The basic widgets can all be constructed without arguments. The following creates a *FloatSliderWidget* without displaying it"
131 "The basic widgets all have sensible default values. Create a *FloatSliderWidget* without displaying it:"
132 ]
132 ]
133 },
133 },
134 {
134 {
@@ -184,7 +184,7 b''
184 "source": [
184 "source": [
185 "It's important to realize that widgets are not the same as output, even though they are displayed with `display`. Widgets are drawn in a special widget area. That area is marked with a close button which allows you to collapse the widgets. Widgets cannot be interleaved with output. Doing so would break the ability to make simple animations using `clear_output`.\n",
185 "It's important to realize that widgets are not the same as output, even though they are displayed with `display`. Widgets are drawn in a special widget area. That area is marked with a close button which allows you to collapse the widgets. Widgets cannot be interleaved with output. Doing so would break the ability to make simple animations using `clear_output`.\n",
186 "\n",
186 "\n",
187 "Widgets are manipulated via special instance properties (traitlets). The names of these instance properties are listed in the widget's `keys` property (as seen below). A few of these properties are common to most, if not all, widgets. The common properties are `value`, `description`, `visible`, and `disabled`. `_css` and `_view_name` are internal properties that exist in all widgets and should not be modified."
187 "Widgets are manipulated via special instance attributes (traitlets). The names of these traitlets are listed in the widget's `keys` attribute (as seen below). A few of these attributes are common to most widgets. The basic attributes are `value`, `description`, `visible`, and `disabled`. `_css` and `_view_name` are private attributes that exist in all widgets and should not be modified."
188 ]
188 ]
189 },
189 },
190 {
190 {
@@ -202,15 +202,15 b''
202 "prompt_number": 6,
202 "prompt_number": 6,
203 "text": [
203 "text": [
204 "['_view_name',\n",
204 "['_view_name',\n",
205 " 'description',\n",
206 " 'min',\n",
207 " 'orientation',\n",
205 " 'orientation',\n",
206 " 'min',\n",
208 " 'max',\n",
207 " 'max',\n",
209 " '_css',\n",
208 " '_css',\n",
210 " 'value',\n",
209 " 'value',\n",
211 " 'disabled',\n",
210 " 'disabled',\n",
212 " 'visible',\n",
211 " 'visible',\n",
213 " 'step']"
212 " 'step',\n",
213 " 'description']"
214 ]
214 ]
215 }
215 }
216 ],
216 ],
@@ -220,7 +220,7 b''
220 "cell_type": "markdown",
220 "cell_type": "markdown",
221 "metadata": {},
221 "metadata": {},
222 "source": [
222 "source": [
223 "Changing a widget's property value will automatically update that widget everywhere it is displayed in the notebook. Here the value of `mywidget` is set. The slider shown above (after inputs 4 and 5) updates automatically to the new value. In reverse, changing the value of the displayed widget will update the property's value."
223 "Changing a widget's attribute will automatically update that widget everywhere it is displayed in the notebook. Here, the `value` attribute of `mywidget` is set. The slider shown above updates automatically with the new value. Syncing also works in the other direction - changing the value of the displayed widget will update the property's value."
224 ]
224 ]
225 },
225 },
226 {
226 {
@@ -255,7 +255,7 b''
255 "output_type": "pyout",
255 "output_type": "pyout",
256 "prompt_number": 8,
256 "prompt_number": 8,
257 "text": [
257 "text": [
258 "0.0"
258 "25.0"
259 ]
259 ]
260 }
260 }
261 ],
261 ],
@@ -265,7 +265,7 b''
265 "cell_type": "markdown",
265 "cell_type": "markdown",
266 "metadata": {},
266 "metadata": {},
267 "source": [
267 "source": [
268 "Widget property values can also be set with kwargs during the construction of the widget (as seen below)."
268 "Widget values can also be set with kwargs during the construction of the widget (as seen below)."
269 ]
269 ]
270 },
270 },
271 {
271 {
@@ -46,7 +46,7 b''
46 "cell_type": "markdown",
46 "cell_type": "markdown",
47 "metadata": {},
47 "metadata": {},
48 "source": [
48 "source": [
49 "As mentioned in Part 1, the widget properties are IPython traitlets. Traitlets are eventful. To handle property value changes, the `on_trait_change` method of the widget can be used to register an event handling callback. The doc string for `on_trait_change` can be seen below. Both the `name` and `remove` properties are optional."
49 "As mentioned in Part 1, the widget attributes are IPython traitlets. Traitlets are eventful. To handle changes, the `on_trait_change` method of the widget can be used to register a callback. The docstring for `on_trait_change` can be seen below. Both the `name` and `remove` properties are optional."
50 ]
50 ]
51 },
51 },
52 {
52 {
@@ -109,13 +109,13 b''
109 "cell_type": "code",
109 "cell_type": "code",
110 "collapsed": false,
110 "collapsed": false,
111 "input": [
111 "input": [
112 "intrange = widgets.IntSliderWidget()\n",
112 "int_range = widgets.IntSliderWidget()\n",
113 "display(intrange)\n",
113 "display(int_range)\n",
114 "\n",
114 "\n",
115 "def on_value_change(name, value):\n",
115 "def on_value_change(name, value):\n",
116 " print(value)\n",
116 " print(value)\n",
117 "\n",
117 "\n",
118 "intrange.on_trait_change(on_value_change, 'value')"
118 "int_range.on_trait_change(on_value_change, 'value')"
119 ],
119 ],
120 "language": "python",
120 "language": "python",
121 "metadata": {},
121 "metadata": {},
@@ -124,21 +124,21 b''
124 "output_type": "stream",
124 "output_type": "stream",
125 "stream": "stdout",
125 "stream": "stdout",
126 "text": [
126 "text": [
127 "34\n"
127 "1\n"
128 ]
128 ]
129 },
129 },
130 {
130 {
131 "output_type": "stream",
131 "output_type": "stream",
132 "stream": "stdout",
132 "stream": "stdout",
133 "text": [
133 "text": [
134 "74\n"
134 "2\n"
135 ]
135 ]
136 },
136 },
137 {
137 {
138 "output_type": "stream",
138 "output_type": "stream",
139 "stream": "stdout",
139 "stream": "stdout",
140 "text": [
140 "text": [
141 "98\n"
141 "3\n"
142 ]
142 ]
143 }
143 }
144 ],
144 ],
@@ -157,14 +157,14 b''
157 "level": 2,
157 "level": 2,
158 "metadata": {},
158 "metadata": {},
159 "source": [
159 "source": [
160 "Button On Click Event"
160 "Button Click Event"
161 ]
161 ]
162 },
162 },
163 {
163 {
164 "cell_type": "markdown",
164 "cell_type": "markdown",
165 "metadata": {},
165 "metadata": {},
166 "source": [
166 "source": [
167 "The `ButtonWidget` is a special widget, like the `ContainerWidget` and `TabWidget`, that isn't used to represent a data type. Instead the button widget is used to handle mouse clicks. The `on_click` method of the `ButtonWidget` can be used to register a click even handler. The doc string of the `on_click` can be seen below."
167 "The `ButtonWidget` is a special widget, like the `ContainerWidget` and `TabWidget`, that isn't used to represent a data type. Instead the button widget is used to handle mouse clicks. The `on_click` method of the `ButtonWidget` can be used to register function to be called when the button is clicked. The docstring of the `on_click` can be seen below."
168 ]
168 ]
169 },
169 },
170 {
170 {
@@ -180,13 +180,10 b''
180 "output_type": "stream",
180 "output_type": "stream",
181 "stream": "stdout",
181 "stream": "stdout",
182 "text": [
182 "text": [
183 "Register a callback to execute when the button is clicked. \n",
183 "Register a callback to execute when the button is clicked.\n",
184 "\n",
184 "\n",
185 " The callback can either accept no parameters or one sender parameter:\n",
185 " The callback will be called with one argument,\n",
186 " - callback()\n",
186 " the clicked button widget instance.\n",
187 " - callback(sender)\n",
188 " If the callback has a sender parameter, the ButtonWidget instance that\n",
189 " called the callback will be passed into the method as the sender.\n",
190 "\n",
187 "\n",
191 " Parameters\n",
188 " Parameters\n",
192 " ----------\n",
189 " ----------\n",
@@ -211,7 +208,7 b''
211 "button = widgets.ButtonWidget(description=\"Click Me!\")\n",
208 "button = widgets.ButtonWidget(description=\"Click Me!\")\n",
212 "display(button)\n",
209 "display(button)\n",
213 "\n",
210 "\n",
214 "def on_button_clicked(sender):\n",
211 "def on_button_clicked(b):\n",
215 " print(\"Button clicked.\")\n",
212 " print(\"Button clicked.\")\n",
216 "\n",
213 "\n",
217 "button.on_click(on_button_clicked)"
214 "button.on_click(on_button_clicked)"
@@ -232,13 +229,6 b''
232 "text": [
229 "text": [
233 "Button clicked.\n"
230 "Button clicked.\n"
234 ]
231 ]
235 },
236 {
237 "output_type": "stream",
238 "stream": "stdout",
239 "text": [
240 "Button clicked.\n"
241 ]
242 }
232 }
243 ],
233 ],
244 "prompt_number": 5
234 "prompt_number": 5
@@ -254,17 +244,17 b''
254 "cell_type": "code",
244 "cell_type": "code",
255 "collapsed": false,
245 "collapsed": false,
256 "input": [
246 "input": [
257 "def show_button(sender):\n",
247 "def new_button(clicked):\n",
258 " button = widgets.ButtonWidget()\n",
248 " button = widgets.ButtonWidget()\n",
259 " button.clicks = 0\n",
249 " button.clicks = 0\n",
260 " sender.clicks += 1\n",
250 " clicked.clicks += 1\n",
261 " button.description = \"%d\" % sender.clicks\n",
251 " button.description = \"%d\" % clicked.clicks\n",
262 " display(button)\n",
252 " display(button)\n",
263 " button.on_click(show_button)\n",
253 " button.on_click(new_button)\n",
264 "button = widgets.ButtonWidget(description = \"Start\")\n",
254 "button = widgets.ButtonWidget(description = \"Start\")\n",
265 "button.clicks = 0\n",
255 "button.clicks = 0\n",
266 "display(button)\n",
256 "display(button)\n",
267 "button.on_click(show_button)\n",
257 "button.on_click(new_button)\n",
268 " "
258 " "
269 ],
259 ],
270 "language": "python",
260 "language": "python",
@@ -44,18 +44,18 b''
44 "cell_type": "markdown",
44 "cell_type": "markdown",
45 "metadata": {},
45 "metadata": {},
46 "source": [
46 "source": [
47 "To display widget A inside widget B, widget A must be a child of widget B. Only one instance of any particular model can be child of another. In other words, *widget A* cannot have *widget B* listed twice in it's children list.\n",
47 "To display widget A inside widget B, widget A must be a child of widget B. Only one instance of any particular widget can be child of another. In other words, *widget A* cannot have *widget B* listed twice in it's list of children.\n",
48 "\n",
48 "\n",
49 "Widgets that can contain other widgets have a `children` property. This property can be set via a kwarg in the widget's constructor or after construction. Calling display on an object with children automatically displays those children too (as seen below)."
49 "Widgets that can contain other widgets have a `children` attribute. This attribute can be set via a kwarg in the widget's constructor or after construction. Calling display on an object with children automatically displays those children, too."
50 ]
50 ]
51 },
51 },
52 {
52 {
53 "cell_type": "code",
53 "cell_type": "code",
54 "collapsed": false,
54 "collapsed": false,
55 "input": [
55 "input": [
56 "floatrange = widgets.FloatSliderWidget()\n",
56 "float_range = widgets.FloatSliderWidget()\n",
57 "string = widgets.TextBoxWidget(value='hi')\n",
57 "string = widgets.TextBoxWidget(value='hi')\n",
58 "container = widgets.ContainerWidget(children=[floatrange, string])\n",
58 "container = widgets.ContainerWidget(children=[float_range, string])\n",
59 "\n",
59 "\n",
60 "display(container) # Displays the `container` and all of it's children."
60 "display(container) # Displays the `container` and all of it's children."
61 ],
61 ],
@@ -78,8 +78,8 b''
78 "container = widgets.ContainerWidget()\n",
78 "container = widgets.ContainerWidget()\n",
79 "display(container)\n",
79 "display(container)\n",
80 "\n",
80 "\n",
81 "intrange = widgets.IntSliderWidget()\n",
81 "int_range = widgets.IntSliderWidget()\n",
82 "container.children=[intrange]\n"
82 "container.children=[int_range]\n"
83 ],
83 ],
84 "language": "python",
84 "language": "python",
85 "metadata": {},
85 "metadata": {},
@@ -98,7 +98,8 b''
98 "cell_type": "markdown",
98 "cell_type": "markdown",
99 "metadata": {},
99 "metadata": {},
100 "source": [
100 "source": [
101 "Sometimes it's necessary to hide/show widget views in place, without having to redisplay the widget views. The `visibility` property of widgets can be used to hide/show widgets that have already been displayed (as seen below)."
101 "Sometimes it is necessary to hide or show widgets in place, without having to redisplay the widget.\n",
102 "The `visibility` property of widgets can be used to hide or show widgets that have already been displayed (as seen below)."
102 ]
103 ]
103 },
104 },
104 {
105 {
@@ -139,7 +140,7 b''
139 "cell_type": "markdown",
140 "cell_type": "markdown",
140 "metadata": {},
141 "metadata": {},
141 "source": [
142 "source": [
142 "In the example below, a form is rendered which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox."
143 "In the example below, a form is rendered, which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox."
143 ]
144 ]
144 },
145 },
145 {
146 {
@@ -44,7 +44,11 b''
44 "cell_type": "markdown",
44 "cell_type": "markdown",
45 "metadata": {},
45 "metadata": {},
46 "source": [
46 "source": [
47 "When trying to design an attractive widget GUI, styling becomes important. Most Widgets views are DOM (document object model) elements that can be controlled with CSS. There are two helper methods defined on widget that allow the manipulation of the widget's CSS. The first is the `set_css` method, whos doc string is displayed below. This method allows one or more CSS attributes to be set at once. "
47 "When trying to design an attractive widget GUI, styling becomes important.\n",
48 "Most widget views are DOM (document object model) elements that can be controlled with CSS.\n",
49 "There are two helper methods that allow the manipulation of the widget's CSS.\n",
50 "The first is the `Widget.set_css` method.\n",
51 "This method allows one or more CSS attributes to be set at once. "
48 ]
52 ]
49 },
53 },
50 {
54 {
@@ -72,9 +76,9 b''
72 " CSS key/value pairs to apply\n",
76 " CSS key/value pairs to apply\n",
73 " key: unicode\n",
77 " key: unicode\n",
74 " CSS key\n",
78 " CSS key\n",
75 " value\n",
79 " value:\n",
76 " CSS value\n",
80 " CSS value\n",
77 " selector: unicode (optional)\n",
81 " selector: unicode (optional, kwarg only)\n",
78 " JQuery selector to use to apply the CSS key/value. If no selector \n",
82 " JQuery selector to use to apply the CSS key/value. If no selector \n",
79 " is provided, an empty selector is used. An empty selector makes the \n",
83 " is provided, an empty selector is used. An empty selector makes the \n",
80 " front-end try to apply the css to a default element. The default\n",
84 " front-end try to apply the css to a default element. The default\n",
@@ -91,7 +95,8 b''
91 "cell_type": "markdown",
95 "cell_type": "markdown",
92 "metadata": {},
96 "metadata": {},
93 "source": [
97 "source": [
94 "The second is `get_css` which allows CSS attributes that have been set to be read. Note that this method will only read CSS attributes that have been set using the `set_css` method. `get_css`'s doc string is displayed below."
98 "The second is `get_css` which allows CSS attributesto be read.\n",
99 "Note that this method will only read CSS attributes that have been set using the `set_css` method."
95 ]
100 ]
96 },
101 },
97 {
102 {
@@ -158,14 +163,17 b''
158 "level": 1,
163 "level": 1,
159 "metadata": {},
164 "metadata": {},
160 "source": [
165 "source": [
161 "DOM Classes"
166 "CSS Classes"
162 ]
167 ]
163 },
168 },
164 {
169 {
165 "cell_type": "markdown",
170 "cell_type": "markdown",
166 "metadata": {},
171 "metadata": {},
167 "source": [
172 "source": [
168 "In some cases it's necessary to apply DOM classes to your widgets. DOM classes allow DOM elements to be indentified by Javascript and CSS. The notebook defines its own set of classes to stylize its elements. The `add_class` widget method allows you to add DOM classes to your widget's definition. The `add_class` method's doc string can be seen below."
173 "In some cases, it is necessary to apply CSS classes to your widgets.\n",
174 "CSS classes allow DOM elements to be indentified in Javascript and CSS.\n",
175 "The notebook defines its own set of classes to stylize its elements.\n",
176 "The `add_class` widget method allows you to add CSS classes to your widget."
169 ]
177 ]
170 },
178 },
171 {
179 {
@@ -200,7 +208,9 b''
200 "cell_type": "markdown",
208 "cell_type": "markdown",
201 "metadata": {},
209 "metadata": {},
202 "source": [
210 "source": [
203 "Since `add_class` if a DOM operation, **it will only affect widgets that have already been displayed**. `add_class` must be called after the widget has been displayed. Extending the example above, the corners of the container can be rounded by adding the `corner-all` notebook class to the container (as seen below). "
211 "Since `add_class` is a DOM operation, **it will only affect widgets that have already been displayed**.\n",
212 "`add_class` must be called after the widget has been displayed.\n",
213 "Extending the example above, the corners of the container can be rounded by adding the `corner-all` CSS class to the container."
204 ]
214 ]
205 },
215 },
206 {
216 {
@@ -227,7 +237,8 b''
227 "cell_type": "markdown",
237 "cell_type": "markdown",
228 "metadata": {},
238 "metadata": {},
229 "source": [
239 "source": [
230 "The IPython notebook uses bootstrap for styling. The example above can be simplified by using a bootstrap class (as seen below). Bootstrap documentation can be found at http://getbootstrap.com/\u200e ."
240 "The IPython notebook uses [bootstrap](http://getbootstrap.com/\u200e) for styling.\n",
241 "The example above can be simplified by using a bootstrap class:"
231 ]
242 ]
232 },
243 },
233 {
244 {
@@ -279,7 +290,9 b''
279 "cell_type": "markdown",
290 "cell_type": "markdown",
280 "metadata": {},
291 "metadata": {},
281 "source": [
292 "source": [
282 "It's also useful to be able to remove DOM classes from widgets. The `remove_class` widget method allows you to remove classes from widgets that have been displayed. Like `add_class`, it must be called after the widget has been displayed. The doc string of `remove_class` can be seen below."
293 "It is also useful to be able to remove CSS classes from widgets.\n",
294 "The `remove_class` method allows you to remove classes from widgets that have been displayed.\n",
295 "Like `add_class`, it must be called after the widget has been displayed."
283 ]
296 ]
284 },
297 },
285 {
298 {
@@ -44,7 +44,9 b''
44 "cell_type": "markdown",
44 "cell_type": "markdown",
45 "metadata": {},
45 "metadata": {},
46 "source": [
46 "source": [
47 "Most widgets have a `description` property which allows a label for the widget to be defined. The label of the widget has a fixed minimum width. The text of the label is always right aligned and the widget is left aligned (as seen below) "
47 "Most widgets have a `description` attribute, which allows a label for the widget to be defined.\n",
48 "The label of the widget has a fixed minimum width.\n",
49 "The text of the label is always right aligned and the widget is left aligned:"
48 ]
50 ]
49 },
51 },
50 {
52 {
@@ -58,13 +60,13 b''
58 "language": "python",
60 "language": "python",
59 "metadata": {},
61 "metadata": {},
60 "outputs": [],
62 "outputs": [],
61 "prompt_number": 2
63 "prompt_number": 3
62 },
64 },
63 {
65 {
64 "cell_type": "markdown",
66 "cell_type": "markdown",
65 "metadata": {},
67 "metadata": {},
66 "source": [
68 "source": [
67 "If a label is longer than the minimum width, the widget is shifted to the right (as seen below)."
69 "If a label is longer than the minimum width, the widget is shifted to the right:"
68 ]
70 ]
69 },
71 },
70 {
72 {
@@ -79,13 +81,13 b''
79 "language": "python",
81 "language": "python",
80 "metadata": {},
82 "metadata": {},
81 "outputs": [],
83 "outputs": [],
82 "prompt_number": 3
84 "prompt_number": 4
83 },
85 },
84 {
86 {
85 "cell_type": "markdown",
87 "cell_type": "markdown",
86 "metadata": {},
88 "metadata": {},
87 "source": [
89 "source": [
88 "If a `description` is not set for the widget, the label is not displayed (as seen below)."
90 "If a `description` is not set for the widget, the label is not displayed:"
89 ]
91 ]
90 },
92 },
91 {
93 {
@@ -100,7 +102,7 b''
100 "language": "python",
102 "language": "python",
101 "metadata": {},
103 "metadata": {},
102 "outputs": [],
104 "outputs": [],
103 "prompt_number": 4
105 "prompt_number": 5
104 },
106 },
105 {
107 {
106 "cell_type": "heading",
108 "cell_type": "heading",
@@ -114,7 +116,8 b''
114 "cell_type": "markdown",
116 "cell_type": "markdown",
115 "metadata": {},
117 "metadata": {},
116 "source": [
118 "source": [
117 "`ContainerWidget`s allow for custom alignment of widgets. The `hbox` and `vbox` DOM classes cause the `ContainerWidget` to both horizontally and vertically align its children. The following example compares `vbox` to `hbox`."
119 "`ContainerWidget`s allow for custom alignment of widgets.\n",
120 "The `hbox` and `vbox` CSS classes cause the `ContainerWidget` to horizontally or vertically align its children."
118 ]
121 ]
119 },
122 },
120 {
123 {
@@ -161,13 +164,14 b''
161 "language": "python",
164 "language": "python",
162 "metadata": {},
165 "metadata": {},
163 "outputs": [],
166 "outputs": [],
164 "prompt_number": 5
167 "prompt_number": 6
165 },
168 },
166 {
169 {
167 "cell_type": "markdown",
170 "cell_type": "markdown",
168 "metadata": {},
171 "metadata": {},
169 "source": [
172 "source": [
170 "The `start`, `center`, and `end` DOM classes adjust the alignment of the widgets on the axis that they are being rendered on. Below is an example of the different alignments."
173 "The `start`, `center`, and `end` classes adjust the alignment of the widgets on the axis where they are being rendered.\n",
174 "Below is an example of the different alignments."
171 ]
175 ]
172 },
176 },
173 {
177 {
@@ -19,7 +19,7 b''
19 "source": [
19 "source": [
20 "[< Back to Part 5](Part 5 - Alignment.ipynb) or [Index](index.ipynb)\n",
20 "[< Back to Part 5](Part 5 - Alignment.ipynb) or [Index](index.ipynb)\n",
21 "\n",
21 "\n",
22 "Before reading, the author recommends the reader to review\n",
22 "Before reading, make sure to review\n",
23 "\n",
23 "\n",
24 "- [MVC prgramming](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)\n",
24 "- [MVC prgramming](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)\n",
25 "- [Backbone.js](https://www.codeschool.com/courses/anatomy-of-backbonejs)\n",
25 "- [Backbone.js](https://www.codeschool.com/courses/anatomy-of-backbonejs)\n",
@@ -33,9 +33,9 b''
33 "input": [
33 "input": [
34 "from __future__ import print_function # For py 2.7 compat\n",
34 "from __future__ import print_function # For py 2.7 compat\n",
35 "\n",
35 "\n",
36 "from IPython.html import widgets # Widget definitions.\n",
36 "from IPython.html import widgets # Widget definitions\n",
37 "from IPython.display import display # Used to display widgets in the notebook.\n",
37 "from IPython.display import display # Used to display widgets in the notebook\n",
38 "from IPython.utils.traitlets import Unicode # Used to declare properties of our widget."
38 "from IPython.utils.traitlets import Unicode # Used to declare attributes of our widget"
39 ],
39 ],
40 "language": "python",
40 "language": "python",
41 "metadata": {},
41 "metadata": {},
@@ -54,7 +54,10 b''
54 "cell_type": "markdown",
54 "cell_type": "markdown",
55 "metadata": {},
55 "metadata": {},
56 "source": [
56 "source": [
57 "This notebook implements a custom date picker widget. The purpose of this notebook is to demonstrate the widget creation process. To create a custom widget, custom Python and JavaScript is required."
57 "This notebook implements a custom date picker widget,\n",
58 "in order to demonstrate the widget creation process.\n",
59 "\n",
60 "To create a custom widget, both Python and JavaScript code is required."
58 ]
61 ]
59 },
62 },
60 {
63 {
@@ -77,7 +80,10 b''
77 "cell_type": "markdown",
80 "cell_type": "markdown",
78 "metadata": {},
81 "metadata": {},
79 "source": [
82 "source": [
80 "When starting a project like this, it is often easiest to make an overly simplified base to verify that the underlying framework is working as expected. To start we will create an empty widget and make sure that it can be rendered. The first step is to create the widget in Python."
83 "When starting a project like this, it is often easiest to make a simple base implementation,\n",
84 "to verify that the underlying framework is working as expected.\n",
85 "To start, we will create an empty widget and make sure that it can be rendered.\n",
86 "The first step is to define the widget in Python."
81 ]
87 ]
82 },
88 },
83 {
89 {
@@ -96,7 +102,9 b''
96 "cell_type": "markdown",
102 "cell_type": "markdown",
97 "metadata": {},
103 "metadata": {},
98 "source": [
104 "source": [
99 "Our widget inherits from `widgets.DOMWidget` since it is intended that it will be displayed in the notebook directly. The `_view_name` trait is specially named, the widget framework will read the `_view_name` trait to determine what Backbone view the widget is associated with. **Using `sync=True` is very important** because it tells the widget framework that that specific traitlet should be synced between the front- and back-ends."
105 "Our widget inherits from `widgets.DOMWidget` since it is intended that it will be displayed in the notebook directly.\n",
106 "The `_view_name` trait is special; the widget framework will read the `_view_name` trait to determine what Backbone view the widget is associated with.\n",
107 "**Using `sync=True` is very important** because it tells the widget framework that that specific traitlet should be synced between the front- and back-ends."
100 ]
108 ]
101 },
109 },
102 {
110 {
@@ -111,7 +119,10 b''
111 "cell_type": "markdown",
119 "cell_type": "markdown",
112 "metadata": {},
120 "metadata": {},
113 "source": [
121 "source": [
114 "In the IPython notebook [require.js](http://requirejs.org/) is used to load JavaScript dependencies. All IPython widget code depends on `notebook/js/widgets/widget.js`. In it the base widget model and base view are defined. We need to use require.js to include this file:"
122 "In the IPython notebook [require.js](http://requirejs.org/) is used to load JavaScript dependencies.\n",
123 "All IPython widget code depends on `notebook/js/widgets/widget.js`,\n",
124 "where the base widget model and base view are defined.\n",
125 "We use require.js to load this file:"
115 ]
126 ]
116 },
127 },
117 {
128 {
@@ -137,7 +148,7 b''
137 "metadata": {},
148 "metadata": {},
138 "output_type": "display_data",
149 "output_type": "display_data",
139 "text": [
150 "text": [
140 "<IPython.core.display.Javascript at 0x2a2e0d0>"
151 "<IPython.core.display.Javascript at 0x109491690>"
141 ]
152 ]
142 }
153 }
143 ],
154 ],
@@ -147,7 +158,12 b''
147 "cell_type": "markdown",
158 "cell_type": "markdown",
148 "metadata": {},
159 "metadata": {},
149 "source": [
160 "source": [
150 "Now we need to define a view that can be used to represent the model. To do this, the `IPython.DOMWidgetView` is extended. A render function must be defined. The render function is used to render a widget view instance to the DOM. For now the render function renders a div that contains the text *Hello World!* Lastly, the view needs to be registered with the widget manager.\n",
161 "Now we need to define a view that can be used to represent the model.\n",
162 "To do this, the `IPython.DOMWidgetView` is extended.\n",
163 "**A render function must be defined**.\n",
164 "The render function is used to render a widget view instance to the DOM.\n",
165 "For now, the render function renders a div that contains the text *Hello World!*\n",
166 "Lastly, the view needs to be registered with the widget manager.\n",
151 "\n",
167 "\n",
152 "**Final JavaScript code below:**"
168 "**Final JavaScript code below:**"
153 ]
169 ]
@@ -189,7 +205,7 b''
189 "metadata": {},
205 "metadata": {},
190 "output_type": "display_data",
206 "output_type": "display_data",
191 "text": [
207 "text": [
192 "<IPython.core.display.Javascript at 0x2a2e3d0>"
208 "<IPython.core.display.Javascript at 0x1094917d0>"
193 ]
209 ]
194 }
210 }
195 ],
211 ],
@@ -207,7 +223,7 b''
207 "cell_type": "markdown",
223 "cell_type": "markdown",
208 "metadata": {},
224 "metadata": {},
209 "source": [
225 "source": [
210 "To test, create the widget the same way that the other widgets are created."
226 "To test what we have so far, create the widget, just like you would the builtin widgets:"
211 ]
227 ]
212 },
228 },
213 {
229 {
@@ -241,7 +257,11 b''
241 "cell_type": "markdown",
257 "cell_type": "markdown",
242 "metadata": {},
258 "metadata": {},
243 "source": [
259 "source": [
244 "In the last section we created a simple widget that displayed *Hello World!* To make an actual date widget, we need to add a property that will be synced between the Python model and the JavaScript model. The new property must be a traitlet property so the widget machinery can automatically handle it. The property needs to be constructed with a `sync=True` keyword argument so the widget machinery knows to syncronize it with the front-end. Adding this to the code from the last section:"
260 "In the last section we created a simple widget that displayed *Hello World!*\n",
261 "To make an actual date widget, we need to add a property that will be synced between the Python model and the JavaScript model.\n",
262 "The new attribute must be a traitlet, so the widget machinery can handle it.\n",
263 "The traitlet must be constructed with a `sync=True` keyword argument, to tell the widget machinery knows to synchronize it with the front-end.\n",
264 "Adding this to the code from the last section:"
245 ]
265 ]
246 },
266 },
247 {
267 {
@@ -269,7 +289,10 b''
269 "cell_type": "markdown",
289 "cell_type": "markdown",
270 "metadata": {},
290 "metadata": {},
271 "source": [
291 "source": [
272 "In the JavaScript there is no need to define counterparts to the traitlets. When the JavaScript model is created for the first time, it copies all of the traitlet `sync=True` attributes from the Python model. We need to replace *Hello World!* with an actual HTML date picker widget."
292 "In the JavaScript, there is no need to define counterparts to the traitlets.\n",
293 "When the JavaScript model is created for the first time,\n",
294 "it copies all of the traitlet `sync=True` attributes from the Python model.\n",
295 "We need to replace *Hello World!* with an actual HTML date picker widget."
273 ]
296 ]
274 },
297 },
275 {
298 {
@@ -321,7 +344,7 b''
321 "metadata": {},
344 "metadata": {},
322 "output_type": "display_data",
345 "output_type": "display_data",
323 "text": [
346 "text": [
324 "<IPython.core.display.Javascript at 0x2a2e6d0>"
347 "<IPython.core.display.Javascript at 0x109491750>"
325 ]
348 ]
326 }
349 }
327 ],
350 ],
@@ -397,7 +420,7 b''
397 "metadata": {},
420 "metadata": {},
398 "output_type": "display_data",
421 "output_type": "display_data",
399 "text": [
422 "text": [
400 "<IPython.core.display.Javascript at 0x2a2e090>"
423 "<IPython.core.display.Javascript at 0x109491750>"
401 ]
424 ]
402 }
425 }
403 ],
426 ],
@@ -407,7 +430,11 b''
407 "cell_type": "markdown",
430 "cell_type": "markdown",
408 "metadata": {},
431 "metadata": {},
409 "source": [
432 "source": [
410 "To get the changed value from the front-end to publish itself to the back-end, we need to listen to the change event triggered by the HTM date control and set the value in the model. After the date change event fires and the new value is set in the model, it's very important that we call `this.touch()` to let the widget machinery know which view changed the model. This is important because the widget machinery needs to know which cell to route the message callbacks to.\n",
433 "To get the changed value from the frontend to publish itself to the backend,\n",
434 "we need to listen to the change event triggered by the HTM date control and set the value in the model.\n",
435 "After the date change event fires and the new value is set in the model,\n",
436 "it is very important that we call `this.touch()` to let the widget machinery know which view changed the model.\n",
437 "This is important because the widget machinery needs to know which cell to route the message callbacks to.\n",
411 "\n",
438 "\n",
412 "**Final JavaScript code below:**"
439 "**Final JavaScript code below:**"
413 ]
440 ]
@@ -495,7 +522,7 b''
495 "metadata": {},
522 "metadata": {},
496 "output_type": "display_data",
523 "output_type": "display_data",
497 "text": [
524 "text": [
498 "<IPython.core.display.Javascript at 0x2a2e750>"
525 "<IPython.core.display.Javascript at 0x109491b10>"
499 ]
526 ]
500 }
527 }
501 ],
528 ],
@@ -567,7 +594,7 b''
567 "output_type": "pyout",
594 "output_type": "pyout",
568 "prompt_number": 12,
595 "prompt_number": 12,
569 "text": [
596 "text": [
570 "u'2014-01-01'"
597 "u''"
571 ]
598 ]
572 }
599 }
573 ],
600 ],
@@ -584,7 +611,7 b''
584 "cell_type": "code",
611 "cell_type": "code",
585 "collapsed": false,
612 "collapsed": false,
586 "input": [
613 "input": [
587 "my_widget.value = \"1998-12-01\" # December 1st, 1999"
614 "my_widget.value = \"1998-12-01\" # December 1st, 1998"
588 ],
615 ],
589 "language": "python",
616 "language": "python",
590 "metadata": {},
617 "metadata": {},
@@ -622,7 +649,10 b''
622 "cell_type": "markdown",
649 "cell_type": "markdown",
623 "metadata": {},
650 "metadata": {},
624 "source": [
651 "source": [
625 "In the last section we created a fully working date picker widget. Now we will add custom validation and support for labels. Currently only the ISO date format \"YYYY-MM-DD\" is supported. We will add support for all of the date formats recognized by the 3rd party Python dateutil library."
652 "In the last section we created a fully working date picker widget.\n",
653 "Now we will add custom validation and support for labels.\n",
654 "So far, only the ISO date format \"YYYY-MM-DD\" is supported.\n",
655 "Now, we will add support for all of the date formats recognized by the Python dateutil library."
626 ]
656 ]
627 },
657 },
628 {
658 {
@@ -637,7 +667,8 b''
637 "cell_type": "markdown",
667 "cell_type": "markdown",
638 "metadata": {},
668 "metadata": {},
639 "source": [
669 "source": [
640 "The standard property name used for widget labels is `description`. In the code block below, `description` has been added to the Python widget."
670 "The standard property name used for widget labels is `description`.\n",
671 "In the code block below, `description` has been added to the Python widget."
641 ]
672 ]
642 },
673 },
643 {
674 {
@@ -658,7 +689,9 b''
658 "cell_type": "markdown",
689 "cell_type": "markdown",
659 "metadata": {},
690 "metadata": {},
660 "source": [
691 "source": [
661 "The traitlet machinery searches the class that the trait is defined in for methods with \"`_changed`\" suffixed onto their names. Any method with the format \"`X_changed`\" will be called when \"`X`\" is modified. We can take advantage of this to perform validation and parsing of different date string formats. Below a method that listens to value has been added to the DateWidget."
692 "The traitlet machinery searches the class that the trait is defined in for methods with \"`_changed`\" suffixed onto their names. Any method with the format \"`_X_changed`\" will be called when \"`X`\" is modified.\n",
693 "We can take advantage of this to perform validation and parsing of different date string formats.\n",
694 "Below, a method that listens to value has been added to the DateWidget."
662 ]
695 ]
663 },
696 },
664 {
697 {
@@ -684,7 +717,8 b''
684 "cell_type": "markdown",
717 "cell_type": "markdown",
685 "metadata": {},
718 "metadata": {},
686 "source": [
719 "source": [
687 "Now the function that parses the date string and only sets it in the correct format can be added."
720 "Now the function parses the date string,\n",
721 "and only sets the value in the correct format."
688 ]
722 ]
689 },
723 },
690 {
724 {
@@ -720,7 +754,9 b''
720 "cell_type": "markdown",
754 "cell_type": "markdown",
721 "metadata": {},
755 "metadata": {},
722 "source": [
756 "source": [
723 "Finally, a `CallbackDispatcher` is added so the user can perform custom validation. If any one of the callbacks registered with the dispatcher returns False, the new date time is not set.\n",
757 "Finally, a `CallbackDispatcher` is added so the user can perform custom validation.\n",
758 "If any one of the callbacks registered with the dispatcher returns False,\n",
759 "the new date is not set.\n",
724 "\n",
760 "\n",
725 "**Final Python code below:**"
761 "**Final Python code below:**"
726 ]
762 ]
@@ -737,10 +773,7 b''
737 " def __init__(self, **kwargs):\n",
773 " def __init__(self, **kwargs):\n",
738 " super(DateWidget, self).__init__(**kwargs)\n",
774 " super(DateWidget, self).__init__(**kwargs)\n",
739 " \n",
775 " \n",
740 " # Specify the number of positional arguments supported. For \n",
776 " self.validate = widgets.CallbackDispatcher()\n",
741 " # validation we only are worried about one parameter, the\n",
742 " # new value that should be validated.\n",
743 " self.validation = widgets.CallbackDispatcher(acceptable_nargs=[1])\n",
744 " \n",
777 " \n",
745 " # This function automatically gets called by the traitlet machinery when\n",
778 " # This function automatically gets called by the traitlet machinery when\n",
746 " # value is modified because of this function's name.\n",
779 " # value is modified because of this function's name.\n",
@@ -755,8 +788,8 b''
755 " \n",
788 " \n",
756 " # Set the parsed date string if the current date string is different.\n",
789 " # Set the parsed date string if the current date string is different.\n",
757 " if old_value != new_value:\n",
790 " if old_value != new_value:\n",
758 " validation = self.validation(parsed_date)\n",
791 " valid = self.validate(parsed_date)\n",
759 " if validation is None or validation == True:\n",
792 " if valid in (None, True):\n",
760 " self.value = parsed_date_string\n",
793 " self.value = parsed_date_string\n",
761 " else:\n",
794 " else:\n",
762 " self.value = old_value\n",
795 " self.value = old_value\n",
@@ -781,7 +814,12 b''
781 "cell_type": "markdown",
814 "cell_type": "markdown",
782 "metadata": {},
815 "metadata": {},
783 "source": [
816 "source": [
784 "Using the Javascript code from the last section, we add a label to the date time object. The label is a div with the `widget-hlabel` class applied to it. The `widget-hlabel` is a class provided by the widget framework that applies special styling to a div to make it look like the rest of the horizontal labels used with the built in widgets. Similar to the `widget-hlabel` class is the `widget-hbox-single` class. The `widget-hbox-single` class applies special styling to widget containers that store a single line horizontal widget. \n",
817 "Using the Javascript code from the last section,\n",
818 "we add a label to the date time object.\n",
819 "The label is a div with the `widget-hlabel` class applied to it.\n",
820 "`widget-hlabel` is a class provided by the widget framework that applies special styling to a div to make it look like the rest of the horizontal labels used with the built-in widgets.\n",
821 "Similar to the `widget-hlabel` class is the `widget-hbox-single` class.\n",
822 "The `widget-hbox-single` class applies special styling to widget containers that store a single line horizontal widget.\n",
785 "\n",
823 "\n",
786 "We hide the label if the description value is blank."
824 "We hide the label if the description value is blank."
787 ]
825 ]
@@ -792,7 +830,6 b''
792 "input": [
830 "input": [
793 "%%javascript\n",
831 "%%javascript\n",
794 "\n",
832 "\n",
795 "\n",
796 "require([\"notebook/js/widgets/widget\"], function(WidgetManager){\n",
833 "require([\"notebook/js/widgets/widget\"], function(WidgetManager){\n",
797 " \n",
834 " \n",
798 " // Define the DatePickerView\n",
835 " // Define the DatePickerView\n",
@@ -849,7 +886,6 b''
849 {
886 {
850 "javascript": [
887 "javascript": [
851 "\n",
888 "\n",
852 "\n",
853 "require([\"notebook/js/widgets/widget\"], function(WidgetManager){\n",
889 "require([\"notebook/js/widgets/widget\"], function(WidgetManager){\n",
854 " \n",
890 " \n",
855 " // Define the DatePickerView\n",
891 " // Define the DatePickerView\n",
@@ -903,7 +939,7 b''
903 "metadata": {},
939 "metadata": {},
904 "output_type": "display_data",
940 "output_type": "display_data",
905 "text": [
941 "text": [
906 "<IPython.core.display.Javascript at 0x2a5a6d0>"
942 "<IPython.core.display.Javascript at 0x1094eef90>"
907 ]
943 ]
908 }
944 }
909 ],
945 ],
@@ -955,9 +991,9 b''
955 "my_widget = DateWidget()\n",
991 "my_widget = DateWidget()\n",
956 "display(my_widget)\n",
992 "display(my_widget)\n",
957 "\n",
993 "\n",
958 "def validate_date(date):\n",
994 "def require_2014(date):\n",
959 " return not date is None and date.year == 2014\n",
995 " return not date is None and date.year == 2014\n",
960 "my_widget.validation.register_callback(validate_date)"
996 "my_widget.validate.register_callback(require_2014)"
961 ],
997 ],
962 "language": "python",
998 "language": "python",
963 "metadata": {},
999 "metadata": {},
@@ -20,7 +20,7 b''
20 "level": 2,
20 "level": 2,
21 "metadata": {},
21 "metadata": {},
22 "source": [
22 "source": [
23 "A short example implementation."
23 "A short example implementation"
24 ]
24 ]
25 },
25 },
26 {
26 {
@@ -34,13 +34,23 b''
34 "cell_type": "code",
34 "cell_type": "code",
35 "collapsed": false,
35 "collapsed": false,
36 "input": [
36 "input": [
37 "from IPython.html import widgets # Loads the Widget framework.\n",
38 "from IPython.core.magics.namespace import NamespaceMagics # Used to query namespace.\n",
39 "\n",
40 "# For this example, hide these names, just to avoid polluting the namespace further\n",
41 "get_ipython().user_ns_hidden['widgets'] = widgets\n",
42 "get_ipython().user_ns_hidden['NamespaceMagics'] = NamespaceMagics"
43 ],
44 "language": "python",
45 "metadata": {},
46 "outputs": [],
47 "prompt_number": 1
48 },
49 {
50 "cell_type": "code",
51 "collapsed": false,
52 "input": [
37 "class VariableInspectorWindow(object):\n",
53 "class VariableInspectorWindow(object):\n",
38 " \n",
39 " # For this example file, the import sit inside the class, just to avoid poluting \n",
40 " # the namespace further.\n",
41 " from IPython.html import widgets # Loads the Widget framework.\n",
42 " from IPython.core.magics.namespace import NamespaceMagics # Used to query namespace.\n",
43 " \n",
44 " instance = None\n",
54 " instance = None\n",
45 " \n",
55 " \n",
46 " def __init__(self, ipython):\n",
56 " def __init__(self, ipython):\n",
@@ -53,21 +63,21 b''
53 " \n",
63 " \n",
54 " VariableInspectorWindow.instance = self\n",
64 " VariableInspectorWindow.instance = self\n",
55 " self.closed = False\n",
65 " self.closed = False\n",
56 " self.namespace = self.NamespaceMagics()\n",
66 " self.namespace = NamespaceMagics()\n",
57 " self.namespace.shell = ipython.kernel.shell\n",
67 " self.namespace.shell = ipython.kernel.shell\n",
58 " \n",
68 " \n",
59 " self._popout = self.widgets.PopupWidget()\n",
69 " self._popout = widgets.PopupWidget()\n",
60 " self._popout.description = \"Variable Inspector\"\n",
70 " self._popout.description = \"Variable Inspector\"\n",
61 " self._popout.button_text = self._popout.description\n",
71 " self._popout.button_text = self._popout.description\n",
62 "\n",
72 "\n",
63 " self._modal_body = self.widgets.ContainerWidget()\n",
73 " self._modal_body = widgets.ContainerWidget()\n",
64 " self._modal_body.set_css('overflow-y', 'scroll')\n",
74 " self._modal_body.set_css('overflow-y', 'scroll')\n",
65 "\n",
75 "\n",
66 " self._modal_body_label = self.widgets.HTMLWidget(value = 'Not hooked')\n",
76 " self._modal_body_label = widgets.HTMLWidget(value = 'Not hooked')\n",
67 " self._modal_body.children = [self._modal_body_label]\n",
77 " self._modal_body.children = [self._modal_body_label]\n",
68 "\n",
78 "\n",
69 " self._modal_footer = self.widgets.ContainerWidget()\n",
79 " self._modal_footer = widgets.ContainerWidget()\n",
70 " self._var_filter = self.widgets.ToggleButtonsWidget(description=\"Method:\", values=['List', 'Details'], value='List')\n",
80 " self._var_filter = widgets.ToggleButtonsWidget(description=\"Method:\", values=['List', 'Details'], value='List')\n",
71 " self._modal_footer.children = [self._var_filter]\n",
81 " self._modal_footer.children = [self._var_filter]\n",
72 "\n",
82 "\n",
73 " self._popout.children = [\n",
83 " self._popout.children = [\n",
@@ -109,7 +119,7 b''
109 "language": "python",
119 "language": "python",
110 "metadata": {},
120 "metadata": {},
111 "outputs": [],
121 "outputs": [],
112 "prompt_number": 17
122 "prompt_number": 2
113 },
123 },
114 {
124 {
115 "cell_type": "code",
125 "cell_type": "code",
@@ -121,7 +131,7 b''
121 "language": "python",
131 "language": "python",
122 "metadata": {},
132 "metadata": {},
123 "outputs": [],
133 "outputs": [],
124 "prompt_number": 18
134 "prompt_number": 3
125 },
135 },
126 {
136 {
127 "cell_type": "heading",
137 "cell_type": "heading",
@@ -140,7 +150,7 b''
140 "language": "python",
150 "language": "python",
141 "metadata": {},
151 "metadata": {},
142 "outputs": [],
152 "outputs": [],
143 "prompt_number": 11
153 "prompt_number": 4
144 },
154 },
145 {
155 {
146 "cell_type": "code",
156 "cell_type": "code",
@@ -151,7 +161,7 b''
151 "language": "python",
161 "language": "python",
152 "metadata": {},
162 "metadata": {},
153 "outputs": [],
163 "outputs": [],
154 "prompt_number": 12
164 "prompt_number": 5
155 },
165 },
156 {
166 {
157 "cell_type": "code",
167 "cell_type": "code",
@@ -162,7 +172,7 b''
162 "language": "python",
172 "language": "python",
163 "metadata": {},
173 "metadata": {},
164 "outputs": [],
174 "outputs": [],
165 "prompt_number": 13
175 "prompt_number": 6
166 },
176 },
167 {
177 {
168 "cell_type": "code",
178 "cell_type": "code",
@@ -173,7 +183,7 b''
173 "language": "python",
183 "language": "python",
174 "metadata": {},
184 "metadata": {},
175 "outputs": [],
185 "outputs": [],
176 "prompt_number": 14
186 "prompt_number": 7
177 },
187 },
178 {
188 {
179 "cell_type": "code",
189 "cell_type": "code",
@@ -184,384 +194,7 b''
184 "language": "python",
194 "language": "python",
185 "metadata": {},
195 "metadata": {},
186 "outputs": [],
196 "outputs": [],
187 "prompt_number": 15
197 "prompt_number": 8
188 },
189 {
190 "cell_type": "code",
191 "collapsed": false,
192 "input": [
193 "?"
194 ],
195 "language": "python",
196 "metadata": {},
197 "outputs": [],
198 "prompt_number": 16
199 },
200 {
201 "cell_type": "code",
202 "collapsed": false,
203 "input": [
204 "dir()"
205 ],
206 "language": "python",
207 "metadata": {},
208 "outputs": [
209 {
210 "metadata": {},
211 "output_type": "pyout",
212 "prompt_number": 15,
213 "text": [
214 "['In',\n",
215 " 'Out',\n",
216 " 'VariableInspectorWindow',\n",
217 " '_',\n",
218 " '_10',\n",
219 " '_14',\n",
220 " '__',\n",
221 " '___',\n",
222 " '__builtin__',\n",
223 " '__builtins__',\n",
224 " '__doc__',\n",
225 " '__name__',\n",
226 " '__package__',\n",
227 " '_dh',\n",
228 " '_i',\n",
229 " '_i1',\n",
230 " '_i10',\n",
231 " '_i11',\n",
232 " '_i12',\n",
233 " '_i13',\n",
234 " '_i14',\n",
235 " '_i15',\n",
236 " '_i2',\n",
237 " '_i3',\n",
238 " '_i4',\n",
239 " '_i5',\n",
240 " '_i6',\n",
241 " '_i7',\n",
242 " '_i8',\n",
243 " '_i9',\n",
244 " '_ih',\n",
245 " '_ii',\n",
246 " '_iii',\n",
247 " '_oh',\n",
248 " '_sh',\n",
249 " 'exit',\n",
250 " 'get_ipython',\n",
251 " 'quit',\n",
252 " 'widgets']"
253 ]
254 }
255 ],
256 "prompt_number": 15
257 },
258 {
259 "cell_type": "code",
260 "collapsed": false,
261 "input": [
262 "dir(get_ipython().kernel.shell)"
263 ],
264 "language": "python",
265 "metadata": {},
266 "outputs": [
267 {
268 "metadata": {},
269 "output_type": "pyout",
270 "prompt_number": 4,
271 "text": [
272 "['Completer',\n",
273 " 'CustomTB',\n",
274 " 'InteractiveTB',\n",
275 " 'SyntaxTB',\n",
276 " '__class__',\n",
277 " '__delattr__',\n",
278 " '__dict__',\n",
279 " '__doc__',\n",
280 " '__format__',\n",
281 " '__getattribute__',\n",
282 " '__hash__',\n",
283 " '__init__',\n",
284 " '__module__',\n",
285 " '__new__',\n",
286 " '__reduce__',\n",
287 " '__reduce_ex__',\n",
288 " '__repr__',\n",
289 " '__setattr__',\n",
290 " '__sizeof__',\n",
291 " '__str__',\n",
292 " '__subclasshook__',\n",
293 " '__weakref__',\n",
294 " '_add_notifiers',\n",
295 " '_call_pdb',\n",
296 " '_config_changed',\n",
297 " '_exit_now_changed',\n",
298 " '_exiter_default',\n",
299 " '_find_my_config',\n",
300 " '_format_user_obj',\n",
301 " '_get_call_pdb',\n",
302 " '_get_exc_info',\n",
303 " '_indent_current_str',\n",
304 " '_inspect',\n",
305 " '_instance',\n",
306 " '_ipython_dir_changed',\n",
307 " '_last_input_line',\n",
308 " '_load_config',\n",
309 " '_main_mod_cache',\n",
310 " '_notify_trait',\n",
311 " '_object_find',\n",
312 " '_ofind',\n",
313 " '_ofind_property',\n",
314 " '_orig_sys_module_state',\n",
315 " '_orig_sys_modules_main_mod',\n",
316 " '_orig_sys_modules_main_name',\n",
317 " '_post_execute',\n",
318 " '_prompt_in1_changed',\n",
319 " '_prompt_in2_changed',\n",
320 " '_prompt_out_changed',\n",
321 " '_prompt_pad_left_changed',\n",
322 " '_prompt_trait_changed',\n",
323 " '_remove_notifiers',\n",
324 " '_reply_content',\n",
325 " '_run_cached_cell_magic',\n",
326 " '_set_call_pdb',\n",
327 " '_showtraceback',\n",
328 " '_trait_dyn_inits',\n",
329 " '_trait_notifiers',\n",
330 " '_trait_values',\n",
331 " '_user_obj_error',\n",
332 " '_walk_mro',\n",
333 " 'alias_manager',\n",
334 " 'all_ns_refs',\n",
335 " 'ask_exit',\n",
336 " 'ask_yes_no',\n",
337 " 'ast_node_interactivity',\n",
338 " 'ast_transformers',\n",
339 " 'atexit_operations',\n",
340 " 'auto_rewrite_input',\n",
341 " 'autocall',\n",
342 " 'autoindent',\n",
343 " 'automagic',\n",
344 " 'builtin_trap',\n",
345 " 'cache_size',\n",
346 " 'call_pdb',\n",
347 " 'class_config_section',\n",
348 " 'class_get_help',\n",
349 " 'class_get_trait_help',\n",
350 " 'class_print_help',\n",
351 " 'class_trait_names',\n",
352 " 'class_traits',\n",
353 " 'cleanup',\n",
354 " 'clear_instance',\n",
355 " 'clear_main_mod_cache',\n",
356 " 'color_info',\n",
357 " 'colors',\n",
358 " 'colors_force',\n",
359 " 'comm_manager',\n",
360 " 'compile',\n",
361 " 'complete',\n",
362 " 'config',\n",
363 " 'configurables',\n",
364 " 'custom_exceptions',\n",
365 " 'data_pub',\n",
366 " 'data_pub_class',\n",
367 " 'db',\n",
368 " 'debug',\n",
369 " 'debugger',\n",
370 " 'deep_reload',\n",
371 " 'default_user_namespaces',\n",
372 " 'define_macro',\n",
373 " 'define_magic',\n",
374 " 'del_var',\n",
375 " 'dir_stack',\n",
376 " 'disable_failing_post_execute',\n",
377 " 'display_formatter',\n",
378 " 'display_pub',\n",
379 " 'display_pub_class',\n",
380 " 'display_trap',\n",
381 " 'displayhook',\n",
382 " 'displayhook_class',\n",
383 " 'drop_by_id',\n",
384 " 'enable_gui',\n",
385 " 'enable_matplotlib',\n",
386 " 'enable_pylab',\n",
387 " 'ev',\n",
388 " 'ex',\n",
389 " 'excepthook',\n",
390 " 'execution_count',\n",
391 " 'exit_now',\n",
392 " 'exiter',\n",
393 " 'extension_manager',\n",
394 " 'extract_input_lines',\n",
395 " 'filename',\n",
396 " 'find_cell_magic',\n",
397 " 'find_line_magic',\n",
398 " 'find_magic',\n",
399 " 'find_user_code',\n",
400 " 'get_ipython',\n",
401 " 'get_parent',\n",
402 " 'getoutput',\n",
403 " 'has_readline',\n",
404 " 'history_length',\n",
405 " 'history_manager',\n",
406 " 'home_dir',\n",
407 " 'hooks',\n",
408 " 'indent_current_nsp',\n",
409 " 'init_alias',\n",
410 " 'init_builtins',\n",
411 " 'init_comms',\n",
412 " 'init_completer',\n",
413 " 'init_create_namespaces',\n",
414 " 'init_data_pub',\n",
415 " 'init_display_formatter',\n",
416 " 'init_display_pub',\n",
417 " 'init_displayhook',\n",
418 " 'init_encoding',\n",
419 " 'init_environment',\n",
420 " 'init_extension_manager',\n",
421 " 'init_history',\n",
422 " 'init_hooks',\n",
423 " 'init_inspector',\n",
424 " 'init_instance_attrs',\n",
425 " 'init_io',\n",
426 " 'init_ipython_dir',\n",
427 " 'init_latextool',\n",
428 " 'init_logger',\n",
429 " 'init_logstart',\n",
430 " 'init_magics',\n",
431 " 'init_payload',\n",
432 " 'init_pdb',\n",
433 " 'init_prefilter',\n",
434 " 'init_profile_dir',\n",
435 " 'init_prompts',\n",
436 " 'init_pushd_popd_magic',\n",
437 " 'init_readline',\n",
438 " 'init_syntax_highlighting',\n",
439 " 'init_sys_modules',\n",
440 " 'init_traceback_handlers',\n",
441 " 'init_user_ns',\n",
442 " 'init_virtualenv',\n",
443 " 'initialized',\n",
444 " 'input_splitter',\n",
445 " 'input_transformer_manager',\n",
446 " 'inspector',\n",
447 " 'instance',\n",
448 " 'ipython_dir',\n",
449 " 'keepkernel_on_exit',\n",
450 " 'kernel',\n",
451 " 'logappend',\n",
452 " 'logfile',\n",
453 " 'logger',\n",
454 " 'logstart',\n",
455 " 'magic',\n",
456 " 'magics_manager',\n",
457 " 'meta',\n",
458 " 'mktempfile',\n",
459 " 'more',\n",
460 " 'multiline_history',\n",
461 " 'new_main_mod',\n",
462 " 'ns_table',\n",
463 " 'object_info_string_level',\n",
464 " 'object_inspect',\n",
465 " 'on_trait_change',\n",
466 " 'parent',\n",
467 " 'parent_header',\n",
468 " 'payload_manager',\n",
469 " 'pdb',\n",
470 " 'pre_readline',\n",
471 " 'prefilter',\n",
472 " 'prefilter_manager',\n",
473 " 'prepare_user_module',\n",
474 " 'profile',\n",
475 " 'profile_dir',\n",
476 " 'prompt_in1',\n",
477 " 'prompt_in2',\n",
478 " 'prompt_manager',\n",
479 " 'prompt_out',\n",
480 " 'prompts_pad_left',\n",
481 " 'push',\n",
482 " 'pycolorize',\n",
483 " 'pylab_gui_select',\n",
484 " 'quiet',\n",
485 " 'raw_input_original',\n",
486 " 'readline',\n",
487 " 'readline_delims',\n",
488 " 'readline_no_record',\n",
489 " 'readline_parse_and_bind',\n",
490 " 'readline_remove_delims',\n",
491 " 'readline_use',\n",
492 " 'refill_readline_hist',\n",
493 " 'register_magic_function',\n",
494 " 'register_magics',\n",
495 " 'register_post_execute',\n",
496 " 'reset',\n",
497 " 'reset_selective',\n",
498 " 'restore_sys_module_state',\n",
499 " 'rl_do_indent',\n",
500 " 'rl_next_input',\n",
501 " 'run_ast_nodes',\n",
502 " 'run_cell',\n",
503 " 'run_cell_magic',\n",
504 " 'run_code',\n",
505 " 'run_line_magic',\n",
506 " 'runcode',\n",
507 " 'safe_execfile',\n",
508 " 'safe_execfile_ipy',\n",
509 " 'safe_run_module',\n",
510 " 'save_sys_module_state',\n",
511 " 'section_names',\n",
512 " 'separate_in',\n",
513 " 'separate_out',\n",
514 " 'separate_out2',\n",
515 " 'set_autoindent',\n",
516 " 'set_completer_frame',\n",
517 " 'set_custom_completer',\n",
518 " 'set_custom_exc',\n",
519 " 'set_hook',\n",
520 " 'set_next_input',\n",
521 " 'set_parent',\n",
522 " 'set_readline_completer',\n",
523 " 'show_rewritten_input',\n",
524 " 'show_usage',\n",
525 " 'show_usage_error',\n",
526 " 'showindentationerror',\n",
527 " 'showsyntaxerror',\n",
528 " 'showtraceback',\n",
529 " 'starting_dir',\n",
530 " 'stdin_encoding',\n",
531 " 'strdispatchers',\n",
532 " 'sys_excepthook',\n",
533 " 'system',\n",
534 " 'system_piped',\n",
535 " 'system_raw',\n",
536 " 'tempfiles',\n",
537 " 'trait_metadata',\n",
538 " 'trait_names',\n",
539 " 'traits',\n",
540 " 'transform_ast',\n",
541 " 'update_config',\n",
542 " 'user_expressions',\n",
543 " 'user_global_ns',\n",
544 " 'user_module',\n",
545 " 'user_ns',\n",
546 " 'user_ns_hidden',\n",
547 " 'user_variables',\n",
548 " 'var_expand',\n",
549 " 'wildcards_case_sensitive',\n",
550 " 'write',\n",
551 " 'write_err',\n",
552 " 'xmode']"
553 ]
554 }
555 ],
556 "prompt_number": 4
557 },
558 {
559 "cell_type": "code",
560 "collapsed": false,
561 "input": [],
562 "language": "python",
563 "metadata": {},
564 "outputs": []
565 }
198 }
566 ],
199 ],
567 "metadata": {}
200 "metadata": {}
General Comments 0
You need to be logged in to leave comments. Login now