Skip to content

Commit 2362ca5

Browse files
committed
Update widget exercises
1 parent 9d18853 commit 2362ca5

File tree

9 files changed

+80
-81
lines changed

9 files changed

+80
-81
lines changed

exercises/Interactive Widgets/Interact Exercises.ipynb

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 1,
12+
"execution_count": null,
1313
"metadata": {
1414
"collapsed": false
1515
},
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 2,
23+
"execution_count": null,
2424
"metadata": {
2525
"collapsed": false
2626
},
@@ -32,7 +32,7 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": 3,
35+
"execution_count": null,
3636
"metadata": {
3737
"collapsed": false
3838
},
@@ -60,7 +60,7 @@
6060
},
6161
{
6262
"cell_type": "code",
63-
"execution_count": 4,
63+
"execution_count": null,
6464
"metadata": {
6565
"collapsed": false
6666
},
@@ -90,7 +90,7 @@
9090
},
9191
{
9292
"cell_type": "code",
93-
"execution_count": 6,
93+
"execution_count": null,
9494
"metadata": {
9595
"collapsed": false
9696
},
@@ -116,7 +116,7 @@
116116
},
117117
{
118118
"cell_type": "code",
119-
"execution_count": 8,
119+
"execution_count": null,
120120
"metadata": {
121121
"collapsed": false
122122
},
@@ -143,7 +143,7 @@
143143
},
144144
{
145145
"cell_type": "code",
146-
"execution_count": 10,
146+
"execution_count": null,
147147
"metadata": {
148148
"collapsed": false
149149
},
@@ -162,22 +162,11 @@
162162
},
163163
{
164164
"cell_type": "code",
165-
"execution_count": 11,
165+
"execution_count": null,
166166
"metadata": {
167167
"collapsed": false
168168
},
169-
"outputs": [
170-
{
171-
"data": {
172-
"text/plain": [
173-
"(150, 4)"
174-
]
175-
},
176-
"execution_count": 11,
177-
"metadata": {},
178-
"output_type": "execute_result"
179-
}
180-
],
169+
"outputs": [],
181170
"source": [
182171
"iris_data.data.shape"
183172
]
@@ -191,25 +180,11 @@
191180
},
192181
{
193182
"cell_type": "code",
194-
"execution_count": 12,
183+
"execution_count": null,
195184
"metadata": {
196185
"collapsed": false
197186
},
198-
"outputs": [
199-
{
200-
"data": {
201-
"text/plain": [
202-
"['sepal length (cm)',\n",
203-
" 'sepal width (cm)',\n",
204-
" 'petal length (cm)',\n",
205-
" 'petal width (cm)']"
206-
]
207-
},
208-
"execution_count": 12,
209-
"metadata": {},
210-
"output_type": "execute_result"
211-
}
212-
],
187+
"outputs": [],
213188
"source": [
214189
"iris_data.feature_names"
215190
]
@@ -232,26 +207,35 @@
232207
},
233208
{
234209
"cell_type": "code",
235-
"execution_count": 13,
210+
"execution_count": null,
236211
"metadata": {
237212
"collapsed": false
238213
},
239214
"outputs": [],
240215
"source": [
241216
"%load soln/data_explorer.py"
242217
]
243-
},
244-
{
245-
"cell_type": "code",
246-
"execution_count": null,
247-
"metadata": {
248-
"collapsed": false
249-
},
250-
"outputs": [],
251-
"source": []
252218
}
253219
],
254-
"metadata": {},
220+
"metadata": {
221+
"kernelspec": {
222+
"display_name": "Python 3",
223+
"language": "python",
224+
"name": "python3"
225+
},
226+
"language_info": {
227+
"codemirror_mode": {
228+
"name": "ipython",
229+
"version": 3
230+
},
231+
"file_extension": ".py",
232+
"mimetype": "text/x-python",
233+
"name": "python",
234+
"nbconvert_exporter": "python",
235+
"pygments_lexer": "ipython3",
236+
"version": "3.4.3"
237+
}
238+
},
255239
"nbformat": 4,
256240
"nbformat_minor": 0
257-
}
241+
}

exercises/Interactive Widgets/Widget Exercises.ipynb

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"metadata": {},
2020
"source": [
2121
"### Displaying a widget\n",
22-
"Create and display a `TextWidget`. Change that widget's `value` and some of it's other properties. Discover the other properties by querying the `keys` property of the instance. \n",
22+
"\n",
23+
"Create and display a `Text` widget. Change that widget's `value` and some of it's other properties. Discover the other properties by querying the `keys` property of the instance. \n",
2324
"\n",
2425
"*Hint: You'll need to import from IPython.html.widgets and IPython.display.*"
2526
]
2627
},
2728
{
2829
"cell_type": "code",
29-
"execution_count": 1,
30+
"execution_count": null,
3031
"metadata": {
3132
"collapsed": false
3233
},
@@ -58,7 +59,7 @@
5859
},
5960
{
6061
"cell_type": "code",
61-
"execution_count": 3,
62+
"execution_count": null,
6263
"metadata": {
6364
"collapsed": false
6465
},
@@ -78,14 +79,14 @@
7879
"cell_type": "markdown",
7980
"metadata": {},
8081
"source": [
81-
"Use a link to link the values of a `TextareaWidget` and, an `HTMLWidget` or a `LatexWidget`. Display the widgets and try typing Latex and HTML in the textarea. \n",
82+
"Use a link to link the values of a `Textarea` widget and, an `HTML` or `Latex` widget. Display the widgets and try typing Latex and HTML in the textarea. \n",
8283
"\n",
8384
"*Hint: Look at the Widget Basics notebook for an example of how to use link.*"
8485
]
8586
},
8687
{
8788
"cell_type": "code",
88-
"execution_count": 5,
89+
"execution_count": null,
8990
"metadata": {
9091
"collapsed": false
9192
},
@@ -112,14 +113,14 @@
112113
"cell_type": "markdown",
113114
"metadata": {},
114115
"source": [
115-
"Create and display a `TextWidget`. Use the `on_submit` event to print the value of the textbox just before you clear the textbox. \n",
116+
"Create and display a `Text` widget. Use the `on_submit` event to print the value of the textbox just before you clear the textbox. \n",
116117
"\n",
117118
"*Hint: The `on_submit` callback must accept one argument, the `sender`.*"
118119
]
119120
},
120121
{
121122
"cell_type": "code",
122-
"execution_count": 9,
123+
"execution_count": null,
123124
"metadata": {
124125
"collapsed": false
125126
},
@@ -139,12 +140,12 @@
139140
"cell_type": "markdown",
140141
"metadata": {},
141142
"source": [
142-
"Create and display a `TextWidget`. Use the `on_trait_change` method to register a callback that prints the value of the textbox without clearing it. Observe the difference in behavior to Exercise 1."
143+
"Create and display a `Text` widget. Use the `on_trait_change` method to register a callback that prints the value of the textbox without clearing it. Observe the difference in behavior to Exercise 1."
143144
]
144145
},
145146
{
146147
"cell_type": "code",
147-
"execution_count": 11,
148+
"execution_count": null,
148149
"metadata": {
149150
"collapsed": false
150151
},
@@ -171,12 +172,12 @@
171172
"cell_type": "markdown",
172173
"metadata": {},
173174
"source": [
174-
"Create and display an `HTMLWidget` with a value of your choice (i.e. \"Hello World\"). Use `set_css` to change that widget's background color and font color."
175+
"Create and display an `HTML` widget with a value of your choice (i.e. \"Hello World\"). Use its attributes to change that widget's background color and font color."
175176
]
176177
},
177178
{
178179
"cell_type": "code",
179-
"execution_count": 13,
180+
"execution_count": null,
180181
"metadata": {
181182
"collapsed": false
182183
},
@@ -203,17 +204,35 @@
203204
},
204205
{
205206
"cell_type": "code",
206-
"execution_count": 15,
207+
"execution_count": null,
207208
"metadata": {
208209
"collapsed": false
209210
},
210211
"outputs": [],
211212
"source": [
212-
"%loadpy soln/sliders.py"
213+
"%load soln/sliders.py"
213214
]
214215
}
215216
],
216-
"metadata": {},
217+
"metadata": {
218+
"kernelspec": {
219+
"display_name": "Python 3",
220+
"language": "python",
221+
"name": "python3"
222+
},
223+
"language_info": {
224+
"codemirror_mode": {
225+
"name": "ipython",
226+
"version": 3
227+
},
228+
"file_extension": ".py",
229+
"mimetype": "text/x-python",
230+
"name": "python",
231+
"nbconvert_exporter": "python",
232+
"pygments_lexer": "ipython3",
233+
"version": "3.4.3"
234+
}
235+
},
217236
"nbformat": 4,
218237
"nbformat_minor": 0
219-
}
238+
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from IPython.html.widgets import *
2-
w = HTMLWidget(value="Hello world!")
3-
w.set_css({
4-
'background': 'red',
5-
'color': 'yellow',
6-
})
7-
w
2+
w = HTML(value="Hello world!")
3+
w.color = 'red'
4+
w.background_color = 'yellow'
5+
w
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from IPython.html.widgets import *
22
from IPython.display import display
33
from IPython.utils.traitlets import link
4-
code = TextareaWidget(description="Source:", value="Cool math: $\\frac{F}{m}=a$")
5-
preview = LatexWidget()
4+
code = Textarea(description="Source:", value="Cool math: $\\frac{F}{m}=a$")
5+
preview = Latex()
66
display(code, preview)
7-
mylink = link((code, 'value'), (preview, 'value'))
7+
mylink = link((code, 'value'), (preview, 'value'))

exercises/Interactive Widgets/soln/on_submit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from IPython.html.widgets import *
2-
w = TextWidget()
2+
w = Text()
33
def handle_submit(sender):
44
print(sender.value)
55
sender.value = ''
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from IPython.html.widgets import *
2-
w = TextWidget()
2+
w = Text()
33
def handle_submit(name, new):
44
print(new)
55
w.on_trait_change(handle_submit, 'value')
6-
w
6+
w

exercises/Interactive Widgets/soln/selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from IPython.html.widgets import *
22
from IPython.display import display
3-
w = RadioButtonsWidget(values={"Left": 0, "Center": 1, "Right": 2}, description="Alignment:")
3+
w = RadioButtons(options={"Left": 0, "Center": 1, "Right": 2}, description="Alignment:")
44
display(w)
55

66
print(w.value)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from IPython.html.widgets import *
22
from IPython.display import display
3-
sliders = [FloatSliderWidget(description=str(i), orientation="vertical", value=50.) for i in range(10)]
4-
container = ContainerWidget(children=sliders)
3+
sliders = [FloatSlider(description=str(i), orientation="vertical", value=50.) for i in range(10)]
4+
container = HBox(children=sliders)
55
display(container)
6-
container.remove_class('vbox')
7-
container.add_class('hbox')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def sort_string(s, reverse=False):
22
s = reversed(sorted(s)) if reverse else sorted(s)
3-
print ''.join(s)
3+
print(''.join(s))
44

55
interact(sort_string, s='Hi', reverse=False);

0 commit comments

Comments
 (0)