##// END OF EJS Templates
Use more conventional *args naming over *parg
Thomas Kluyver -
Show More
@@ -1,95 +1,95 b''
1 """String class.
1 """String 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 from .widget import DOMWidget, CallbackDispatcher, register
16 from .widget import DOMWidget, CallbackDispatcher, register
17 from IPython.utils.traitlets import Unicode, Bool
17 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
18 from IPython.utils.warn import DeprecatedClass
19
19
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21 # Classes
21 # Classes
22 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
23 class _String(DOMWidget):
23 class _String(DOMWidget):
24 """Base class used to create widgets that represent a string."""
24 """Base class used to create widgets that represent a string."""
25 value = Unicode(help="String value", sync=True)
25 value = Unicode(help="String value", sync=True)
26 disabled = Bool(False, help="Enable or disable user changes", sync=True)
26 disabled = Bool(False, help="Enable or disable user changes", sync=True)
27 description = Unicode(help="Description of the value this widget represents", sync=True)
27 description = Unicode(help="Description of the value this widget represents", sync=True)
28 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
28 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
29
29
30 def __init__(self, value=None, **kwargs):
30 def __init__(self, value=None, **kwargs):
31 if value is not None:
31 if value is not None:
32 kwargs['value'] = value
32 kwargs['value'] = value
33 super(_String, self).__init__(**kwargs)
33 super(_String, self).__init__(**kwargs)
34
34
35 @register('IPython.HTML')
35 @register('IPython.HTML')
36 class HTML(_String):
36 class HTML(_String):
37 """Renders the string `value` as HTML."""
37 """Renders the string `value` as HTML."""
38 _view_name = Unicode('HTMLView', sync=True)
38 _view_name = Unicode('HTMLView', sync=True)
39
39
40
40
41 @register('IPython.Latex')
41 @register('IPython.Latex')
42 class Latex(_String):
42 class Latex(_String):
43 """Renders math inside the string `value` as Latex (requires $ $ or $$ $$
43 """Renders math inside the string `value` as Latex (requires $ $ or $$ $$
44 and similar latex tags)."""
44 and similar latex tags)."""
45 _view_name = Unicode('LatexView', sync=True)
45 _view_name = Unicode('LatexView', sync=True)
46
46
47
47
48 @register('IPython.Textarea')
48 @register('IPython.Textarea')
49 class Textarea(_String):
49 class Textarea(_String):
50 """Multiline text area widget."""
50 """Multiline text area widget."""
51 _view_name = Unicode('TextareaView', sync=True)
51 _view_name = Unicode('TextareaView', sync=True)
52
52
53 def scroll_to_bottom(self):
53 def scroll_to_bottom(self):
54 self.send({"method": "scroll_to_bottom"})
54 self.send({"method": "scroll_to_bottom"})
55
55
56
56
57 @register('IPython.Text')
57 @register('IPython.Text')
58 class Text(_String):
58 class Text(_String):
59 """Single line textbox widget."""
59 """Single line textbox widget."""
60 _view_name = Unicode('TextView', sync=True)
60 _view_name = Unicode('TextView', sync=True)
61
61
62 def __init__(self, *parg, **kwargs):
62 def __init__(self, *args, **kwargs):
63 super(Text, self).__init__(*parg, **kwargs)
63 super(Text, self).__init__(*args, **kwargs)
64 self._submission_callbacks = CallbackDispatcher()
64 self._submission_callbacks = CallbackDispatcher()
65 self.on_msg(self._handle_string_msg)
65 self.on_msg(self._handle_string_msg)
66
66
67 def _handle_string_msg(self, _, content):
67 def _handle_string_msg(self, _, content):
68 """Handle a msg from the front-end.
68 """Handle a msg from the front-end.
69
69
70 Parameters
70 Parameters
71 ----------
71 ----------
72 content: dict
72 content: dict
73 Content of the msg."""
73 Content of the msg."""
74 if content.get('event', '') == 'submit':
74 if content.get('event', '') == 'submit':
75 self._submission_callbacks(self)
75 self._submission_callbacks(self)
76
76
77 def on_submit(self, callback, remove=False):
77 def on_submit(self, callback, remove=False):
78 """(Un)Register a callback to handle text submission.
78 """(Un)Register a callback to handle text submission.
79
79
80 Triggered when the user clicks enter.
80 Triggered when the user clicks enter.
81
81
82 Parameters
82 Parameters
83 ----------
83 ----------
84 callback: callable
84 callback: callable
85 Will be called with exactly one argument: the Widget instance
85 Will be called with exactly one argument: the Widget instance
86 remove: bool (optional)
86 remove: bool (optional)
87 Whether to unregister the callback"""
87 Whether to unregister the callback"""
88 self._submission_callbacks.register_callback(callback, remove=remove)
88 self._submission_callbacks.register_callback(callback, remove=remove)
89
89
90
90
91 # Remove in IPython 4.0
91 # Remove in IPython 4.0
92 HTMLWidget = DeprecatedClass(HTML, 'HTMLWidget')
92 HTMLWidget = DeprecatedClass(HTML, 'HTMLWidget')
93 LatexWidget = DeprecatedClass(Latex, 'LatexWidget')
93 LatexWidget = DeprecatedClass(Latex, 'LatexWidget')
94 TextareaWidget = DeprecatedClass(Textarea, 'TextareaWidget')
94 TextareaWidget = DeprecatedClass(Textarea, 'TextareaWidget')
95 TextWidget = DeprecatedClass(Text, 'TextWidget')
95 TextWidget = DeprecatedClass(Text, 'TextWidget')
General Comments 0
You need to be logged in to leave comments. Login now