##// END OF EJS Templates
Added sync=True to all view name attrs
Jonathan Frederic -
Show More
@@ -1,30 +1,30 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class BoolWidget(DOMWidget):
23 target_name = Unicode('BoolWidgetModel')
23 target_name = Unicode('BoolWidgetModel')
24 view_name = Unicode('CheckboxView')
24 view_name = Unicode('CheckboxView', sync=True)
25
25
26 # Model Keys
26 # Model Keys
27 value = Bool(False, help="Bool value", sync=True)
27 value = Bool(False, help="Bool value", sync=True)
28 description = Unicode('', help="Description of the boolean (label).", sync=True)
28 description = Unicode('', help="Description of the boolean (label).", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
30 No newline at end of file
30
@@ -1,92 +1,92 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 DOMWidget
20 from .widget import DOMWidget
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(DOMWidget):
26 class ButtonWidget(DOMWidget):
27 target_name = Unicode('ButtonWidgetModel')
27 target_name = Unicode('ButtonWidgetModel')
28 view_name = Unicode('ButtonView')
28 view_name = Unicode('ButtonView', sync=True)
29
29
30 # Keys
30 # Keys
31 description = Unicode('', help="Description of the button (label).", sync=True)
31 description = Unicode('', help="Description of the button (label).", sync=True)
32 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
32 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
33
33
34
34
35 def __init__(self, **kwargs):
35 def __init__(self, **kwargs):
36 super(ButtonWidget, self).__init__(**kwargs)
36 super(ButtonWidget, self).__init__(**kwargs)
37
37
38 self._click_handlers = []
38 self._click_handlers = []
39 self.on_msg(self._handle_button_msg)
39 self.on_msg(self._handle_button_msg)
40
40
41
41
42 def on_click(self, callback, remove=False):
42 def on_click(self, callback, remove=False):
43 """Register a callback to execute when the button is clicked. The
43 """Register a callback to execute when the button is clicked. The
44 callback can either accept no parameters or one sender parameter:
44 callback can either accept no parameters or one sender parameter:
45 - callback()
45 - callback()
46 - callback(sender)
46 - callback(sender)
47 If the callback has a sender parameter, the ButtonWidget instance that
47 If the callback has a sender parameter, the ButtonWidget instance that
48 called the callback will be passed into the method as the sender.
48 called the callback will be passed into the method as the sender.
49
49
50 Parameters
50 Parameters
51 ----------
51 ----------
52 remove : bool (optional)
52 remove : bool (optional)
53 Set to true to remove the callback from the list of callbacks."""
53 Set to true to remove the callback from the list of callbacks."""
54 if remove:
54 if remove:
55 self._click_handlers.remove(callback)
55 self._click_handlers.remove(callback)
56 elif not callback in self._click_handlers:
56 elif not callback in self._click_handlers:
57 self._click_handlers.append(callback)
57 self._click_handlers.append(callback)
58
58
59
59
60 def _handle_button_msg(self, content):
60 def _handle_button_msg(self, content):
61 """Handle a msg from the front-end
61 """Handle a msg from the front-end
62
62
63 Parameters
63 Parameters
64 ----------
64 ----------
65 content: dict
65 content: dict
66 Content of the msg."""
66 Content of the msg."""
67 if 'event' in content and content['event'] == 'click':
67 if 'event' in content and content['event'] == 'click':
68 self._handle_click()
68 self._handle_click()
69
69
70
70
71 def _handle_click(self):
71 def _handle_click(self):
72 """Handles when the button has been clicked. Fires on_click
72 """Handles when the button has been clicked. Fires on_click
73 callbacks when appropriate."""
73 callbacks when appropriate."""
74
74
75 for handler in self._click_handlers:
75 for handler in self._click_handlers:
76 if callable(handler):
76 if callable(handler):
77 argspec = inspect.getargspec(handler)
77 argspec = inspect.getargspec(handler)
78 nargs = len(argspec[0])
78 nargs = len(argspec[0])
79
79
80 # Bound methods have an additional 'self' argument
80 # Bound methods have an additional 'self' argument
81 if isinstance(handler, types.MethodType):
81 if isinstance(handler, types.MethodType):
82 nargs -= 1
82 nargs -= 1
83
83
84 # Call the callback
84 # Call the callback
85 if nargs == 0:
85 if nargs == 0:
86 handler()
86 handler()
87 elif nargs == 1:
87 elif nargs == 1:
88 handler(self)
88 handler(self)
89 else:
89 else:
90 raise TypeError('ButtonWidget click callback must ' \
90 raise TypeError('ButtonWidget click callback must ' \
91 'accept 0 or 1 arguments.')
91 'accept 0 or 1 arguments.')
92
92
@@ -1,31 +1,31 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class ContainerWidget(DOMWidget):
23 target_name = Unicode('ContainerWidgetModel')
23 target_name = Unicode('ContainerWidgetModel')
24 view_name = Unicode('ContainerView')
24 view_name = Unicode('ContainerView', sync=True)
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 children = List(Instance(DOMWidget), sync=True)
28 children = List(Instance(DOMWidget), sync=True)
29
29
30 description = Unicode(sync=True)
30 description = Unicode(sync=True)
31 button_text = Unicode(sync=True)
31 button_text = Unicode(sync=True)
@@ -1,29 +1,29 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class FloatWidget(DOMWidget):
23 target_name = Unicode('FloatWidgetModel')
23 target_name = Unicode('FloatWidgetModel')
24 view_name = Unicode('FloatTextView')
24 view_name = Unicode('FloatTextView', sync=True)
25
25
26 # Keys
26 # Keys
27 value = Float(0.0, help="Float value", sync=True)
27 value = Float(0.0, help="Float value", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
29 description = Unicode(help="Description of the value this widget represents", sync=True)
29 description = Unicode(help="Description of the value this widget represents", sync=True)
@@ -1,33 +1,33 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class FloatRangeWidget(DOMWidget):
23 target_name = Unicode('FloatRangeWidgetModel')
23 target_name = Unicode('FloatRangeWidgetModel')
24 view_name = Unicode('FloatSliderView')
24 view_name = Unicode('FloatSliderView', sync=True)
25
25
26 # Keys
26 # Keys
27 value = Float(0.0, help="Float value", sync=True)
27 value = Float(0.0, help="Float value", sync=True)
28 max = Float(100.0, help="Max value", sync=True)
28 max = Float(100.0, help="Max value", sync=True)
29 min = Float(0.0, help="Min value", sync=True)
29 min = Float(0.0, help="Min value", sync=True)
30 disabled = Bool(False, help="Enable or disable user changes", sync=True)
30 disabled = Bool(False, help="Enable or disable user changes", sync=True)
31 step = Float(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
31 step = Float(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
32 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
32 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
33 description = Unicode(help="Description of the value this widget represents", sync=True)
33 description = Unicode(help="Description of the value this widget represents", sync=True)
@@ -1,37 +1,37 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 DOMWidget
19 from .widget import DOMWidget
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(DOMWidget):
25 class ImageWidget(DOMWidget):
26 target_name = Unicode('ImageWidgetModel')
26 target_name = Unicode('ImageWidgetModel')
27 view_name = Unicode('ImageView')
27 view_name = Unicode('ImageView', sync=True)
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 format = Unicode('png', sync=True)
30 format = Unicode('png', sync=True)
31 width = Unicode(sync=True) # TODO: C unicode
31 width = Unicode(sync=True) # TODO: C unicode
32 height = Unicode(sync=True)
32 height = Unicode(sync=True)
33 _b64value = Unicode(sync=True)
33 _b64value = Unicode(sync=True)
34
34
35 value = Bytes()
35 value = Bytes()
36 def _value_changed(self, name, old, new):
36 def _value_changed(self, name, old, new):
37 self._b64value = base64.b64encode(new) No newline at end of file
37 self._b64value = base64.b64encode(new)
@@ -1,29 +1,29 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class IntWidget(DOMWidget):
23 target_name = Unicode('IntWidgetModel')
23 target_name = Unicode('IntWidgetModel')
24 view_name = Unicode('IntTextView')
24 view_name = Unicode('IntTextView', sync=True)
25
25
26 # Keys
26 # Keys
27 value = Int(0, help="Int value", sync=True)
27 value = Int(0, help="Int value", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
28 disabled = Bool(False, help="Enable or disable user changes", sync=True)
29 description = Unicode(help="Description of the value this widget represents", sync=True)
29 description = Unicode(help="Description of the value this widget represents", sync=True)
@@ -1,33 +1,33 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class IntRangeWidget(DOMWidget):
23 target_name = Unicode('IntRangeWidgetModel')
23 target_name = Unicode('IntRangeWidgetModel')
24 view_name = Unicode('IntSliderView')
24 view_name = Unicode('IntSliderView', sync=True)
25
25
26 # Keys
26 # Keys
27 value = Int(0, help="Int value", sync=True)
27 value = Int(0, help="Int value", sync=True)
28 max = Int(100, help="Max value", sync=True)
28 max = Int(100, help="Max value", sync=True)
29 min = Int(0, help="Min value", sync=True)
29 min = Int(0, help="Min value", sync=True)
30 disabled = Bool(False, help="Enable or disable user changes", sync=True)
30 disabled = Bool(False, help="Enable or disable user changes", sync=True)
31 step = Int(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
31 step = Int(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
32 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
32 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
33 description = Unicode(help="Description of the value this widget represents", sync=True)
33 description = Unicode(help="Description of the value this widget represents", sync=True)
@@ -1,31 +1,31 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 DOMWidget
16 from .widget import DOMWidget
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(DOMWidget):
22 class SelectionWidget(DOMWidget):
23 target_name = Unicode('SelectionWidgetModel')
23 target_name = Unicode('SelectionWidgetModel')
24 view_name = Unicode('DropdownView')
24 view_name = Unicode('DropdownView', sync=True)
25
25
26 # Keys
26 # Keys
27 value = Unicode(help="Selected value", sync=True) # TODO: Any support
27 value = Unicode(help="Selected value", sync=True) # TODO: Any support
28 values = List(help="List of values the user can select", sync=True)
28 values = List(help="List of values the user can select", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes", sync=True)
30 description = Unicode(help="Description of the value this widget represents", sync=True)
30 description = Unicode(help="Description of the value this widget represents", sync=True)
31 No newline at end of file
31
@@ -1,57 +1,57 b''
1 """SelectionContainerWidget class.
1 """SelectionContainerWidget 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 DOMWidget
17 from .widget import DOMWidget
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 SelectionContainerWidget(DOMWidget):
23 class SelectionContainerWidget(DOMWidget):
24 target_name = Unicode('SelectionContainerWidgetModel')
24 target_name = Unicode('SelectionContainerWidgetModel')
25 view_name = Unicode('TabView')
25 view_name = Unicode('TabView', sync=True)
26
26
27 # Keys
27 # Keys
28 _titles = Dict(help="Titles of the pages", sync=True)
28 _titles = Dict(help="Titles of the pages", sync=True)
29 selected_index = Int(0, sync=True)
29 selected_index = Int(0, sync=True)
30
30
31 children = List(Instance(DOMWidget))
31 children = List(Instance(DOMWidget))
32
32
33 # Public methods
33 # Public methods
34 def set_title(self, index, title):
34 def set_title(self, index, title):
35 """Sets the title of a container page
35 """Sets the title of a container page
36
36
37 Parameters
37 Parameters
38 ----------
38 ----------
39 index : int
39 index : int
40 Index of the container page
40 Index of the container page
41 title : unicode
41 title : unicode
42 New title"""
42 New title"""
43 self._titles[index] = title
43 self._titles[index] = title
44 self.send_state('_titles')
44 self.send_state('_titles')
45
45
46
46
47 def get_title(self, index):
47 def get_title(self, index):
48 """Gets the title of a container pages
48 """Gets the title of a container pages
49
49
50 Parameters
50 Parameters
51 ----------
51 ----------
52 index : int
52 index : int
53 Index of the container page"""
53 Index of the container page"""
54 if index in self._titles:
54 if index in self._titles:
55 return self._titles[index]
55 return self._titles[index]
56 else:
56 else:
57 return None
57 return None
@@ -1,92 +1,92 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 DOMWidget
19 from .widget import DOMWidget
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(DOMWidget):
25 class StringWidget(DOMWidget):
26 target_name = Unicode('StringWidgetModel')
26 target_name = Unicode('StringWidgetModel')
27 view_name = Unicode('TextBoxView')
27 view_name = Unicode('TextBoxView', sync=True)
28
28
29 # Keys
29 # Keys
30 value = Unicode(help="String value", sync=True)
30 value = Unicode(help="String value", sync=True)
31 disabled = Bool(False, help="Enable or disable user changes", sync=True)
31 disabled = Bool(False, help="Enable or disable user changes", sync=True)
32 description = Unicode(help="Description of the value this widget represents", sync=True)
32 description = Unicode(help="Description of the value this widget represents", sync=True)
33
33
34
34
35 def __init__(self, **kwargs):
35 def __init__(self, **kwargs):
36 super(StringWidget, self).__init__(**kwargs)
36 super(StringWidget, self).__init__(**kwargs)
37 self._submission_callbacks = []
37 self._submission_callbacks = []
38 self.on_msg(self._handle_string_msg)
38 self.on_msg(self._handle_string_msg)
39
39
40
40
41 def scroll_to_bottom(self):
41 def scroll_to_bottom(self):
42 self.send({"method": "scroll_to_bottom"})
42 self.send({"method": "scroll_to_bottom"})
43
43
44
44
45 def _handle_string_msg(self, content):
45 def _handle_string_msg(self, content):
46 """Handle a msg from the front-end
46 """Handle a msg from the front-end
47
47
48 Parameters
48 Parameters
49 ----------
49 ----------
50 content: dict
50 content: dict
51 Content of the msg."""
51 Content of the msg."""
52 if 'event' in content and content['event'] == 'submit':
52 if 'event' in content and content['event'] == 'submit':
53 self._handle_submit()
53 self._handle_submit()
54
54
55
55
56 def on_submit(self, callback, remove=False):
56 def on_submit(self, callback, remove=False):
57 """Register a callback to handle text submission (triggered when the
57 """Register a callback to handle text submission (triggered when the
58 user clicks enter).
58 user clicks enter).
59
59
60 Parameters
60 Parameters
61 callback: Method handle
61 callback: Method handle
62 Function to be called when the text has been submitted. Function
62 Function to be called when the text has been submitted. Function
63 can have two possible signatures:
63 can have two possible signatures:
64 callback()
64 callback()
65 callback(sender)
65 callback(sender)
66 remove: bool (optional)
66 remove: bool (optional)
67 Whether or not to unregister the callback"""
67 Whether or not to unregister the callback"""
68 if remove and callback in self._submission_callbacks:
68 if remove and callback in self._submission_callbacks:
69 self._submission_callbacks.remove(callback)
69 self._submission_callbacks.remove(callback)
70 elif not remove and not callback in self._submission_callbacks:
70 elif not remove and not callback in self._submission_callbacks:
71 self._submission_callbacks.append(callback)
71 self._submission_callbacks.append(callback)
72
72
73
73
74 def _handle_submit(self):
74 def _handle_submit(self):
75 """Handles when a string widget view is submitted."""
75 """Handles when a string widget view is submitted."""
76 for handler in self._submission_callbacks:
76 for handler in self._submission_callbacks:
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('StringWidget submit callback must ' \
91 raise TypeError('StringWidget submit callback must ' \
92 'accept 0 or 1 arguments.')
92 'accept 0 or 1 arguments.')
General Comments 0
You need to be logged in to leave comments. Login now