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