Show More
@@ -1,31 +1,31 b'' | |||||
1 | """BoolWidget class. |
|
1 | """BoolWidget class. | |
2 |
|
2 | |||
3 | Represents a boolean using a widget. |
|
3 | Represents a boolean using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, Bool, List |
|
17 | from IPython.utils.traitlets import Unicode, Bool, List | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class BoolWidget(Widget): |
|
22 | class BoolWidget(Widget): | |
23 | target_name = Unicode('BoolWidgetModel') |
|
23 | target_name = Unicode('BoolWidgetModel') | |
24 | default_view_name = Unicode('CheckboxView') |
|
24 | default_view_name = Unicode('CheckboxView') | |
25 |
|
25 | |||
26 | # Model Keys |
|
26 | # Model Keys | |
27 |
|
|
27 | keys = ['value', 'description', 'disabled'] + Widget.keys | |
28 | value = Bool(False, help="Bool value") |
|
28 | value = Bool(False, help="Bool value") | |
29 | description = Unicode('', help="Description of the boolean (label).") |
|
29 | description = Unicode('', help="Description of the boolean (label).") | |
30 | disabled = Bool(False, help="Enable or disable user changes.") |
|
30 | disabled = Bool(False, help="Enable or disable user changes.") | |
31 | No newline at end of file |
|
31 |
@@ -1,93 +1,93 b'' | |||||
1 | """ButtonWidget class. |
|
1 | """ButtonWidget class. | |
2 |
|
2 | |||
3 | Represents a button in the frontend using a widget. Allows user to listen for |
|
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. |
|
4 | click events on the button and trigger backend code when the clicks are fired. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | # Copyright (c) 2013, the IPython Development Team. | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
10 | # | |
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 | import inspect |
|
17 | import inspect | |
18 | import types |
|
18 | import types | |
19 |
|
19 | |||
20 | from .widget import Widget |
|
20 | from .widget import Widget | |
21 | from IPython.utils.traitlets import Unicode, Bool, Int |
|
21 | from IPython.utils.traitlets import Unicode, Bool, Int | |
22 |
|
22 | |||
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
24 | # Classes |
|
24 | # Classes | |
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 | class ButtonWidget(Widget): |
|
26 | class ButtonWidget(Widget): | |
27 | target_name = Unicode('ButtonWidgetModel') |
|
27 | target_name = Unicode('ButtonWidgetModel') | |
28 | default_view_name = Unicode('ButtonView') |
|
28 | default_view_name = Unicode('ButtonView') | |
29 |
|
29 | |||
30 | # Keys |
|
30 | # Keys | |
31 |
|
|
31 | keys = ['description', 'disabled'] + Widget.keys | |
32 | description = Unicode('', help="Description of the button (label).") |
|
32 | description = Unicode('', help="Description of the button (label).") | |
33 | disabled = Bool(False, help="Enable or disable user changes.") |
|
33 | disabled = Bool(False, help="Enable or disable user changes.") | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def __init__(self, **kwargs): |
|
36 | def __init__(self, **kwargs): | |
37 | super(ButtonWidget, self).__init__(**kwargs) |
|
37 | super(ButtonWidget, self).__init__(**kwargs) | |
38 |
|
38 | |||
39 | self._click_handlers = [] |
|
39 | self._click_handlers = [] | |
40 | self.on_msg(self._handle_button_msg) |
|
40 | self.on_msg(self._handle_button_msg) | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | def on_click(self, callback, remove=False): |
|
43 | def on_click(self, callback, remove=False): | |
44 | """Register a callback to execute when the button is clicked. The |
|
44 | """Register a callback to execute when the button is clicked. The | |
45 | callback can either accept no parameters or one sender parameter: |
|
45 | callback can either accept no parameters or one sender parameter: | |
46 | - callback() |
|
46 | - callback() | |
47 | - callback(sender) |
|
47 | - callback(sender) | |
48 | If the callback has a sender parameter, the ButtonWidget instance that |
|
48 | If the callback has a sender parameter, the ButtonWidget instance that | |
49 | called the callback will be passed into the method as the sender. |
|
49 | called the callback will be passed into the method as the sender. | |
50 |
|
50 | |||
51 | Parameters |
|
51 | Parameters | |
52 | ---------- |
|
52 | ---------- | |
53 | remove : bool (optional) |
|
53 | remove : bool (optional) | |
54 | Set to true to remove the callback from the list of callbacks.""" |
|
54 | Set to true to remove the callback from the list of callbacks.""" | |
55 | if remove: |
|
55 | if remove: | |
56 | self._click_handlers.remove(callback) |
|
56 | self._click_handlers.remove(callback) | |
57 | elif not callback in self._click_handlers: |
|
57 | elif not callback in self._click_handlers: | |
58 | self._click_handlers.append(callback) |
|
58 | self._click_handlers.append(callback) | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def _handle_button_msg(self, content): |
|
61 | def _handle_button_msg(self, content): | |
62 | """Handle a msg from the front-end |
|
62 | """Handle a msg from the front-end | |
63 |
|
63 | |||
64 | Parameters |
|
64 | Parameters | |
65 | ---------- |
|
65 | ---------- | |
66 | content: dict |
|
66 | content: dict | |
67 | Content of the msg.""" |
|
67 | Content of the msg.""" | |
68 | if 'event' in content and content['event'] == 'click': |
|
68 | if 'event' in content and content['event'] == 'click': | |
69 | self._handle_click() |
|
69 | self._handle_click() | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | def _handle_click(self): |
|
72 | def _handle_click(self): | |
73 | """Handles when the button has been clicked. Fires on_click |
|
73 | """Handles when the button has been clicked. Fires on_click | |
74 | callbacks when appropriate.""" |
|
74 | callbacks when appropriate.""" | |
75 |
|
75 | |||
76 | for handler in self._click_handlers: |
|
76 | for handler in self._click_handlers: | |
77 | if callable(handler): |
|
77 | if callable(handler): | |
78 | argspec = inspect.getargspec(handler) |
|
78 | argspec = inspect.getargspec(handler) | |
79 | nargs = len(argspec[0]) |
|
79 | nargs = len(argspec[0]) | |
80 |
|
80 | |||
81 | # Bound methods have an additional 'self' argument |
|
81 | # Bound methods have an additional 'self' argument | |
82 | if isinstance(handler, types.MethodType): |
|
82 | if isinstance(handler, types.MethodType): | |
83 | nargs -= 1 |
|
83 | nargs -= 1 | |
84 |
|
84 | |||
85 | # Call the callback |
|
85 | # Call the callback | |
86 | if nargs == 0: |
|
86 | if nargs == 0: | |
87 | handler() |
|
87 | handler() | |
88 | elif nargs == 1: |
|
88 | elif nargs == 1: | |
89 | handler(self) |
|
89 | handler(self) | |
90 | else: |
|
90 | else: | |
91 | raise TypeError('ButtonWidget click callback must ' \ |
|
91 | raise TypeError('ButtonWidget click callback must ' \ | |
92 | 'accept 0 or 1 arguments.') |
|
92 | 'accept 0 or 1 arguments.') | |
93 |
|
93 |
@@ -1,203 +1,203 b'' | |||||
1 | """ContainerWidget class. |
|
1 | """ContainerWidget class. | |
2 |
|
2 | |||
3 | Represents a container that can be used to group other widgets. |
|
3 | Represents a container that can be used to group other widgets. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, Bool, List, Instance |
|
17 | from IPython.utils.traitlets import Unicode, Bool, List, Instance | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class ContainerWidget(Widget): |
|
22 | class ContainerWidget(Widget): | |
23 | target_name = Unicode('ContainerWidgetModel') |
|
23 | target_name = Unicode('ContainerWidgetModel') | |
24 | default_view_name = Unicode('ContainerView') |
|
24 | default_view_name = Unicode('ContainerView') | |
25 |
|
25 | |||
26 | # Keys, all private and managed by helper methods. Flexible box model |
|
26 | # Keys, all private and managed by helper methods. Flexible box model | |
27 | # classes... |
|
27 | # classes... | |
28 |
|
|
28 | keys = ['_vbox', '_hbox', '_align_start', '_align_end', '_align_center', | |
29 | '_pack_start', '_pack_end', '_pack_center', '_flex0', '_flex1', |
|
29 | '_pack_start', '_pack_end', '_pack_center', '_flex0', '_flex1', | |
30 | '_flex2', 'description', 'button_text', |
|
30 | '_flex2', 'description', 'button_text', | |
31 | 'children'] |
|
31 | 'children'] + Widget.keys | |
32 | children = List(Instance(Widget)) |
|
32 | children = List(Instance(Widget)) | |
33 |
|
33 | |||
34 | description = Unicode() |
|
34 | description = Unicode() | |
35 | button_text = Unicode() |
|
35 | button_text = Unicode() | |
36 | _hbox = Bool(False) |
|
36 | _hbox = Bool(False) | |
37 | _vbox = Bool(False) |
|
37 | _vbox = Bool(False) | |
38 | _align_start = Bool(False) |
|
38 | _align_start = Bool(False) | |
39 | _align_end = Bool(False) |
|
39 | _align_end = Bool(False) | |
40 | _align_center = Bool(False) |
|
40 | _align_center = Bool(False) | |
41 | _pack_start = Bool(False) |
|
41 | _pack_start = Bool(False) | |
42 | _pack_end = Bool(False) |
|
42 | _pack_end = Bool(False) | |
43 | _pack_center = Bool(False) |
|
43 | _pack_center = Bool(False) | |
44 | _flex0 = Bool(False) |
|
44 | _flex0 = Bool(False) | |
45 | _flex1 = Bool(False) |
|
45 | _flex1 = Bool(False) | |
46 | _flex2 = Bool(False) |
|
46 | _flex2 = Bool(False) | |
47 |
|
47 | |||
48 | def hbox(self, enabled=True): |
|
48 | def hbox(self, enabled=True): | |
49 | """Make this container an hbox. Automatically disables conflicting |
|
49 | """Make this container an hbox. Automatically disables conflicting | |
50 | features. |
|
50 | features. | |
51 |
|
51 | |||
52 | Parameters |
|
52 | Parameters | |
53 | ---------- |
|
53 | ---------- | |
54 | enabled: bool (optional) |
|
54 | enabled: bool (optional) | |
55 | Enabled or disable the hbox feature of the container, defaults to |
|
55 | Enabled or disable the hbox feature of the container, defaults to | |
56 | True.""" |
|
56 | True.""" | |
57 | self._hbox = enabled |
|
57 | self._hbox = enabled | |
58 | if enabled: |
|
58 | if enabled: | |
59 | self._vbox = False |
|
59 | self._vbox = False | |
60 |
|
60 | |||
61 | def vbox(self, enabled=True): |
|
61 | def vbox(self, enabled=True): | |
62 | """Make this container an vbox. Automatically disables conflicting |
|
62 | """Make this container an vbox. Automatically disables conflicting | |
63 | features. |
|
63 | features. | |
64 |
|
64 | |||
65 | Parameters |
|
65 | Parameters | |
66 | ---------- |
|
66 | ---------- | |
67 | enabled: bool (optional) |
|
67 | enabled: bool (optional) | |
68 | Enabled or disable the vbox feature of the container, defaults to |
|
68 | Enabled or disable the vbox feature of the container, defaults to | |
69 | True.""" |
|
69 | True.""" | |
70 | self._vbox = enabled |
|
70 | self._vbox = enabled | |
71 | if enabled: |
|
71 | if enabled: | |
72 | self._hbox = False |
|
72 | self._hbox = False | |
73 |
|
73 | |||
74 | def align_start(self, enabled=True): |
|
74 | def align_start(self, enabled=True): | |
75 | """Make the contents of this container align to the start of the axis. |
|
75 | """Make the contents of this container align to the start of the axis. | |
76 | Automatically disables conflicting alignments. |
|
76 | Automatically disables conflicting alignments. | |
77 |
|
77 | |||
78 | Parameters |
|
78 | Parameters | |
79 | ---------- |
|
79 | ---------- | |
80 | enabled: bool (optional) |
|
80 | enabled: bool (optional) | |
81 | Enabled or disable the start alignment of the container, defaults to |
|
81 | Enabled or disable the start alignment of the container, defaults to | |
82 | True.""" |
|
82 | True.""" | |
83 | self._align_start = enabled |
|
83 | self._align_start = enabled | |
84 | if enabled: |
|
84 | if enabled: | |
85 | self._align_end = False |
|
85 | self._align_end = False | |
86 | self._align_center = False |
|
86 | self._align_center = False | |
87 |
|
87 | |||
88 | def align_end(self, enabled=True): |
|
88 | def align_end(self, enabled=True): | |
89 | """Make the contents of this container align to the end of the axis. |
|
89 | """Make the contents of this container align to the end of the axis. | |
90 | Automatically disables conflicting alignments. |
|
90 | Automatically disables conflicting alignments. | |
91 |
|
91 | |||
92 | Parameters |
|
92 | Parameters | |
93 | ---------- |
|
93 | ---------- | |
94 | enabled: bool (optional) |
|
94 | enabled: bool (optional) | |
95 | Enabled or disable the end alignment of the container, defaults to |
|
95 | Enabled or disable the end alignment of the container, defaults to | |
96 | True.""" |
|
96 | True.""" | |
97 | self._align_end = enabled |
|
97 | self._align_end = enabled | |
98 | if enabled: |
|
98 | if enabled: | |
99 | self._align_start = False |
|
99 | self._align_start = False | |
100 | self._align_center = False |
|
100 | self._align_center = False | |
101 |
|
101 | |||
102 | def align_center(self, enabled=True): |
|
102 | def align_center(self, enabled=True): | |
103 | """Make the contents of this container align to the center of the axis. |
|
103 | """Make the contents of this container align to the center of the axis. | |
104 | Automatically disables conflicting alignments. |
|
104 | Automatically disables conflicting alignments. | |
105 |
|
105 | |||
106 | Parameters |
|
106 | Parameters | |
107 | ---------- |
|
107 | ---------- | |
108 | enabled: bool (optional) |
|
108 | enabled: bool (optional) | |
109 | Enabled or disable the center alignment of the container, defaults to |
|
109 | Enabled or disable the center alignment of the container, defaults to | |
110 | True.""" |
|
110 | True.""" | |
111 | self._align_center = enabled |
|
111 | self._align_center = enabled | |
112 | if enabled: |
|
112 | if enabled: | |
113 | self._align_start = False |
|
113 | self._align_start = False | |
114 | self._align_end = False |
|
114 | self._align_end = False | |
115 |
|
115 | |||
116 |
|
116 | |||
117 | def pack_start(self, enabled=True): |
|
117 | def pack_start(self, enabled=True): | |
118 | """Make the contents of this container pack to the start of the axis. |
|
118 | """Make the contents of this container pack to the start of the axis. | |
119 | Automatically disables conflicting packings. |
|
119 | Automatically disables conflicting packings. | |
120 |
|
120 | |||
121 | Parameters |
|
121 | Parameters | |
122 | ---------- |
|
122 | ---------- | |
123 | enabled: bool (optional) |
|
123 | enabled: bool (optional) | |
124 | Enabled or disable the start packing of the container, defaults to |
|
124 | Enabled or disable the start packing of the container, defaults to | |
125 | True.""" |
|
125 | True.""" | |
126 | self._pack_start = enabled |
|
126 | self._pack_start = enabled | |
127 | if enabled: |
|
127 | if enabled: | |
128 | self._pack_end = False |
|
128 | self._pack_end = False | |
129 | self._pack_center = False |
|
129 | self._pack_center = False | |
130 |
|
130 | |||
131 | def pack_end(self, enabled=True): |
|
131 | def pack_end(self, enabled=True): | |
132 | """Make the contents of this container pack to the end of the axis. |
|
132 | """Make the contents of this container pack to the end of the axis. | |
133 | Automatically disables conflicting packings. |
|
133 | Automatically disables conflicting packings. | |
134 |
|
134 | |||
135 | Parameters |
|
135 | Parameters | |
136 | ---------- |
|
136 | ---------- | |
137 | enabled: bool (optional) |
|
137 | enabled: bool (optional) | |
138 | Enabled or disable the end packing of the container, defaults to |
|
138 | Enabled or disable the end packing of the container, defaults to | |
139 | True.""" |
|
139 | True.""" | |
140 | self._pack_end = enabled |
|
140 | self._pack_end = enabled | |
141 | if enabled: |
|
141 | if enabled: | |
142 | self._pack_start = False |
|
142 | self._pack_start = False | |
143 | self._pack_center = False |
|
143 | self._pack_center = False | |
144 |
|
144 | |||
145 | def pack_center(self, enabled=True): |
|
145 | def pack_center(self, enabled=True): | |
146 | """Make the contents of this container pack to the center of the axis. |
|
146 | """Make the contents of this container pack to the center of the axis. | |
147 | Automatically disables conflicting packings. |
|
147 | Automatically disables conflicting packings. | |
148 |
|
148 | |||
149 | Parameters |
|
149 | Parameters | |
150 | ---------- |
|
150 | ---------- | |
151 | enabled: bool (optional) |
|
151 | enabled: bool (optional) | |
152 | Enabled or disable the center packing of the container, defaults to |
|
152 | Enabled or disable the center packing of the container, defaults to | |
153 | True.""" |
|
153 | True.""" | |
154 | self._pack_center = enabled |
|
154 | self._pack_center = enabled | |
155 | if enabled: |
|
155 | if enabled: | |
156 | self._pack_start = False |
|
156 | self._pack_start = False | |
157 | self._pack_end = False |
|
157 | self._pack_end = False | |
158 |
|
158 | |||
159 |
|
159 | |||
160 | def flex0(self, enabled=True): |
|
160 | def flex0(self, enabled=True): | |
161 | """Put this container in flex0 mode. Automatically disables conflicting |
|
161 | """Put this container in flex0 mode. Automatically disables conflicting | |
162 | flex modes. See the widget tutorial part 5 example notebook for more |
|
162 | flex modes. See the widget tutorial part 5 example notebook for more | |
163 | information. |
|
163 | information. | |
164 |
|
164 | |||
165 | Parameters |
|
165 | Parameters | |
166 | ---------- |
|
166 | ---------- | |
167 | enabled: bool (optional) |
|
167 | enabled: bool (optional) | |
168 | Enabled or disable the flex0 attribute of the container, defaults to |
|
168 | Enabled or disable the flex0 attribute of the container, defaults to | |
169 | True.""" |
|
169 | True.""" | |
170 | self._flex0 = enabled |
|
170 | self._flex0 = enabled | |
171 | if enabled: |
|
171 | if enabled: | |
172 | self._flex1 = False |
|
172 | self._flex1 = False | |
173 | self._flex2 = False |
|
173 | self._flex2 = False | |
174 |
|
174 | |||
175 | def flex1(self, enabled=True): |
|
175 | def flex1(self, enabled=True): | |
176 | """Put this container in flex1 mode. Automatically disables conflicting |
|
176 | """Put this container in flex1 mode. Automatically disables conflicting | |
177 | flex modes. See the widget tutorial part 5 example notebook for more |
|
177 | flex modes. See the widget tutorial part 5 example notebook for more | |
178 | information. |
|
178 | information. | |
179 |
|
179 | |||
180 | Parameters |
|
180 | Parameters | |
181 | ---------- |
|
181 | ---------- | |
182 | enabled: bool (optional) |
|
182 | enabled: bool (optional) | |
183 | Enabled or disable the flex1 attribute of the container, defaults to |
|
183 | Enabled or disable the flex1 attribute of the container, defaults to | |
184 | True.""" |
|
184 | True.""" | |
185 | self._flex1 = enabled |
|
185 | self._flex1 = enabled | |
186 | if enabled: |
|
186 | if enabled: | |
187 | self._flex0 = False |
|
187 | self._flex0 = False | |
188 | self._flex2 = False |
|
188 | self._flex2 = False | |
189 |
|
189 | |||
190 | def flex2(self, enabled=True): |
|
190 | def flex2(self, enabled=True): | |
191 | """Put this container in flex2 mode. Automatically disables conflicting |
|
191 | """Put this container in flex2 mode. Automatically disables conflicting | |
192 | flex modes. See the widget tutorial part 5 example notebook for more |
|
192 | flex modes. See the widget tutorial part 5 example notebook for more | |
193 | information. |
|
193 | information. | |
194 |
|
194 | |||
195 | Parameters |
|
195 | Parameters | |
196 | ---------- |
|
196 | ---------- | |
197 | enabled: bool (optional) |
|
197 | enabled: bool (optional) | |
198 | Enabled or disable the flex2 attribute of the container, defaults to |
|
198 | Enabled or disable the flex2 attribute of the container, defaults to | |
199 | True.""" |
|
199 | True.""" | |
200 | self._flex2 = enabled |
|
200 | self._flex2 = enabled | |
201 | if enabled: |
|
201 | if enabled: | |
202 | self._flex0 = False |
|
202 | self._flex0 = False | |
203 | self._flex1 = False |
|
203 | self._flex1 = False |
@@ -1,30 +1,30 b'' | |||||
1 | """FloatWidget class. |
|
1 | """FloatWidget class. | |
2 |
|
2 | |||
3 | Represents an unbounded float using a widget. |
|
3 | Represents an unbounded float using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, Float, Bool, List |
|
17 | from IPython.utils.traitlets import Unicode, Float, Bool, List | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class FloatWidget(Widget): |
|
22 | class FloatWidget(Widget): | |
23 | target_name = Unicode('FloatWidgetModel') |
|
23 | target_name = Unicode('FloatWidgetModel') | |
24 | default_view_name = Unicode('FloatTextView') |
|
24 | default_view_name = Unicode('FloatTextView') | |
25 |
|
25 | |||
26 | # Keys |
|
26 | # Keys | |
27 |
|
|
27 | keys = ['value', 'disabled', 'description'] + Widget.keys | |
28 | value = Float(0.0, help="Float value") |
|
28 | value = Float(0.0, help="Float value") | |
29 | disabled = Bool(False, help="Enable or disable user changes") |
|
29 | disabled = Bool(False, help="Enable or disable user changes") | |
30 | description = Unicode(help="Description of the value this widget represents") |
|
30 | description = Unicode(help="Description of the value this widget represents") |
@@ -1,34 +1,34 b'' | |||||
1 | """FloatRangeWidget class. |
|
1 | """FloatRangeWidget class. | |
2 |
|
2 | |||
3 | Represents a bounded float using a widget. |
|
3 | Represents a bounded float using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, Float, Bool, List |
|
17 | from IPython.utils.traitlets import Unicode, Float, Bool, List | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class FloatRangeWidget(Widget): |
|
22 | class FloatRangeWidget(Widget): | |
23 | target_name = Unicode('FloatRangeWidgetModel') |
|
23 | target_name = Unicode('FloatRangeWidgetModel') | |
24 | default_view_name = Unicode('FloatSliderView') |
|
24 | default_view_name = Unicode('FloatSliderView') | |
25 |
|
25 | |||
26 | # Keys |
|
26 | # Keys | |
27 |
|
|
27 | keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + Widget.keys | |
28 | value = Float(0.0, help="Flaot value") |
|
28 | value = Float(0.0, help="Flaot value") | |
29 | max = Float(100.0, help="Max value") |
|
29 | max = Float(100.0, help="Max value") | |
30 | min = Float(0.0, help="Min value") |
|
30 | min = Float(0.0, help="Min value") | |
31 | disabled = Bool(False, help="Enable or disable user changes") |
|
31 | disabled = Bool(False, help="Enable or disable user changes") | |
32 | step = Float(0.1, help="Minimum step that the value can take (ignored by some views)") |
|
32 | step = Float(0.1, help="Minimum step that the value can take (ignored by some views)") | |
33 | orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)") |
|
33 | orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)") | |
34 | description = Unicode(help="Description of the value this widget represents") |
|
34 | description = Unicode(help="Description of the value this widget represents") |
@@ -1,38 +1,38 b'' | |||||
1 | """ButtonWidget class. |
|
1 | """ButtonWidget class. | |
2 |
|
2 | |||
3 | Represents a button in the frontend using a widget. Allows user to listen for |
|
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. |
|
4 | click events on the button and trigger backend code when the clicks are fired. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | # Copyright (c) 2013, the IPython Development Team. | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
10 | # | |
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 | import base64 |
|
17 | import base64 | |
18 |
|
18 | |||
19 | from .widget import Widget |
|
19 | from .widget import Widget | |
20 | from IPython.utils.traitlets import Unicode, Bytes |
|
20 | from IPython.utils.traitlets import Unicode, Bytes | |
21 |
|
21 | |||
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | # Classes |
|
23 | # Classes | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | class ImageWidget(Widget): |
|
25 | class ImageWidget(Widget): | |
26 | target_name = Unicode('ImageWidgetModel') |
|
26 | target_name = Unicode('ImageWidgetModel') | |
27 | default_view_name = Unicode('ImageView') |
|
27 | default_view_name = Unicode('ImageView') | |
28 |
|
28 | |||
29 | # Define the custom state properties to sync with the front-end |
|
29 | # Define the custom state properties to sync with the front-end | |
30 |
|
|
30 | keys = ['image_format', 'width', 'height', '_b64value'] + Widget.keys | |
31 | image_format = Unicode('png') |
|
31 | image_format = Unicode('png') | |
32 | width = Unicode() |
|
32 | width = Unicode() | |
33 | height = Unicode() |
|
33 | height = Unicode() | |
34 | _b64value = Unicode() |
|
34 | _b64value = Unicode() | |
35 |
|
35 | |||
36 | value = Bytes() |
|
36 | value = Bytes() | |
37 | def _value_changed(self, name, old, new): |
|
37 | def _value_changed(self, name, old, new): | |
38 | self._b64value = base64.b64encode(new) No newline at end of file |
|
38 | self._b64value = base64.b64encode(new) |
@@ -1,30 +1,30 b'' | |||||
1 | """IntWidget class. |
|
1 | """IntWidget class. | |
2 |
|
2 | |||
3 | Represents an unbounded int using a widget. |
|
3 | Represents an unbounded int using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, Int, Bool, List |
|
17 | from IPython.utils.traitlets import Unicode, Int, Bool, List | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class IntWidget(Widget): |
|
22 | class IntWidget(Widget): | |
23 | target_name = Unicode('IntWidgetModel') |
|
23 | target_name = Unicode('IntWidgetModel') | |
24 | default_view_name = Unicode('IntTextView') |
|
24 | default_view_name = Unicode('IntTextView') | |
25 |
|
25 | |||
26 | # Keys |
|
26 | # Keys | |
27 |
|
|
27 | keys = ['value', 'disabled', 'description'] + Widget.keys | |
28 | value = Int(0, help="Int value") |
|
28 | value = Int(0, help="Int value") | |
29 | disabled = Bool(False, help="Enable or disable user changes") |
|
29 | disabled = Bool(False, help="Enable or disable user changes") | |
30 | description = Unicode(help="Description of the value this widget represents") |
|
30 | description = Unicode(help="Description of the value this widget represents") |
@@ -1,34 +1,34 b'' | |||||
1 | """IntRangeWidget class. |
|
1 | """IntRangeWidget class. | |
2 |
|
2 | |||
3 | Represents a bounded int using a widget. |
|
3 | Represents a bounded int using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, Int, Bool, List |
|
17 | from IPython.utils.traitlets import Unicode, Int, Bool, List | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Classes |
|
20 | # Classes | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class IntRangeWidget(Widget): |
|
22 | class IntRangeWidget(Widget): | |
23 | target_name = Unicode('IntRangeWidgetModel') |
|
23 | target_name = Unicode('IntRangeWidgetModel') | |
24 | default_view_name = Unicode('IntSliderView') |
|
24 | default_view_name = Unicode('IntSliderView') | |
25 |
|
25 | |||
26 | # Keys |
|
26 | # Keys | |
27 |
|
|
27 | keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + Widget.keys | |
28 | value = Int(0, help="Int value") |
|
28 | value = Int(0, help="Int value") | |
29 | max = Int(100, help="Max value") |
|
29 | max = Int(100, help="Max value") | |
30 | min = Int(0, help="Min value") |
|
30 | min = Int(0, help="Min value") | |
31 | disabled = Bool(False, help="Enable or disable user changes") |
|
31 | disabled = Bool(False, help="Enable or disable user changes") | |
32 | step = Int(1, help="Minimum step that the value can take (ignored by some views)") |
|
32 | step = Int(1, help="Minimum step that the value can take (ignored by some views)") | |
33 | orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)") |
|
33 | orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)") | |
34 | description = Unicode(help="Description of the value this widget represents") |
|
34 | description = Unicode(help="Description of the value this widget represents") |
@@ -1,58 +1,58 b'' | |||||
1 | """MulticontainerWidget class. |
|
1 | """MulticontainerWidget class. | |
2 |
|
2 | |||
3 | Represents a multipage container that can be used to group other widgets into |
|
3 | Represents a multipage container that can be used to group other widgets into | |
4 | pages. |
|
4 | pages. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
7 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | # Copyright (c) 2013, the IPython Development Team. | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
10 | # | |
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
17 | from .widget import Widget |
|
17 | from .widget import Widget | |
18 | from IPython.utils.traitlets import Unicode, Dict, Int, List, Instance |
|
18 | from IPython.utils.traitlets import Unicode, Dict, Int, List, Instance | |
19 |
|
19 | |||
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
21 | # Classes |
|
21 | # Classes | |
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | class MulticontainerWidget(Widget): |
|
23 | class MulticontainerWidget(Widget): | |
24 | target_name = Unicode('MulticontainerWidgetModel') |
|
24 | target_name = Unicode('MulticontainerWidgetModel') | |
25 | default_view_name = Unicode('TabView') |
|
25 | default_view_name = Unicode('TabView') | |
26 |
|
26 | |||
27 | # Keys |
|
27 | # Keys | |
28 |
|
|
28 | keys = ['_titles', 'selected_index', 'children'] + Widget.keys | |
29 | _titles = Dict(help="Titles of the pages") |
|
29 | _titles = Dict(help="Titles of the pages") | |
30 | selected_index = Int(0) |
|
30 | selected_index = Int(0) | |
31 |
|
31 | |||
32 | children = List(Instance(Widget)) |
|
32 | children = List(Instance(Widget)) | |
33 |
|
33 | |||
34 | # Public methods |
|
34 | # Public methods | |
35 | def set_title(self, index, title): |
|
35 | def set_title(self, index, title): | |
36 | """Sets the title of a container page |
|
36 | """Sets the title of a container page | |
37 |
|
37 | |||
38 | Parameters |
|
38 | Parameters | |
39 | ---------- |
|
39 | ---------- | |
40 | index : int |
|
40 | index : int | |
41 | Index of the container page |
|
41 | Index of the container page | |
42 | title : unicode |
|
42 | title : unicode | |
43 | New title""" |
|
43 | New title""" | |
44 | self._titles[index] = title |
|
44 | self._titles[index] = title | |
45 | self.send_state('_titles') |
|
45 | self.send_state('_titles') | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | def get_title(self, index): |
|
48 | def get_title(self, index): | |
49 | """Gets the title of a container pages |
|
49 | """Gets the title of a container pages | |
50 |
|
50 | |||
51 | Parameters |
|
51 | Parameters | |
52 | ---------- |
|
52 | ---------- | |
53 | index : int |
|
53 | index : int | |
54 | Index of the container page""" |
|
54 | Index of the container page""" | |
55 | if index in self._titles: |
|
55 | if index in self._titles: | |
56 | return self._titles[index] |
|
56 | return self._titles[index] | |
57 | else: |
|
57 | else: | |
58 | return None |
|
58 | return None |
@@ -1,32 +1,32 b'' | |||||
1 | """SelectionWidget class. |
|
1 | """SelectionWidget class. | |
2 |
|
2 | |||
3 | Represents an enumeration using a widget. |
|
3 | Represents an enumeration using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | from .widget import Widget |
|
16 | from .widget import Widget | |
17 | from IPython.utils.traitlets import Unicode, List, Bool |
|
17 | from IPython.utils.traitlets import Unicode, List, Bool | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # SelectionWidget |
|
20 | # SelectionWidget | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | class SelectionWidget(Widget): |
|
22 | class SelectionWidget(Widget): | |
23 | target_name = Unicode('SelectionWidgetModel') |
|
23 | target_name = Unicode('SelectionWidgetModel') | |
24 | default_view_name = Unicode('DropdownView') |
|
24 | default_view_name = Unicode('DropdownView') | |
25 |
|
25 | |||
26 | # Keys |
|
26 | # Keys | |
27 |
|
|
27 | keys = ['value', 'values', 'disabled', 'description'] + Widget.keys | |
28 | value = Unicode(help="Selected value") |
|
28 | value = Unicode(help="Selected value") | |
29 | values = List(help="List of values the user can select") |
|
29 | values = List(help="List of values the user can select") | |
30 | disabled = Bool(False, help="Enable or disable user changes") |
|
30 | disabled = Bool(False, help="Enable or disable user changes") | |
31 | description = Unicode(help="Description of the value this widget represents") |
|
31 | description = Unicode(help="Description of the value this widget represents") | |
32 | No newline at end of file |
|
32 |
@@ -1,93 +1,93 b'' | |||||
1 | """StringWidget class. |
|
1 | """StringWidget class. | |
2 |
|
2 | |||
3 | Represents a unicode string using a widget. |
|
3 | Represents a unicode string using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
6 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
9 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | import inspect |
|
16 | import inspect | |
17 | import types |
|
17 | import types | |
18 |
|
18 | |||
19 | from .widget import Widget |
|
19 | from .widget import Widget | |
20 | from IPython.utils.traitlets import Unicode, Bool, List, Int |
|
20 | from IPython.utils.traitlets import Unicode, Bool, List, Int | |
21 |
|
21 | |||
22 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
23 | # Classes |
|
23 | # Classes | |
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | class StringWidget(Widget): |
|
25 | class StringWidget(Widget): | |
26 | target_name = Unicode('StringWidgetModel') |
|
26 | target_name = Unicode('StringWidgetModel') | |
27 | default_view_name = Unicode('TextBoxView') |
|
27 | default_view_name = Unicode('TextBoxView') | |
28 |
|
28 | |||
29 | # Keys |
|
29 | # Keys | |
30 |
|
|
30 | keys = ['value', 'disabled', 'description'] + Widget.keys | |
31 | value = Unicode(help="String value") |
|
31 | value = Unicode(help="String value") | |
32 | disabled = Bool(False, help="Enable or disable user changes") |
|
32 | disabled = Bool(False, help="Enable or disable user changes") | |
33 | description = Unicode(help="Description of the value this widget represents") |
|
33 | description = Unicode(help="Description of the value this widget represents") | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def __init__(self, **kwargs): |
|
36 | def __init__(self, **kwargs): | |
37 | super(StringWidget, self).__init__(**kwargs) |
|
37 | super(StringWidget, self).__init__(**kwargs) | |
38 | self._submission_callbacks = [] |
|
38 | self._submission_callbacks = [] | |
39 | self.on_msg(self._handle_string_msg) |
|
39 | self.on_msg(self._handle_string_msg) | |
40 |
|
40 | |||
41 |
|
41 | |||
42 | def scroll_to_bottom(self): |
|
42 | def scroll_to_bottom(self): | |
43 | self.send({"method": "scroll_to_bottom"}) |
|
43 | self.send({"method": "scroll_to_bottom"}) | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | def _handle_string_msg(self, content): |
|
46 | def _handle_string_msg(self, content): | |
47 | """Handle a msg from the front-end |
|
47 | """Handle a msg from the front-end | |
48 |
|
48 | |||
49 | Parameters |
|
49 | Parameters | |
50 | ---------- |
|
50 | ---------- | |
51 | content: dict |
|
51 | content: dict | |
52 | Content of the msg.""" |
|
52 | Content of the msg.""" | |
53 | if 'event' in content and content['event'] == 'submit': |
|
53 | if 'event' in content and content['event'] == 'submit': | |
54 | self._handle_submit() |
|
54 | self._handle_submit() | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | def on_submit(self, callback, remove=False): |
|
57 | def on_submit(self, callback, remove=False): | |
58 | """Register a callback to handle text submission (triggered when the |
|
58 | """Register a callback to handle text submission (triggered when the | |
59 | user clicks enter). |
|
59 | user clicks enter). | |
60 |
|
60 | |||
61 | Parameters |
|
61 | Parameters | |
62 | callback: Method handle |
|
62 | callback: Method handle | |
63 | Function to be called when the text has been submitted. Function |
|
63 | Function to be called when the text has been submitted. Function | |
64 | can have two possible signatures: |
|
64 | can have two possible signatures: | |
65 | callback() |
|
65 | callback() | |
66 | callback(sender) |
|
66 | callback(sender) | |
67 | remove: bool (optional) |
|
67 | remove: bool (optional) | |
68 | Whether or not to unregister the callback""" |
|
68 | Whether or not to unregister the callback""" | |
69 | if remove and callback in self._submission_callbacks: |
|
69 | if remove and callback in self._submission_callbacks: | |
70 | self._submission_callbacks.remove(callback) |
|
70 | self._submission_callbacks.remove(callback) | |
71 | elif not remove and not callback in self._submission_callbacks: |
|
71 | elif not remove and not callback in self._submission_callbacks: | |
72 | self._submission_callbacks.append(callback) |
|
72 | self._submission_callbacks.append(callback) | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | def _handle_submit(self): |
|
75 | def _handle_submit(self): | |
76 | """Handles when a string widget view is submitted.""" |
|
76 | """Handles when a string widget view is submitted.""" | |
77 | for handler in self._submission_callbacks: |
|
77 | for handler in self._submission_callbacks: | |
78 | if callable(handler): |
|
78 | if callable(handler): | |
79 | argspec = inspect.getargspec(handler) |
|
79 | argspec = inspect.getargspec(handler) | |
80 | nargs = len(argspec[0]) |
|
80 | nargs = len(argspec[0]) | |
81 |
|
81 | |||
82 | # Bound methods have an additional 'self' argument |
|
82 | # Bound methods have an additional 'self' argument | |
83 | if isinstance(handler, types.MethodType): |
|
83 | if isinstance(handler, types.MethodType): | |
84 | nargs -= 1 |
|
84 | nargs -= 1 | |
85 |
|
85 | |||
86 | # Call the callback |
|
86 | # Call the callback | |
87 | if nargs == 0: |
|
87 | if nargs == 0: | |
88 | handler() |
|
88 | handler() | |
89 | elif nargs == 1: |
|
89 | elif nargs == 1: | |
90 | handler(self) |
|
90 | handler(self) | |
91 | else: |
|
91 | else: | |
92 | raise TypeError('StringWidget submit callback must ' \ |
|
92 | raise TypeError('StringWidget submit callback must ' \ | |
93 | 'accept 0 or 1 arguments.') |
|
93 | 'accept 0 or 1 arguments.') |
General Comments 0
You need to be logged in to leave comments.
Login now