##// END OF EJS Templates
1-to-1 widget / view mapping
Jonathan Frederic -
Show More
@@ -1,13 +1,13 b''
1 from .widget import Widget, DOMWidget
1 from .widget import Widget, DOMWidget
2
2
3 from .widget_bool import BoolWidget
3 from .widget_bool import CheckBoxWidget, ToggleButtonWidget
4 from .widget_button import ButtonWidget
4 from .widget_button import ButtonWidget
5 from .widget_container import ContainerWidget
5 from .widget_container import ContainerWidget, ModalWidget
6 from .widget_float import FloatWidget
6 from .widget_float import FloatTextWidget
7 from .widget_float_range import FloatRangeWidget
7 from .widget_float_range import BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
8 from .widget_image import ImageWidget
8 from .widget_image import ImageWidget
9 from .widget_int import IntWidget
9 from .widget_int import IntTextWidget
10 from .widget_int_range import IntRangeWidget
10 from .widget_int_range import BoundedIntTextWidget, IntSliderWidget, IntProgressWidget
11 from .widget_selection import SelectionWidget
11 from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, ListBoxWidget
12 from .widget_selectioncontainer import SelectionContainerWidget
12 from .widget_selectioncontainer import TabWidget, AccordionWidget
13 from .widget_string import StringWidget
13 from .widget_string import HTMLWidget, LatexWidget, TextBoxWidget, TextAreaWidget
@@ -19,11 +19,14 b' from IPython.utils.traitlets import Unicode, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class BoolWidget(DOMWidget):
22 class CheckBoxWidget(DOMWidget):
23 view_name = Unicode('CheckboxView', sync=True)
23 view_name = Unicode('CheckBoxView', sync=True)
24
24
25 # Model Keys
25 # Model Keys
26 value = Bool(False, help="Bool value", sync=True)
26 value = Bool(False, help="Bool value", sync=True)
27 description = Unicode('', help="Description of the boolean (label).", sync=True)
27 description = Unicode('', help="Description of the boolean (label).", 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
30 class ToggleButtonWidget(CheckboxWidget):
31 view_name = Unicode('ToggleButtonView', sync=True)
29 No newline at end of file
32
@@ -28,3 +28,6 b' class ContainerWidget(DOMWidget):'
28
28
29 description = Unicode(sync=True)
29 description = Unicode(sync=True)
30 button_text = Unicode(sync=True)
30 button_text = Unicode(sync=True)
31
32 class ModalWidget(ContainerWidget):
33 view_name = Unicode('ModalView', sync=True)
@@ -19,7 +19,7 b' from IPython.utils.traitlets import Unicode, Float, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class FloatWidget(DOMWidget):
22 class FloatTextWidget(DOMWidget):
23 view_name = Unicode('FloatTextView', sync=True)
23 view_name = Unicode('FloatTextView', sync=True)
24
24
25 # Keys
25 # Keys
@@ -19,14 +19,20 b' from IPython.utils.traitlets import Unicode, Float, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class FloatRangeWidget(DOMWidget):
22 class BoundedFloatTextWidget(DOMWidget):
23 view_name = Unicode('FloatSliderView', sync=True)
23 view_name = Unicode('FloatTextView', sync=True)
24
25 # Keys
26 value = Float(0.0, help="Float value", sync=True)
24 value = Float(0.0, help="Float value", sync=True)
27 max = Float(100.0, help="Max value", sync=True)
25 max = Float(100.0, help="Max value", sync=True)
28 min = Float(0.0, help="Min value", sync=True)
26 min = Float(0.0, help="Min value", sync=True)
29 disabled = Bool(False, help="Enable or disable user changes", sync=True)
27 disabled = Bool(False, help="Enable or disable user changes", sync=True)
30 step = Float(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
28 step = Float(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
31 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
32 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)
30
31
32 class FloatSliderWidget(BoundedFloatTextWidget):
33 view_name = Unicode('FloatSliderView', sync=True)
34 orientation = Unicode(u'horizontal', help="Vertical or horizontal.", sync=True)
35
36
37 class FloatProgressWidget(BoundedFloatTextWidget):
38 view_name = Unicode('ProgressView', sync=True)
@@ -19,7 +19,7 b' from IPython.utils.traitlets import Unicode, Int, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class IntWidget(DOMWidget):
22 class IntTextWidget(DOMWidget):
23 view_name = Unicode('IntTextView', sync=True)
23 view_name = Unicode('IntTextView', sync=True)
24
24
25 # Keys
25 # Keys
@@ -19,8 +19,8 b' from IPython.utils.traitlets import Unicode, Int, Bool, List'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Classes
20 # Classes
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class IntRangeWidget(DOMWidget):
22 class BoundedIntTextWidget(DOMWidget):
23 view_name = Unicode('IntSliderView', sync=True)
23 view_name = Unicode('IntTextView', sync=True)
24
24
25 # Keys
25 # Keys
26 value = Int(0, help="Int value", sync=True)
26 value = Int(0, help="Int value", sync=True)
@@ -28,5 +28,13 b' class IntRangeWidget(DOMWidget):'
28 min = Int(0, help="Min value", sync=True)
28 min = Int(0, help="Min value", 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 step = Int(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
30 step = Int(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
31 orientation = Unicode(u'horizontal', help="Vertical or horizontal (ignored by some views)", sync=True)
32 description = Unicode(help="Description of the value this widget represents", sync=True)
31 description = Unicode(help="Description of the value this widget represents", sync=True)
32
33
34 class IntSliderWidget(BoundedIntTextWidget):
35 view_name = Unicode('IntSliderView', sync=True)
36 orientation = Unicode(u'horizontal', help="Vertical or horizontal.", sync=True)
37
38
39 class IntProgressWidget(BoundedIntTextWidget):
40 view_name = Unicode('ProgressView', sync=True)
@@ -19,12 +19,23 b' from IPython.utils.traitlets import Unicode, List, Bool'
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # SelectionWidget
20 # SelectionWidget
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 class SelectionWidget(DOMWidget):
22 class ToggleButtonsWidget(DOMWidget):
23 view_name = Unicode('DropdownView', sync=True)
23 view_name = Unicode('ToggleButtonsView', sync=True)
24
24
25 # Keys
25 # Keys
26 value = Unicode(help="Selected value", sync=True) # TODO: Any support
26 value = Unicode(help="Selected value", sync=True) # TODO: Any support
27 values = List(help="List of values the user can select", sync=True)
27 values = List(help="List of values the user can select", 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)
30 No newline at end of file
30
31
32 class DropdownWidget(SelectionWidget):
33 view_name = Unicode('DropdownView', sync=True)
34
35
36 class RadioButtonsWidget(SelectionWidget):
37 view_name = Unicode('RadioButtonsView', sync=True)
38
39
40 class ListBoxWidget(SelectionWidget):
41 view_name = Unicode('ListBoxView', sync=True)
@@ -20,8 +20,8 b' from IPython.utils.traitlets import Unicode, Dict, Int, List, Instance'
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # Classes
21 # Classes
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 class SelectionContainerWidget(DOMWidget):
23 class AccordionWidget(DOMWidget):
24 view_name = Unicode('TabView', sync=True)
24 view_name = Unicode('AccordionView', sync=True)
25
25
26 # Keys
26 # Keys
27 _titles = Dict(help="Titles of the pages", sync=True)
27 _titles = Dict(help="Titles of the pages", sync=True)
@@ -54,3 +54,7 b' class SelectionContainerWidget(DOMWidget):'
54 return self._titles[index]
54 return self._titles[index]
55 else:
55 else:
56 return None
56 return None
57
58
59 class TabWidget(AccordionWidget):
60 view_name = Unicode('TabView', sync=True)
@@ -22,8 +22,8 b' from IPython.utils.traitlets import Unicode, Bool, List, Int'
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 # Classes
23 # Classes
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
25 class StringWidget(DOMWidget):
25 class HTMLWidget(DOMWidget):
26 view_name = Unicode('TextBoxView', sync=True)
26 view_name = Unicode('HTMLView', sync=True)
27
27
28 # Keys
28 # Keys
29 value = Unicode(help="String value", sync=True)
29 value = Unicode(help="String value", sync=True)
@@ -31,16 +31,25 b' class StringWidget(DOMWidget):'
31 description = Unicode(help="Description of the value this widget represents", sync=True)
31 description = Unicode(help="Description of the value this widget represents", sync=True)
32
32
33
33
34 def __init__(self, **kwargs):
34 class LatexWidget(HTMLWidget):
35 super(StringWidget, self).__init__(**kwargs)
35 view_name = Unicode('LatexView', sync=True)
36 self._submission_callbacks = []
36
37 self.on_msg(self._handle_string_msg)
38
37
38 class TextAreaWidget(HTMLWidget):
39 view_name = Unicode('TextAreaView', sync=True)
39
40
40 def scroll_to_bottom(self):
41 def scroll_to_bottom(self):
41 self.send({"method": "scroll_to_bottom"})
42 self.send({"method": "scroll_to_bottom"})
42
43
43
44
45 class TextBoxWidget(HTMLWidget):
46 view_name = Unicode('TextBoxView', sync=True)
47
48 def __init__(self, **kwargs):
49 super(StringWidget, self).__init__(**kwargs)
50 self._submission_callbacks = []
51 self.on_msg(self._handle_string_msg)
52
44 def _handle_string_msg(self, content):
53 def _handle_string_msg(self, content):
45 """Handle a msg from the front-end
54 """Handle a msg from the front-end
46
55
@@ -49,8 +58,8 b' class StringWidget(DOMWidget):'
49 content: dict
58 content: dict
50 Content of the msg."""
59 Content of the msg."""
51 if 'event' in content and content['event'] == 'submit':
60 if 'event' in content and content['event'] == 'submit':
52 self._handle_submit()
61 for handler in self._submission_callbacks:
53
62 handler(self)
54
63
55 def on_submit(self, callback, remove=False):
64 def on_submit(self, callback, remove=False):
56 """Register a callback to handle text submission (triggered when the
65 """Register a callback to handle text submission (triggered when the
@@ -67,25 +76,19 b' class StringWidget(DOMWidget):'
67 if remove and callback in self._submission_callbacks:
76 if remove and callback in self._submission_callbacks:
68 self._submission_callbacks.remove(callback)
77 self._submission_callbacks.remove(callback)
69 elif not remove and not callback in self._submission_callbacks:
78 elif not remove and not callback in self._submission_callbacks:
70 self._submission_callbacks.append(callback)
79 if callable(callback):
71
80 argspec = inspect.getargspec(callback)
72
73 def _handle_submit(self):
74 """Handles when a string widget view is submitted."""
75 for handler in self._submission_callbacks:
76 if callable(handler):
77 argspec = inspect.getargspec(handler)
78 nargs = len(argspec[0])
81 nargs = len(argspec[0])
79
82
80 # Bound methods have an additional 'self' argument
83 # Bound methods have an additional 'self' argument
81 if isinstance(handler, types.MethodType):
84 if isinstance(callback, types.MethodType):
82 nargs -= 1
85 nargs -= 1
83
86
84 # Call the callback
87 # Call the callback
85 if nargs == 0:
88 if nargs == 0:
86 handler()
89 self._submission_callbacks.append(lambda sender: callback())
87 elif nargs == 1:
90 elif nargs == 1:
88 handler(self)
91 self._submission_callbacks.append(callback)
89 else:
92 else:
90 raise TypeError('StringWidget submit callback must ' \
93 raise TypeError('StringWidget submit callback must ' \
91 'accept 0 or 1 arguments.')
94 'accept 0 or 1 arguments.')
General Comments 0
You need to be logged in to leave comments. Login now