##// END OF EJS Templates
s/Widget/DOMWidget s/BaseWidget/Widget
Jonathan Frederic -
Show More
@@ -1,4 +1,4 b''
1 from .widget import Widget
1 from .widget import Widget, DOMWidget
2
2
3 from .widget_bool import BoolWidget
3 from .widget_bool import BoolWidget
4 from .widget_button import ButtonWidget
4 from .widget_button import ButtonWidget
@@ -31,7 +31,7 b' from IPython.utils.py3compat import string_types'
31 # Classes
31 # Classes
32 #-----------------------------------------------------------------------------
32 #-----------------------------------------------------------------------------
33
33
34 class BaseWidget(LoggingConfigurable):
34 class Widget(LoggingConfigurable):
35
35
36 # Shared declarations (Class level)
36 # Shared declarations (Class level)
37 widget_construction_callback = None
37 widget_construction_callback = None
@@ -42,12 +42,12 b' class BaseWidget(LoggingConfigurable):'
42 """Class method, registers a callback to be called when a widget is
42 """Class method, registers a callback to be called when a widget is
43 constructed. The callback must have the following signature:
43 constructed. The callback must have the following signature:
44 callback(widget)"""
44 callback(widget)"""
45 BaseWidget.widget_construction_callback = callback
45 Widget.widget_construction_callback = callback
46
46
47 def _handle_widget_constructed(widget):
47 def _handle_widget_constructed(widget):
48 """Class method, called when a widget is constructed."""
48 """Class method, called when a widget is constructed."""
49 if BaseWidget.widget_construction_callback is not None and callable(BaseWidget.widget_construction_callback):
49 if Widget.widget_construction_callback is not None and callable(Widget.widget_construction_callback):
50 BaseWidget.widget_construction_callback(widget)
50 Widget.widget_construction_callback(widget)
51
51
52
52
53
53
@@ -68,10 +68,10 b' class BaseWidget(LoggingConfigurable):'
68 """
68 """
69 self._display_callbacks = []
69 self._display_callbacks = []
70 self._msg_callbacks = []
70 self._msg_callbacks = []
71 super(BaseWidget, self).__init__(**kwargs)
71 super(Widget, self).__init__(**kwargs)
72
72
73 self.on_trait_change(self._handle_property_changed, self.keys)
73 self.on_trait_change(self._handle_property_changed, self.keys)
74 BaseWidget._handle_widget_constructed(self)
74 Widget._handle_widget_constructed(self)
75
75
76 def __del__(self):
76 def __del__(self):
77 """Object disposal"""
77 """Object disposal"""
@@ -205,14 +205,14 b' class BaseWidget(LoggingConfigurable):'
205 for k in keys:
205 for k in keys:
206 value = getattr(self, k)
206 value = getattr(self, k)
207
207
208 # a more elegant solution to encoding BaseWidgets would be
208 # a more elegant solution to encoding Widgets would be
209 # to tap into the JSON encoder and teach it how to deal
209 # to tap into the JSON encoder and teach it how to deal
210 # with BaseWidget objects, or maybe just teach the JSON
210 # with Widget objects, or maybe just teach the JSON
211 # encoder to look for a _repr_json property before giving
211 # encoder to look for a _repr_json property before giving
212 # up encoding
212 # up encoding
213 if isinstance(value, BaseWidget):
213 if isinstance(value, Widget):
214 value = value.model_id
214 value = value.model_id
215 elif isinstance(value, list) and len(value)>0 and isinstance(value[0], BaseWidget):
215 elif isinstance(value, list) and len(value)>0 and isinstance(value[0], Widget):
216 # assume all elements of the list are widgets
216 # assume all elements of the list are widgets
217 value = [i.model_id for i in value]
217 value = [i.model_id for i in value]
218 state[k] = value
218 state[k] = value
@@ -321,13 +321,13 b' class BaseWidget(LoggingConfigurable):'
321 return False
321 return False
322
322
323
323
324 class Widget(BaseWidget):
324 class DOMWidget(Widget):
325 visible = Bool(True, help="Whether or not the widget is visible.")
325 visible = Bool(True, help="Whether or not the widget is visible.")
326
326
327 # Private/protected declarations
327 # Private/protected declarations
328 _css = Dict() # Internal CSS property dict
328 _css = Dict() # Internal CSS property dict
329
329
330 keys = ['visible', '_css'] + BaseWidget.keys
330 keys = ['visible', '_css'] + Widget.keys
331
331
332 def get_css(self, key, selector=""):
332 def get_css(self, key, selector=""):
333 """Get a CSS property of the widget. Note, this function does not
333 """Get a CSS property of the widget. Note, this function does not
@@ -13,18 +13,18 b' Represents a boolean using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class BoolWidget(DOMWidget):
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 keys = ['value', 'description', 'disabled'] + Widget.keys
27 keys = ['value', 'description', 'disabled'] + DOMWidget.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.")
@@ -17,18 +17,18 b' click events on the button and trigger backend code when the clicks are fired.'
17 import inspect
17 import inspect
18 import types
18 import types
19
19
20 from .widget import Widget
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(Widget):
26 class ButtonWidget(DOMWidget):
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 keys = ['description', 'disabled'] + Widget.keys
31 keys = ['description', 'disabled'] + DOMWidget.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
@@ -13,13 +13,13 b' Represents a container that can be used to group other widgets.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class ContainerWidget(DOMWidget):
23 target_name = Unicode('ContainerWidgetModel')
23 target_name = Unicode('ContainerWidgetModel')
24 default_view_name = Unicode('ContainerView')
24 default_view_name = Unicode('ContainerView')
25
25
@@ -28,8 +28,8 b' class ContainerWidget(Widget):'
28 keys = ['_vbox', '_hbox', '_align_start', '_align_end', '_align_center',
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'] + Widget.keys
31 'children'] + DOMWidget.keys
32 children = List(Instance(Widget))
32 children = List(Instance(DOMWidget))
33
33
34 description = Unicode()
34 description = Unicode()
35 button_text = Unicode()
35 button_text = Unicode()
@@ -13,18 +13,18 b' Represents an unbounded float using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class FloatWidget(DOMWidget):
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 keys = ['value', 'disabled', 'description'] + Widget.keys
27 keys = ['value', 'disabled', 'description'] + DOMWidget.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")
@@ -13,18 +13,18 b' Represents a bounded float using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class FloatRangeWidget(DOMWidget):
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 keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + Widget.keys
27 keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + DOMWidget.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")
@@ -16,18 +16,18 b' click events on the button and trigger backend code when the clicks are fired.'
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 import base64
17 import base64
18
18
19 from .widget import Widget
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(Widget):
25 class ImageWidget(DOMWidget):
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 keys = ['image_format', 'width', 'height', '_b64value'] + Widget.keys
30 keys = ['image_format', 'width', 'height', '_b64value'] + DOMWidget.keys
31 image_format = Unicode('png')
31 image_format = Unicode('png')
32 width = Unicode()
32 width = Unicode()
33 height = Unicode()
33 height = Unicode()
@@ -13,18 +13,18 b' Represents an unbounded int using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class IntWidget(DOMWidget):
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 keys = ['value', 'disabled', 'description'] + Widget.keys
27 keys = ['value', 'disabled', 'description'] + DOMWidget.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")
@@ -13,18 +13,18 b' Represents a bounded int using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class IntRangeWidget(DOMWidget):
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 keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + Widget.keys
27 keys = ['value', 'step', 'max', 'min', 'disabled', 'orientation', 'description'] + DOMWidget.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")
@@ -14,22 +14,22 b' pages.'
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from .widget import Widget
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 MulticontainerWidget(Widget):
23 class MulticontainerWidget(DOMWidget):
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 keys = ['_titles', 'selected_index', 'children'] + Widget.keys
28 keys = ['_titles', 'selected_index', 'children'] + DOMWidget.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(DOMWidget))
33
33
34 # Public methods
34 # Public methods
35 def set_title(self, index, title):
35 def set_title(self, index, title):
@@ -13,18 +13,18 b' Represents an enumeration using a widget.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import Widget
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(Widget):
22 class SelectionWidget(DOMWidget):
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 keys = ['value', 'values', 'disabled', 'description'] + Widget.keys
27 keys = ['value', 'values', 'disabled', 'description'] + DOMWidget.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")
@@ -16,18 +16,18 b' Represents a unicode string using a widget.'
16 import inspect
16 import inspect
17 import types
17 import types
18
18
19 from .widget import Widget
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(Widget):
25 class StringWidget(DOMWidget):
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 keys = ['value', 'disabled', 'description'] + Widget.keys
30 keys = ['value', 'disabled', 'description'] + DOMWidget.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")
General Comments 0
You need to be logged in to leave comments. Login now