##// END OF EJS Templates
Replace O(N^2) algorithm with a faster one.
Replace O(N^2) algorithm with a faster one.

File last commit:

r14670:3644592c
r14699:48fcdd1f
Show More
widget_string.py
75 lines | 2.6 KiB | text/x-python | PythonLexer
Jonathan Frederic
Cleaned up Python widget code.
r14283 """StringWidget class.
Represents a unicode string using a widget.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Jonathan Frederic
Added new CallbackDispatcher class
r14658 from .widget import DOMWidget, CallbackDispatcher
Jonathan Frederic
s/Int/CInt s/Float/CFloat
r14603 from IPython.utils.traitlets import Unicode, Bool, List
Jonathan Frederic
Add string widget
r14243
Jonathan Frederic
Cleaned up Python widget code.
r14283 #-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
Jonathan Frederic
Create base widget classes
r14670 class _StringWidget(DOMWidget):
Jonathan Frederic
sync=True isntead of a keys list
r14588 value = Unicode(help="String value", sync=True)
disabled = Bool(False, help="Enable or disable user changes", sync=True)
description = Unicode(help="Description of the value this widget represents", sync=True)
Jonathan Frederic
Added TextBox submit event
r14391
Jonathan Frederic
Create base widget classes
r14670 class HTMLWidget(_StringWidget):
view_name = Unicode('HTMLView', sync=True)
class LatexWidget(_StringWidget):
Jonathan Frederic
1-to-1 widget / view mapping
r14592 view_name = Unicode('LatexView', sync=True)
Jonathan Frederic
Added TextBox submit event
r14391
Jonathan Frederic
Create base widget classes
r14670 class TextAreaWidget(_StringWidget):
Jonathan Frederic
1-to-1 widget / view mapping
r14592 view_name = Unicode('TextAreaView', sync=True)
Jonathan Frederic
Added TextBox submit event
r14391
Jonathan Frederic
Add scroll_to_bottom method for TextAreaView (StringWidget).
r14393 def scroll_to_bottom(self):
Jonathan Frederic
Fix scroll_to_bottom
r14406 self.send({"method": "scroll_to_bottom"})
Jonathan Frederic
Add scroll_to_bottom method for TextAreaView (StringWidget).
r14393
Jonathan Frederic
Create base widget classes
r14670 class TextBoxWidget(_StringWidget):
Jonathan Frederic
1-to-1 widget / view mapping
r14592 view_name = Unicode('TextBoxView', sync=True)
def __init__(self, **kwargs):
Jonathan Frederic
More fixes
r14595 super(TextBoxWidget, self).__init__(**kwargs)
Jonathan Frederic
Added new CallbackDispatcher class
r14658 self._submission_callbacks = CallbackDispatcher(acceptable_nargs=[0, 1])
Jonathan Frederic
1-to-1 widget / view mapping
r14592 self.on_msg(self._handle_string_msg)
Jonathan Frederic
Changed on_submit to use custom messages instead of stateful communcation
r14402 def _handle_string_msg(self, content):
Jonathan Frederic
More PEP8 changes
r14607 """Handle a msg from the front-end.
Jonathan Frederic
Changed on_submit to use custom messages instead of stateful communcation
r14402
Parameters
----------
content: dict
Content of the msg."""
if 'event' in content and content['event'] == 'submit':
Jonathan Frederic
Added new CallbackDispatcher class
r14658 self._submission_callbacks()
self._submission_callbacks(self)
Jonathan Frederic
Changed on_submit to use custom messages instead of stateful communcation
r14402
Jonathan Frederic
Added TextBox submit event
r14391 def on_submit(self, callback, remove=False):
Jonathan Frederic
More PEP8 changes
r14607 """(Un)Register a callback to handle text submission.
Triggered when the user clicks enter.
Jonathan Frederic
Added TextBox submit event
r14391
Parameters
callback: Method handle
Function to be called when the text has been submitted. Function
can have two possible signatures:
callback()
callback(sender)
remove: bool (optional)
Whether or not to unregister the callback"""
Jonathan Frederic
Added new CallbackDispatcher class
r14658 self._submission_callbacks.register_callback(callback, remove=remove)