Show More
@@ -0,0 +1,55 b'' | |||||
|
1 | //---------------------------------------------------------------------------- | |||
|
2 | // Copyright (C) 2013 The IPython Development Team | |||
|
3 | // | |||
|
4 | // Distributed under the terms of the BSD License. The full license is in | |||
|
5 | // the file COPYING, distributed as part of this software. | |||
|
6 | //---------------------------------------------------------------------------- | |||
|
7 | ||||
|
8 | //============================================================================ | |||
|
9 | // ImageWidget | |||
|
10 | //============================================================================ | |||
|
11 | ||||
|
12 | /** | |||
|
13 | * @module IPython | |||
|
14 | * @namespace IPython | |||
|
15 | **/ | |||
|
16 | ||||
|
17 | define(["notebook/js/widget"], function(widget_manager){ | |||
|
18 | var ImageWidgetModel = IPython.WidgetModel.extend({}); | |||
|
19 | widget_manager.register_widget_model('ImageWidgetModel', ImageWidgetModel); | |||
|
20 | ||||
|
21 | var ImageView = IPython.WidgetView.extend({ | |||
|
22 | ||||
|
23 | // Called when view is rendered. | |||
|
24 | render : function(){ | |||
|
25 | this.setElement($("<img />")); | |||
|
26 | this.update(); // Set defaults. | |||
|
27 | }, | |||
|
28 | ||||
|
29 | // Handles: Backend -> Frontend Sync | |||
|
30 | // Frontent -> Frontend Sync | |||
|
31 | update : function(){ | |||
|
32 | var image_src = 'data:image/' + this.model.get('image_format') + ';base64,' + this.model.get('_b64value'); | |||
|
33 | this.$el.attr('src', image_src); | |||
|
34 | ||||
|
35 | var width = this.model.get('width'); | |||
|
36 | if (width !== undefined && width.length > 0) { | |||
|
37 | this.$el.attr('width', width); | |||
|
38 | } else { | |||
|
39 | this.$el.removeAttr('width'); | |||
|
40 | } | |||
|
41 | ||||
|
42 | var height = this.model.get('height'); | |||
|
43 | if (height !== undefined && height.length > 0) { | |||
|
44 | this.$el.attr('height', height); | |||
|
45 | } else { | |||
|
46 | this.$el.removeAttr('height'); | |||
|
47 | } | |||
|
48 | return IPython.WidgetView.prototype.update.call(this); | |||
|
49 | }, | |||
|
50 | ||||
|
51 | }); | |||
|
52 | ||||
|
53 | widget_manager.register_widget_view('ImageView', ImageView); | |||
|
54 | ||||
|
55 | }); |
@@ -0,0 +1,38 b'' | |||||
|
1 | """ButtonWidget class. | |||
|
2 | ||||
|
3 | Represents a button in the frontend using a widget. Allows user to listen for | |||
|
4 | click events on the button and trigger backend code when the clicks are fired. | |||
|
5 | """ | |||
|
6 | #----------------------------------------------------------------------------- | |||
|
7 | # Copyright (c) 2013, the IPython Development Team. | |||
|
8 | # | |||
|
9 | # Distributed under the terms of the Modified BSD License. | |||
|
10 | # | |||
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |||
|
12 | #----------------------------------------------------------------------------- | |||
|
13 | ||||
|
14 | #----------------------------------------------------------------------------- | |||
|
15 | # Imports | |||
|
16 | #----------------------------------------------------------------------------- | |||
|
17 | import base64 | |||
|
18 | ||||
|
19 | from .widget import Widget | |||
|
20 | from IPython.utils.traitlets import Unicode, Bytes | |||
|
21 | ||||
|
22 | #----------------------------------------------------------------------------- | |||
|
23 | # Classes | |||
|
24 | #----------------------------------------------------------------------------- | |||
|
25 | class ImageWidget(Widget): | |||
|
26 | target_name = Unicode('ImageWidgetModel') | |||
|
27 | default_view_name = Unicode('ImageView') | |||
|
28 | ||||
|
29 | # Define the custom state properties to sync with the front-end | |||
|
30 | _keys = ['image_format', 'width', 'height', '_b64value'] | |||
|
31 | image_format = Unicode('png') | |||
|
32 | width = Unicode() | |||
|
33 | height = Unicode() | |||
|
34 | _b64value = Unicode() | |||
|
35 | ||||
|
36 | value = Bytes() | |||
|
37 | def _value_changed(self, name, old, new): | |||
|
38 | self._b64value = base64.b64encode(new) No newline at end of file |
@@ -1,23 +1,24 b'' | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2013 The IPython Development Team |
|
2 | // Copyright (C) 2013 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // Basic Widgets |
|
9 | // Basic Widgets | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | define([ |
|
12 | define([ | |
13 | "notebook/js/widgets/bool", |
|
13 | "notebook/js/widgets/bool", | |
14 | "notebook/js/widgets/button", |
|
14 | "notebook/js/widgets/button", | |
15 | "notebook/js/widgets/container", |
|
15 | "notebook/js/widgets/container", | |
16 | "notebook/js/widgets/float", |
|
16 | "notebook/js/widgets/float", | |
17 | "notebook/js/widgets/float_range", |
|
17 | "notebook/js/widgets/float_range", | |
|
18 | "notebook/js/widgets/image", | |||
18 | "notebook/js/widgets/int", |
|
19 | "notebook/js/widgets/int", | |
19 | "notebook/js/widgets/int_range", |
|
20 | "notebook/js/widgets/int_range", | |
20 | "notebook/js/widgets/multicontainer", |
|
21 | "notebook/js/widgets/multicontainer", | |
21 | "notebook/js/widgets/selection", |
|
22 | "notebook/js/widgets/selection", | |
22 | "notebook/js/widgets/string", |
|
23 | "notebook/js/widgets/string", | |
23 | ], function(){ return true; }); |
|
24 | ], function(){ return true; }); |
@@ -1,12 +1,13 b'' | |||||
1 | from .widget import Widget |
|
1 | from .widget import Widget | |
2 |
|
2 | |||
3 | from .widget_bool import BoolWidget |
|
3 | from .widget_bool import BoolWidget | |
4 | from .widget_button import ButtonWidget |
|
4 | from .widget_button import ButtonWidget | |
5 | from .widget_container import ContainerWidget |
|
5 | from .widget_container import ContainerWidget | |
6 | from .widget_float import FloatWidget |
|
6 | from .widget_float import FloatWidget | |
7 | from .widget_float_range import FloatRangeWidget |
|
7 | from .widget_float_range import FloatRangeWidget | |
|
8 | from .widget_image import ImageWidget | |||
8 | from .widget_int import IntWidget |
|
9 | from .widget_int import IntWidget | |
9 | from .widget_int_range import IntRangeWidget |
|
10 | from .widget_int_range import IntRangeWidget | |
10 | from .widget_multicontainer import MulticontainerWidget |
|
11 | from .widget_multicontainer import MulticontainerWidget | |
11 | from .widget_selection import SelectionWidget |
|
12 | from .widget_selection import SelectionWidget | |
12 | from .widget_string import StringWidget |
|
13 | from .widget_string import StringWidget |
@@ -1,326 +1,327 b'' | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
3 | "cell_tags": [ |
|
3 | "cell_tags": [ | |
4 | [ |
|
4 | [ | |
5 | "<None>", |
|
5 | "<None>", | |
6 | null |
|
6 | null | |
7 | ] |
|
7 | ] | |
8 | ], |
|
8 | ], | |
9 | "name": "" |
|
9 | "name": "" | |
10 | }, |
|
10 | }, | |
11 | "nbformat": 3, |
|
11 | "nbformat": 3, | |
12 | "nbformat_minor": 0, |
|
12 | "nbformat_minor": 0, | |
13 | "worksheets": [ |
|
13 | "worksheets": [ | |
14 | { |
|
14 | { | |
15 | "cells": [ |
|
15 | "cells": [ | |
16 | { |
|
16 | { | |
17 | "cell_type": "markdown", |
|
17 | "cell_type": "markdown", | |
18 | "metadata": {}, |
|
18 | "metadata": {}, | |
19 | "source": [ |
|
19 | "source": [ | |
20 | "To use IPython widgets in the notebook, the widget namespace and display function need to be imported." |
|
20 | "To use IPython widgets in the notebook, the widget namespace and display function need to be imported." | |
21 | ] |
|
21 | ] | |
22 | }, |
|
22 | }, | |
23 | { |
|
23 | { | |
24 | "cell_type": "code", |
|
24 | "cell_type": "code", | |
25 | "collapsed": false, |
|
25 | "collapsed": false, | |
26 | "input": [ |
|
26 | "input": [ | |
27 | "from IPython.html import widgets # Widget definitions\n", |
|
27 | "from IPython.html import widgets # Widget definitions\n", | |
28 | "from IPython.display import display # Used to display widgets in the notebook" |
|
28 | "from IPython.display import display # Used to display widgets in the notebook" | |
29 | ], |
|
29 | ], | |
30 | "language": "python", |
|
30 | "language": "python", | |
31 | "metadata": {}, |
|
31 | "metadata": {}, | |
32 | "outputs": [], |
|
32 | "outputs": [], | |
33 | "prompt_number": 1 |
|
33 | "prompt_number": 1 | |
34 | }, |
|
34 | }, | |
35 | { |
|
35 | { | |
36 | "cell_type": "heading", |
|
36 | "cell_type": "heading", | |
37 | "level": 1, |
|
37 | "level": 1, | |
38 | "metadata": {}, |
|
38 | "metadata": {}, | |
39 | "source": [ |
|
39 | "source": [ | |
40 | "Basic Widgets" |
|
40 | "Basic Widgets" | |
41 | ] |
|
41 | ] | |
42 | }, |
|
42 | }, | |
43 | { |
|
43 | { | |
44 | "cell_type": "markdown", |
|
44 | "cell_type": "markdown", | |
45 | "metadata": {}, |
|
45 | "metadata": {}, | |
46 | "source": [ |
|
46 | "source": [ | |
47 | "The IPython notebook comes preloaded with basic widgets that represent common data types. These widgets are\n", |
|
47 | "The IPython notebook comes preloaded with basic widgets that represent common data types. These widgets are\n", | |
48 | "\n", |
|
48 | "\n", | |
49 | "- BoolWidget : boolean \n", |
|
49 | "- BoolWidget : boolean \n", | |
50 | "- FloatRangeWidget : bounded float \n", |
|
50 | "- FloatRangeWidget : bounded float \n", | |
51 | "- FloatWidget : unbounded float \n", |
|
51 | "- FloatWidget : unbounded float \n", | |
|
52 | "- ImageWidget : image\n", | |||
52 | "- IntRangeWidget : bounded integer \n", |
|
53 | "- IntRangeWidget : bounded integer \n", | |
53 | "- IntWidget : unbounded integer \n", |
|
54 | "- IntWidget : unbounded integer \n", | |
54 | "- SelectionWidget : enumeration \n", |
|
55 | "- SelectionWidget : enumeration \n", | |
55 | "- StringWidget : string \n", |
|
56 | "- StringWidget : string \n", | |
56 | "\n", |
|
57 | "\n", | |
57 | "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", |
|
58 | "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", | |
58 | "\n", |
|
59 | "\n", | |
59 | "- ButtonWidget \n", |
|
60 | "- ButtonWidget \n", | |
60 | "- ContainerWidget \n", |
|
61 | "- ContainerWidget \n", | |
61 | "- MulticontainerWidget \n", |
|
62 | "- MulticontainerWidget \n", | |
62 | "\n", |
|
63 | "\n", | |
63 | "To see the complete list of widgets, one can execute the following" |
|
64 | "To see the complete list of widgets, one can execute the following" | |
64 | ] |
|
65 | ] | |
65 | }, |
|
66 | }, | |
66 | { |
|
67 | { | |
67 | "cell_type": "code", |
|
68 | "cell_type": "code", | |
68 | "collapsed": false, |
|
69 | "collapsed": false, | |
69 | "input": [ |
|
70 | "input": [ | |
70 | "[widget for widget in dir(widgets) if widget.endswith('Widget')]" |
|
71 | "[widget for widget in dir(widgets) if widget.endswith('Widget')]" | |
71 | ], |
|
72 | ], | |
72 | "language": "python", |
|
73 | "language": "python", | |
73 | "metadata": {}, |
|
74 | "metadata": {}, | |
74 | "outputs": [ |
|
75 | "outputs": [ | |
75 | { |
|
76 | { | |
76 | "metadata": {}, |
|
77 | "metadata": {}, | |
77 | "output_type": "pyout", |
|
78 | "output_type": "pyout", | |
78 | "prompt_number": 2, |
|
79 | "prompt_number": 2, | |
79 | "text": [ |
|
80 | "text": [ | |
80 | "['BoolWidget',\n", |
|
81 | "['BoolWidget',\n", | |
81 | " 'ButtonWidget',\n", |
|
82 | " 'ButtonWidget',\n", | |
82 | " 'ContainerWidget',\n", |
|
83 | " 'ContainerWidget',\n", | |
83 | " 'FloatRangeWidget',\n", |
|
84 | " 'FloatRangeWidget',\n", | |
84 | " 'FloatWidget',\n", |
|
85 | " 'FloatWidget',\n", | |
|
86 | " 'ImageWidget',\n", | |||
85 | " 'IntRangeWidget',\n", |
|
87 | " 'IntRangeWidget',\n", | |
86 | " 'IntWidget',\n", |
|
88 | " 'IntWidget',\n", | |
87 | " 'MulticontainerWidget',\n", |
|
89 | " 'MulticontainerWidget',\n", | |
88 | " 'SelectionWidget',\n", |
|
90 | " 'SelectionWidget',\n", | |
89 | " 'StringWidget',\n", |
|
91 | " 'StringWidget',\n", | |
90 | " 'Widget']" |
|
92 | " 'Widget']" | |
91 | ] |
|
93 | ] | |
92 | } |
|
94 | } | |
93 | ], |
|
95 | ], | |
94 | "prompt_number": 2 |
|
96 | "prompt_number": 2 | |
95 | }, |
|
97 | }, | |
96 | { |
|
98 | { | |
97 | "cell_type": "markdown", |
|
99 | "cell_type": "markdown", | |
98 | "metadata": {}, |
|
100 | "metadata": {}, | |
99 | "source": [ |
|
101 | "source": [ | |
100 | "The basic widgets can all be constructed without arguments. The following creates a FloatRangeWidget without displaying it" |
|
102 | "The basic widgets can all be constructed without arguments. The following creates a FloatRangeWidget without displaying it" | |
101 | ] |
|
103 | ] | |
102 | }, |
|
104 | }, | |
103 | { |
|
105 | { | |
104 | "cell_type": "code", |
|
106 | "cell_type": "code", | |
105 | "collapsed": false, |
|
107 | "collapsed": false, | |
106 | "input": [ |
|
108 | "input": [ | |
107 | "mywidget = widgets.FloatRangeWidget()" |
|
109 | "mywidget = widgets.FloatRangeWidget()" | |
108 | ], |
|
110 | ], | |
109 | "language": "python", |
|
111 | "language": "python", | |
110 | "metadata": {}, |
|
112 | "metadata": {}, | |
111 | "outputs": [], |
|
113 | "outputs": [], | |
112 | "prompt_number": 3 |
|
114 | "prompt_number": 3 | |
113 | }, |
|
115 | }, | |
114 | { |
|
116 | { | |
115 | "cell_type": "markdown", |
|
117 | "cell_type": "markdown", | |
116 | "metadata": {}, |
|
118 | "metadata": {}, | |
117 | "source": [ |
|
119 | "source": [ | |
118 | "Constructing a widget does not display it on the page. To display a widget, the widget must be passed to the IPython `display(object)` method. `mywidget` is displayed by" |
|
120 | "Constructing a widget does not display it on the page. To display a widget, the widget must be passed to the IPython `display(object)` method. `mywidget` is displayed by" | |
119 | ] |
|
121 | ] | |
120 | }, |
|
122 | }, | |
121 | { |
|
123 | { | |
122 | "cell_type": "code", |
|
124 | "cell_type": "code", | |
123 | "collapsed": false, |
|
125 | "collapsed": false, | |
124 | "input": [ |
|
126 | "input": [ | |
125 | "display(mywidget)" |
|
127 | "display(mywidget)" | |
126 | ], |
|
128 | ], | |
127 | "language": "python", |
|
129 | "language": "python", | |
128 | "metadata": {}, |
|
130 | "metadata": {}, | |
129 | "outputs": [], |
|
131 | "outputs": [], | |
130 | "prompt_number": 4 |
|
132 | "prompt_number": 4 | |
131 | }, |
|
133 | }, | |
132 | { |
|
134 | { | |
133 | "cell_type": "markdown", |
|
135 | "cell_type": "markdown", | |
134 | "metadata": {}, |
|
136 | "metadata": {}, | |
135 | "source": [ |
|
137 | "source": [ | |
136 | "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", |
|
138 | "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", | |
137 | "\n", |
|
139 | "\n", | |
138 | "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`, `_add_class`, and `_remove_class` are internal properties that exist in all widgets and should not be modified." |
|
140 | "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`, `_add_class`, and `_remove_class` are internal properties that exist in all widgets and should not be modified." | |
139 | ] |
|
141 | ] | |
140 | }, |
|
142 | }, | |
141 | { |
|
143 | { | |
142 | "cell_type": "code", |
|
144 | "cell_type": "code", | |
143 | "collapsed": false, |
|
145 | "collapsed": false, | |
144 | "input": [ |
|
146 | "input": [ | |
145 | "mywidget.keys" |
|
147 | "mywidget.keys" | |
146 | ], |
|
148 | ], | |
147 | "language": "python", |
|
149 | "language": "python", | |
148 | "metadata": {}, |
|
150 | "metadata": {}, | |
149 | "outputs": [ |
|
151 | "outputs": [ | |
150 | { |
|
152 | { | |
151 | "metadata": {}, |
|
153 | "metadata": {}, | |
152 | "output_type": "pyout", |
|
154 | "output_type": "pyout", | |
153 | "prompt_number": 5, |
|
155 | "prompt_number": 5, | |
154 | "text": [ |
|
156 | "text": [ | |
155 | "['visible',\n", |
|
157 | "['visible',\n", | |
156 | " '_css',\n", |
|
158 | " '_css',\n", | |
157 | " '_add_class',\n", |
|
|||
158 | " '_remove_class',\n", |
|
|||
159 | " 'value',\n", |
|
159 | " 'value',\n", | |
160 | " 'step',\n", |
|
160 | " 'step',\n", | |
161 | " 'max',\n", |
|
161 | " 'max',\n", | |
162 | " 'min',\n", |
|
162 | " 'min',\n", | |
163 | " 'disabled',\n", |
|
163 | " 'disabled',\n", | |
164 | " 'orientation',\n", |
|
164 | " 'orientation',\n", | |
165 | " 'description']" |
|
165 | " 'description']" | |
166 | ] |
|
166 | ] | |
167 | } |
|
167 | } | |
168 | ], |
|
168 | ], | |
169 | "prompt_number": 5 |
|
169 | "prompt_number": 5 | |
170 | }, |
|
170 | }, | |
171 | { |
|
171 | { | |
172 | "cell_type": "markdown", |
|
172 | "cell_type": "markdown", | |
173 | "metadata": {}, |
|
173 | "metadata": {}, | |
174 | "source": [ |
|
174 | "source": [ | |
175 | "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 input 4) updates automatically to the new value. In reverse, changing the value of the displayed widget will update the property's value." |
|
175 | "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 input 4) updates automatically to the new value. In reverse, changing the value of the displayed widget will update the property's value." | |
176 | ] |
|
176 | ] | |
177 | }, |
|
177 | }, | |
178 | { |
|
178 | { | |
179 | "cell_type": "code", |
|
179 | "cell_type": "code", | |
180 | "collapsed": false, |
|
180 | "collapsed": false, | |
181 | "input": [ |
|
181 | "input": [ | |
182 | "mywidget.value = 25.0" |
|
182 | "mywidget.value = 25.0" | |
183 | ], |
|
183 | ], | |
184 | "language": "python", |
|
184 | "language": "python", | |
185 | "metadata": {}, |
|
185 | "metadata": {}, | |
186 | "outputs": [], |
|
186 | "outputs": [], | |
187 | "prompt_number": 6 |
|
187 | "prompt_number": 6 | |
188 | }, |
|
188 | }, | |
189 | { |
|
189 | { | |
190 | "cell_type": "markdown", |
|
190 | "cell_type": "markdown", | |
191 | "metadata": {}, |
|
191 | "metadata": {}, | |
192 | "source": [ |
|
192 | "source": [ | |
193 | "After changing the widget's value in the notebook by hand to 0.0 (sliding the bar to the far left)." |
|
193 | "After changing the widget's value in the notebook by hand to 0.0 (sliding the bar to the far left)." | |
194 | ] |
|
194 | ] | |
195 | }, |
|
195 | }, | |
196 | { |
|
196 | { | |
197 | "cell_type": "code", |
|
197 | "cell_type": "code", | |
198 | "collapsed": false, |
|
198 | "collapsed": false, | |
199 | "input": [ |
|
199 | "input": [ | |
200 | "mywidget.value" |
|
200 | "mywidget.value" | |
201 | ], |
|
201 | ], | |
202 | "language": "python", |
|
202 | "language": "python", | |
203 | "metadata": {}, |
|
203 | "metadata": {}, | |
204 | "outputs": [ |
|
204 | "outputs": [ | |
205 | { |
|
205 | { | |
206 | "metadata": {}, |
|
206 | "metadata": {}, | |
207 | "output_type": "pyout", |
|
207 | "output_type": "pyout", | |
208 | "prompt_number": 7, |
|
208 | "prompt_number": 7, | |
209 | "text": [ |
|
209 | "text": [ | |
210 | "0.0" |
|
210 | "0.0" | |
211 | ] |
|
211 | ] | |
212 | } |
|
212 | } | |
213 | ], |
|
213 | ], | |
214 | "prompt_number": 7 |
|
214 | "prompt_number": 7 | |
215 | }, |
|
215 | }, | |
216 | { |
|
216 | { | |
217 | "cell_type": "markdown", |
|
217 | "cell_type": "markdown", | |
218 | "metadata": {}, |
|
218 | "metadata": {}, | |
219 | "source": [ |
|
219 | "source": [ | |
220 | "Widget property values can also be set with kwargs during the construction of the widget (as seen below)." |
|
220 | "Widget property values can also be set with kwargs during the construction of the widget (as seen below)." | |
221 | ] |
|
221 | ] | |
222 | }, |
|
222 | }, | |
223 | { |
|
223 | { | |
224 | "cell_type": "code", |
|
224 | "cell_type": "code", | |
225 | "collapsed": false, |
|
225 | "collapsed": false, | |
226 | "input": [ |
|
226 | "input": [ | |
227 | "mysecondwidget = widgets.SelectionWidget(values=[\"Item A\", \"Item B\", \"Item C\"], value=\"Nothing Selected\")\n", |
|
227 | "mysecondwidget = widgets.SelectionWidget(values=[\"Item A\", \"Item B\", \"Item C\"], value=\"Nothing Selected\")\n", | |
228 | "display(mysecondwidget)" |
|
228 | "display(mysecondwidget)" | |
229 | ], |
|
229 | ], | |
230 | "language": "python", |
|
230 | "language": "python", | |
231 | "metadata": {}, |
|
231 | "metadata": {}, | |
232 | "outputs": [], |
|
232 | "outputs": [], | |
233 | "prompt_number": 8 |
|
233 | "prompt_number": 8 | |
234 | }, |
|
234 | }, | |
235 | { |
|
235 | { | |
236 | "cell_type": "heading", |
|
236 | "cell_type": "heading", | |
237 | "level": 1, |
|
237 | "level": 1, | |
238 | "metadata": {}, |
|
238 | "metadata": {}, | |
239 | "source": [ |
|
239 | "source": [ | |
240 | "Views" |
|
240 | "Views" | |
241 | ] |
|
241 | ] | |
242 | }, |
|
242 | }, | |
243 | { |
|
243 | { | |
244 | "cell_type": "markdown", |
|
244 | "cell_type": "markdown", | |
245 | "metadata": {}, |
|
245 | "metadata": {}, | |
246 | "source": [ |
|
246 | "source": [ | |
247 | "The data types that most of the widgets represent can be displayed more than one way. A `view` is a visual representation of a widget in the notebook. In the example in the section above, the default `view` for the `FloatRangeWidget` is used. The default view is set in the widgets `default_view_name` instance property (as seen below)." |
|
247 | "The data types that most of the widgets represent can be displayed more than one way. A `view` is a visual representation of a widget in the notebook. In the example in the section above, the default `view` for the `FloatRangeWidget` is used. The default view is set in the widgets `default_view_name` instance property (as seen below)." | |
248 | ] |
|
248 | ] | |
249 | }, |
|
249 | }, | |
250 | { |
|
250 | { | |
251 | "cell_type": "code", |
|
251 | "cell_type": "code", | |
252 | "collapsed": false, |
|
252 | "collapsed": false, | |
253 | "input": [ |
|
253 | "input": [ | |
254 | "mywidget.default_view_name" |
|
254 | "mywidget.default_view_name" | |
255 | ], |
|
255 | ], | |
256 | "language": "python", |
|
256 | "language": "python", | |
257 | "metadata": {}, |
|
257 | "metadata": {}, | |
258 | "outputs": [ |
|
258 | "outputs": [ | |
259 | { |
|
259 | { | |
260 | "metadata": {}, |
|
260 | "metadata": {}, | |
261 | "output_type": "pyout", |
|
261 | "output_type": "pyout", | |
262 | "prompt_number": 9, |
|
262 | "prompt_number": 9, | |
263 | "text": [ |
|
263 | "text": [ | |
264 | "u'FloatSliderView'" |
|
264 | "u'FloatSliderView'" | |
265 | ] |
|
265 | ] | |
266 | } |
|
266 | } | |
267 | ], |
|
267 | ], | |
268 | "prompt_number": 9 |
|
268 | "prompt_number": 9 | |
269 | }, |
|
269 | }, | |
270 | { |
|
270 | { | |
271 | "cell_type": "markdown", |
|
271 | "cell_type": "markdown", | |
272 | "metadata": {}, |
|
272 | "metadata": {}, | |
273 | "source": [ |
|
273 | "source": [ | |
274 | "When a widget is displayed using `display(...)`, the `default_view_name` is used to determine what view type should be used to display the widget. View names are case sensitive. Sometimes the default view isn't the best view to represent a piece of data. To change what view is used, either the `default_view_name` can be changed or the `view_name` kwarg of `display` can be set. This also can be used to display one widget multiple ways in one output (as seen below)." |
|
274 | "When a widget is displayed using `display(...)`, the `default_view_name` is used to determine what view type should be used to display the widget. View names are case sensitive. Sometimes the default view isn't the best view to represent a piece of data. To change what view is used, either the `default_view_name` can be changed or the `view_name` kwarg of `display` can be set. This also can be used to display one widget multiple ways in one output (as seen below)." | |
275 | ] |
|
275 | ] | |
276 | }, |
|
276 | }, | |
277 | { |
|
277 | { | |
278 | "cell_type": "code", |
|
278 | "cell_type": "code", | |
279 | "collapsed": false, |
|
279 | "collapsed": false, | |
280 | "input": [ |
|
280 | "input": [ | |
281 | "display(mywidget)\n", |
|
281 | "display(mywidget)\n", | |
282 | "display(mywidget, view_name=\"FloatTextView\")" |
|
282 | "display(mywidget, view_name=\"FloatTextView\")" | |
283 | ], |
|
283 | ], | |
284 | "language": "python", |
|
284 | "language": "python", | |
285 | "metadata": {}, |
|
285 | "metadata": {}, | |
286 | "outputs": [], |
|
286 | "outputs": [], | |
287 | "prompt_number": 10 |
|
287 | "prompt_number": 10 | |
288 | }, |
|
288 | }, | |
289 | { |
|
289 | { | |
290 | "cell_type": "markdown", |
|
290 | "cell_type": "markdown", | |
291 | "metadata": {}, |
|
291 | "metadata": {}, | |
292 | "source": [ |
|
292 | "source": [ | |
293 | "Some views work with multiple different widget types and some views only work with one. The complete list of views and supported widgets is below. The default views are italicized.\n", |
|
293 | "Some views work with multiple different widget types and some views only work with one. The complete list of views and supported widgets is below. The default views are italicized.\n", | |
294 | "\n", |
|
294 | "\n", | |
295 | "| Widget Name | View Names |\n", |
|
295 | "| Widget Name | View Names |\n", | |
296 | "|:-----------------------|:--------------------|\n", |
|
296 | "|:-----------------------|:--------------------|\n", | |
297 | "| BoolWidget | *CheckboxView* |\n", |
|
297 | "| BoolWidget | *CheckboxView* |\n", | |
298 | "| | ToggleButtonView |\n", |
|
298 | "| | ToggleButtonView |\n", | |
299 | "| ButtonWidget | *ButtonView* |\n", |
|
299 | "| ButtonWidget | *ButtonView* |\n", | |
300 | "| ContainerWidget | *ContainerView* |\n", |
|
300 | "| ContainerWidget | *ContainerView* |\n", | |
301 | "| | ModalView |\n", |
|
301 | "| | ModalView |\n", | |
302 | "| FloatRangeWidget | *FloatSliderView* |\n", |
|
302 | "| FloatRangeWidget | *FloatSliderView* |\n", | |
303 | "| | FloatTextView |\n", |
|
303 | "| | FloatTextView |\n", | |
304 | "| | ProgressView |\n", |
|
304 | "| | ProgressView |\n", | |
305 | "| FloatWidget | *FloatTextView* |\n", |
|
305 | "| FloatWidget | *FloatTextView* |\n", | |
|
306 | "| ImageWidget | *ImageView* |\n", | |||
306 | "| IntRangeWidget | *IntSliderView* |\n", |
|
307 | "| IntRangeWidget | *IntSliderView* |\n", | |
307 | "| | IntTextView |\n", |
|
308 | "| | IntTextView |\n", | |
308 | "| | ProgressView |\n", |
|
309 | "| | ProgressView |\n", | |
309 | "| IntWidget | *IntTextView* |\n", |
|
310 | "| IntWidget | *IntTextView* |\n", | |
310 | "| MulticontainerWidget | AccordionView |\n", |
|
311 | "| MulticontainerWidget | AccordionView |\n", | |
311 | "| | *TabView* |\n", |
|
312 | "| | *TabView* |\n", | |
312 | "| SelectionWidget | ToggleButtonsView |\n", |
|
313 | "| SelectionWidget | ToggleButtonsView |\n", | |
313 | "| | RadioButtonsView |\n", |
|
314 | "| | RadioButtonsView |\n", | |
314 | "| | *DropdownView* |\n", |
|
315 | "| | *DropdownView* |\n", | |
315 | "| | ListBoxView |\n", |
|
316 | "| | ListBoxView |\n", | |
316 | "| StringWidget | HTMLView |\n", |
|
317 | "| StringWidget | HTMLView |\n", | |
317 | "| | LatexView |\n", |
|
318 | "| | LatexView |\n", | |
318 | "| | TextAreaView |\n", |
|
319 | "| | TextAreaView |\n", | |
319 | "| | *TextBoxView* |\n" |
|
320 | "| | *TextBoxView* |\n" | |
320 | ] |
|
321 | ] | |
321 | } |
|
322 | } | |
322 | ], |
|
323 | ], | |
323 | "metadata": {} |
|
324 | "metadata": {} | |
324 | } |
|
325 | } | |
325 | ] |
|
326 | ] | |
326 | } No newline at end of file |
|
327 | } |
General Comments 0
You need to be logged in to leave comments.
Login now