From 32716dc495f035c2c9d8308e23dffe18b3126430 2014-01-16 14:20:04 From: Jonathan Frederic Date: 2014-01-16 14:20:04 Subject: [PATCH] More PEP8 changes --- diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 9f389ca..90f0f73 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -31,8 +31,9 @@ class Widget(LoggingConfigurable): widgets = {} def on_widget_constructed(callback): - """Class method, registers a callback to be called when a widget is - constructed. The callback must have the following signature: + """Registers a callback to be called when a widget is constructed. + + The callback must have the following signature: callback(widget)""" Widget.widget_construction_callback = callback @@ -41,8 +42,6 @@ class Widget(LoggingConfigurable): if Widget.widget_construction_callback is not None and callable(Widget.widget_construction_callback): Widget.widget_construction_callback(widget) - - # Public declarations (Instance level) model_name = Unicode('WidgetModel', help="""Name of the backbone model registered in the front-end to create and sync this widget with.""") @@ -80,8 +79,7 @@ class Widget(LoggingConfigurable): _comm = Instance('IPython.kernel.comm.Comm') def __init__(self, **kwargs): - """Public constructor - """ + """Public constructor""" self.closed = False self._property_lock = (None, None) self._display_callbacks = [] @@ -97,21 +95,21 @@ class Widget(LoggingConfigurable): self.close() def close(self): - """Close method. Closes the widget which closes the underlying comm. + """Close method. + + Closes the widget which closes the underlying comm. When the comm is closed, all of the widget views are automatically removed from the front-end.""" if not self.closed: self._comm.close() self._close() - def _close(self): """Unsafe close""" del Widget.widgets[self.model_id] self._comm = None self.closed = True - @property def comm(self): if self._comm is None: @@ -147,7 +145,6 @@ class Widget(LoggingConfigurable): if 'custom_content' in data: self._handle_custom_msg(data['custom_content']) - def _handle_receive_state(self, sync_data): """Called when a state is received from the front-end.""" for name in self.keys: @@ -156,13 +153,11 @@ class Widget(LoggingConfigurable): with self.property_lock(name, value): setattr(self, name, value) - def _handle_custom_msg(self, content): """Called when a custom msg is received.""" for handler in self._msg_callbacks: handler(self, content) - def _handle_property_changed(self, name, old, new): """Called when a property has been changed.""" # Make sure this isn't information that the front-end just sent us. @@ -198,10 +193,8 @@ class Widget(LoggingConfigurable): keys = self.keys if key is None else [key] return {k: self._pack_widgets(getattr(self, k)) for k in keys} - def _pack_widgets(self, values): - """This function recursively converts all widget instances to model id - strings. + """Recursively converts all widget instances to model id strings. Children widgets will be stored and transmitted to the front-end by their model ids.""" @@ -220,10 +213,8 @@ class Widget(LoggingConfigurable): else: return values - def _unpack_widgets(self, values): - """This function recursively converts all model id strings to widget - instances. + """Recursively converts all model id strings to widget instances. Children widgets will be stored and transmitted to the front-end by their model ids.""" @@ -245,7 +236,6 @@ class Widget(LoggingConfigurable): else: return values - def send(self, content): """Sends a custom msg to the widget model in the front-end. @@ -256,10 +246,8 @@ class Widget(LoggingConfigurable): """ self._send({"method": "custom", "custom_content": content}) - def on_msg(self, callback, remove=False): - """Register or unregister a callback for when a custom msg is recieved - from the front-end. + """(Un)Register a custom msg recieve callback. Parameters ---------- @@ -291,10 +279,8 @@ class Widget(LoggingConfigurable): else: raise Exception('Callback must be callable.') - def on_displayed(self, callback, remove=False): - """Register or unregister a callback to be called when the widget has - been displayed. + """(Un)Register a widget displayed callback. Parameters ---------- @@ -312,20 +298,16 @@ class Widget(LoggingConfigurable): else: raise Exception('Callback must be callable.') - # Support methods def _ipython_display_(self, **kwargs): - """Function that is called when `IPython.display.display` is called on - the widget.""" - + """Called when `IPython.display.display` is called on the widget.""" # Show view. By sending a display message, the comm is opened and the # initial state is sent. self._send({"method": "display"}) self._handle_displayed(**kwargs) - def _send(self, msg): - """Sends a message to the model in the front-end""" + """Sends a message to the model in the front-end.""" self.comm.send(msg) @@ -408,9 +390,8 @@ class DOMWidget(Widget): else: raise Exception('set_css only accepts 1-3 arguments') - def add_class(self, class_names, selector=""): - """Add class[es] to a DOM element + """Add class[es] to a DOM element. Parameters ---------- @@ -428,9 +409,8 @@ class DOMWidget(Widget): "class_list": class_list, "selector": selector}) - def remove_class(self, class_names, selector=""): - """Remove class[es] from a DOM element + """Remove class[es] from a DOM element. Parameters ---------- diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index 0ad088a..f558189 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -27,6 +27,7 @@ class CheckBoxWidget(DOMWidget): description = Unicode('', help="Description of the boolean (label).", sync=True) disabled = Bool(False, help="Enable or disable user changes.", sync=True) + class ToggleButtonWidget(CheckBoxWidget): view_name = Unicode('ToggleButtonView', sync=True) \ No newline at end of file diff --git a/IPython/html/widgets/widget_button.py b/IPython/html/widgets/widget_button.py index 793ae6f..326b367 100644 --- a/IPython/html/widgets/widget_button.py +++ b/IPython/html/widgets/widget_button.py @@ -30,17 +30,17 @@ class ButtonWidget(DOMWidget): description = Unicode('', help="Description of the button (label).", sync=True) disabled = Bool(False, help="Enable or disable user changes.", sync=True) - def __init__(self, **kwargs): + """Constructor""" super(ButtonWidget, self).__init__(**kwargs) self._click_handlers = [] self.on_msg(self._handle_button_msg) - def on_click(self, callback, remove=False): - """Register a callback to execute when the button is clicked. The - callback can either accept no parameters or one sender parameter: + """Register a callback to execute when the button is clicked. + + The callback can either accept no parameters or one sender parameter: - callback() - callback(sender) If the callback has a sender parameter, the ButtonWidget instance that @@ -55,9 +55,8 @@ class ButtonWidget(DOMWidget): elif not callback in self._click_handlers: self._click_handlers.append(callback) - def _handle_button_msg(self, content): - """Handle a msg from the front-end + """Handle a msg from the front-end. Parameters ---------- @@ -66,11 +65,10 @@ class ButtonWidget(DOMWidget): if 'event' in content and content['event'] == 'click': self._handle_click() - def _handle_click(self): - """Handles when the button has been clicked. Fires on_click - callbacks when appropriate.""" - + """Handles when the button has been clicked. + + Fires on_click callbacks when appropriate.""" for handler in self._click_handlers: if callable(handler): argspec = inspect.getargspec(handler) @@ -88,4 +86,3 @@ class ButtonWidget(DOMWidget): else: raise TypeError('ButtonWidget click callback must ' \ 'accept 0 or 1 arguments.') - diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index b1aa4ae..54211a9 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -29,5 +29,6 @@ class ContainerWidget(DOMWidget): description = Unicode(sync=True) button_text = Unicode(sync=True) + class ModalWidget(ContainerWidget): view_name = Unicode('ModalView', sync=True) diff --git a/IPython/html/widgets/widget_float_range.py b/IPython/html/widgets/widget_float_range.py index 6d5aeb4..e49aed9 100644 --- a/IPython/html/widgets/widget_float_range.py +++ b/IPython/html/widgets/widget_float_range.py @@ -34,7 +34,7 @@ class BoundedFloatTextWidget(DOMWidget): self.on_trait_change(self._validate, ['value', 'min', 'max']) def _validate(self, name, old, new): - """Validate value, max, min""" + """Validate value, max, min.""" if self.min > new or new > self.max: self.value = min(max(new, self.min), self.max) diff --git a/IPython/html/widgets/widget_int_range.py b/IPython/html/widgets/widget_int_range.py index 7f3afa1..f9d5cd5 100644 --- a/IPython/html/widgets/widget_int_range.py +++ b/IPython/html/widgets/widget_int_range.py @@ -36,7 +36,7 @@ class BoundedIntTextWidget(DOMWidget): self.on_trait_change(self._validate, ['value', 'min', 'max']) def _validate(self, name, old, new): - """Validate value, max, min""" + """Validate value, max, min.""" if self.min > new or new > self.max: self.value = min(max(new, self.min), self.max) diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index 77416db..c5c97d0 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -31,7 +31,7 @@ class AccordionWidget(DOMWidget): # Public methods def set_title(self, index, title): - """Sets the title of a container page + """Sets the title of a container page. Parameters ---------- @@ -42,9 +42,8 @@ class AccordionWidget(DOMWidget): self._titles[index] = title self.send_state('_titles') - def get_title(self, index): - """Gets the title of a container pages + """Gets the title of a container pages. Parameters ---------- diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index cb1d377..ad53683 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -51,7 +51,7 @@ class TextBoxWidget(HTMLWidget): self.on_msg(self._handle_string_msg) def _handle_string_msg(self, content): - """Handle a msg from the front-end + """Handle a msg from the front-end. Parameters ---------- @@ -62,8 +62,9 @@ class TextBoxWidget(HTMLWidget): handler(self) def on_submit(self, callback, remove=False): - """Register a callback to handle text submission (triggered when the - user clicks enter). + """(Un)Register a callback to handle text submission. + + Triggered when the user clicks enter. Parameters callback: Method handle