##// END OF EJS Templates
refactor to improve cell switching in edit mode...
refactor to improve cell switching in edit mode This code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell. TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell prior to this, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above. The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

File last commit:

r15530:4b9f1569 merge
r15754:d60e793e
Show More
widget_container.py
62 lines | 2.3 KiB | text/x-python | PythonLexer
Jonathan Frederic
Cleaned up Python widget code.
r14283 """ContainerWidget class.
Represents a container that can be used to group other widgets.
"""
#-----------------------------------------------------------------------------
# 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
s/Widget/DOMWidget s/BaseWidget/Widget
r14540 from .widget import DOMWidget
MinRK
don't validate ContainerWidget.children...
r15480 from IPython.utils.traitlets import Unicode, Tuple, TraitError
Jonathan Frederic
Add container widget
r14239
Jonathan Frederic
Cleaned up Python widget code.
r14283 #-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
MinRK
don't check shape of ContainerWidget.children
r15475
Jonathan Frederic
s/Widget/DOMWidget s/BaseWidget/Widget
r14540 class ContainerWidget(DOMWidget):
Jonathan Frederic
s/view_name/_view_name
r14701 _view_name = Unicode('ContainerView', sync=True)
Jonathan Frederic
Attempt 1, HBox and VBox implementation.
r14268
MinRK
don't validate ContainerWidget.children...
r15480 # Child widgets in the container.
# Using a tuple here to force reassignment to update the list.
# When a proper notifying-list trait exists, that is what should be used here.
children = Tuple()
_children = Tuple(sync=True)
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608
zah
Children fire event...
r15446
def __init__(self, **kwargs):
super(ContainerWidget, self).__init__(**kwargs)
self.on_displayed(ContainerWidget._fire_children_displayed)
def _fire_children_displayed(self):
for child in self._children:
child._handle_displayed()
Jonathan Frederic
Fixed type in container...
r14715 def _children_changed(self, name, old, new):
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608 """Validate children list.
Makes sure only one instance of any given model can exist in the
Jonathan Frederic
Replace O(N^2) algorithm with a faster one.
r14699 children list.
An excellent post on uniqifiers is available at
http://www.peterbe.com/plog/uniqifiers-benchmark
which provides the inspiration for using this implementation. Below
I've implemented the `f5` algorithm using Python comprehensions."""
MinRK
remove incorrect is instance check in children_changed
r15476 if new is not None:
Jonathan Frederic
Replace O(N^2) algorithm with a faster one.
r14699 seen = {}
def add_item(i):
seen[i.model_id] = True
return i
Jonathan Frederic
Fixed type in container...
r14715 self._children = [add_item(i) for i in new if not i.model_id in seen]
Jonathan Frederic
1-to-1 widget / view mapping
r14592
Jonathan Frederic
More PEP8 changes
r14607
Jonathan Frederic
s/ModalView/PopupView
r14676 class PopupWidget(ContainerWidget):
Jonathan Frederic
s/view_name/_view_name
r14701 _view_name = Unicode('PopupView', sync=True)
Jonathan Frederic
containers and selectioncontainers now only allow one of any single child
r14608
description = Unicode(sync=True)
button_text = Unicode(sync=True)