Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Htmlnotebook #705

Merged
merged 232 commits into from
Aug 23, 2011
Merged
Show file tree
Hide file tree
Changes from 179 commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
1bc3aac
Fixing code to assume msg_type and msg_id are top-level.
ellisonbg Jul 14, 2011
efa1f33
Renaming unpack_message to unserialize and updating docstrings.
ellisonbg Jul 14, 2011
d86d45f
Fixing docstrings and a few more places for msg_id/msg_type.
ellisonbg Jul 14, 2011
a09b42a
Adding tests for zmq.session.
ellisonbg Jul 14, 2011
b95a185
More tests for Session.send/recv.
ellisonbg Jul 14, 2011
fa7cc46
Fixing messaging docs to reflect msg_type in header.
ellisonbg Jul 14, 2011
e5d9e2c
Adding temp refs to msg_type to prevent nested dict gets.
ellisonbg Jul 14, 2011
e4a965d
Fixing bug in ipkernel.py related to msg_type refactoring.
ellisonbg Jul 14, 2011
f0d2271
Fixing another bug in msg_type refactoring.
ellisonbg Jul 14, 2011
0494d13
Adding html notebook subpackage.
ellisonbg Mar 14, 2011
adcfbf8
Initial draft of HTML5/JS/CSS3 notebook.
ellisonbg Mar 18, 2011
9e95afe
Adding shift-enter support.
ellisonbg Mar 18, 2011
04da04e
Fixing selection and focus logic.
ellisonbg Mar 19, 2011
927f44b
Added placeholder text for TextCell.
ellisonbg Mar 19, 2011
d7f2add
Adding preventDefault to shift-up/down events.
ellisonbg Mar 20, 2011
398f176
Work on the server side of the html notebook.
ellisonbg Mar 23, 2011
b7248bf
Basic server for htmlnotebook working.
ellisonbg Mar 23, 2011
0bfc754
Initial reply handling implemented along with css fixes.
ellisonbg Mar 24, 2011
5a8489e
Make the main notebook div auto scroll.
ellisonbg Mar 24, 2011
5dc428b
Server side of file based notebook store implemented.
ellisonbg Mar 25, 2011
a2dd039
Initial template for notebook browser.
ellisonbg Mar 25, 2011
74b8ea8
Added message to help users open notebook.
ellisonbg Mar 31, 2011
1497e96
Updating jquery UI and themes.
ellisonbg Apr 2, 2011
339135b
Fixing main toolbar area and cleaning up jquery themes.
ellisonbg Apr 2, 2011
2ad3ee4
Different clients now share a single zmq session.
ellisonbg Apr 26, 2011
df52f21
Minor changes to notebook css.
ellisonbg Apr 26, 2011
7731a50
Interrupt and restart work for kernels.
ellisonbg Apr 26, 2011
9fe1c2c
Cleaned up kernel action interface.
ellisonbg Apr 27, 2011
1f5c4be
Status monitoring added to notebook.
ellisonbg Apr 27, 2011
2050714
Fixes to notebook scrolling and layout.
ellisonbg Apr 29, 2011
169110d
Tweaking and cleanup of notebook.css.
ellisonbg Apr 29, 2011
3b1715e
Further font adjustments to the notebook.
ellisonbg Apr 29, 2011
5d9b6e7
Work on the notebook's code cell.
ellisonbg Apr 29, 2011
2607443
Basic notebook saving and loading.
ellisonbg May 1, 2011
68db752
Initial latex printing for sympy and fixes to autogrow.
ellisonbg May 3, 2011
9e126bc
Refactoring of the output and display system.
ellisonbg May 3, 2011
6c644c6
Fixes to the latex rendering by adjusting the MathJax config.
ellisonbg May 3, 2011
bffb119
Basic exception display in the notebook is working.
ellisonbg May 3, 2011
9447eb0
Added basic styling to text cells.
ellisonbg May 3, 2011
a563b92
Cells call grow by hand when they reload from JSON.
ellisonbg May 3, 2011
e6b3e5b
include html frontend in packages/package_data
minrk May 3, 2011
e341cf4
Shift-Enter only selects the next cell if it is a CodeCell.
ellisonbg May 3, 2011
e513eb9
Fine tuning of notebook styles.
ellisonbg May 3, 2011
5e55e20
Adding logic to look for CDN version of MathJax and fallback to local.
ellisonbg May 3, 2011
ff6dc82
Added note about tornado version to main script.
ellisonbg May 4, 2011
5d05db0
Minor fix to sympy latex printing.
ellisonbg May 4, 2011
7877585
Adding new notebook examples.
ellisonbg May 4, 2011
1ff5a82
Minor changes to text_analysis notebook example.
ellisonbg May 4, 2011
264b061
Updating notebook examples, and notebook js/html.
ellisonbg May 13, 2011
e3dc236
General CSS cleanup.
ellisonbg May 13, 2011
f5911d3
CodeMirror code editing added.
ellisonbg May 14, 2011
e270403
Better handling of up/down arrows for CodeCells.
ellisonbg May 16, 2011
c14e651
Much improved nagivation for the notebook cells.
ellisonbg May 16, 2011
c9ad4e8
Updating notebook examples.
ellisonbg May 18, 2011
b2aa21f
Updating sympy notebook examples.
ellisonbg May 19, 2011
0f16a10
Updating examples notebooks.
ellisonbg May 20, 2011
b55bc76
Adding new density of states notebook example.
ellisonbg Jun 6, 2011
98f7851
Creating files to new notebook app.
ellisonbg Jul 1, 2011
a94f1fa
Fixing import statments in handlers and notebookapp.
ellisonbg Jul 1, 2011
02f9051
Initial reorg of files complete.
ellisonbg Jul 1, 2011
8deb465
Renaming NotebookApplication to NotebookWebApplication.
ellisonbg Jul 1, 2011
3f3cd92
Refactored htmlnotebook session and kernel manager.
ellisonbg Jul 12, 2011
9ce4875
Refactoring the notebook app to support the new config system.
ellisonbg Jul 12, 2011
e051436
Notebook app debugging.
ellisonbg Jul 12, 2011
f0ab259
Work to adapt routers to new Session message protocol.
ellisonbg Jul 13, 2011
fd1d84c
More work on updating the notebook zmq forwarding.
ellisonbg Jul 13, 2011
97f1ce7
Updating the notebook to work with the latex master.
ellisonbg Jul 14, 2011
82dfeed
Splitting notebook.js into muliple files for development ease.
ellisonbg Jul 14, 2011
90a9bbc
Updating main notebook template to use split scripts.
ellisonbg Jul 14, 2011
27afdf3
Change unpack_message to unserialize in routers.py.
ellisonbg Jul 14, 2011
c5b0c06
Implemented module and namespace pattern in js notebook.
ellisonbg Jul 15, 2011
73126bf
Using $.proxy to clean up callbacks.
ellisonbg Jul 15, 2011
7fc2c96
Actually kill old kernels upon restart.
ellisonbg Jul 15, 2011
ad2890a
Starting to refactor the notebook layout
ellisonbg Jul 15, 2011
af64139
Initial payload handling.
ellisonbg Jul 15, 2011
aa37ef2
Refactoring pager into its own class.
ellisonbg Jul 15, 2011
8766e94
Updating jQuery to 1.6.2 and jQuery UI to 1.8.14.
ellisonbg Jul 17, 2011
ed4b3fd
Adding note about vbox related scroll bugs.
ellisonbg Jul 18, 2011
a0257f5
More work updating the notebook to use dynamics resizing.
ellisonbg Jul 18, 2011
9262f15
Pager is working again.
ellisonbg Jul 19, 2011
e37fefa
More accuract height calculations for the pager collapse/expand.
ellisonbg Jul 19, 2011
450ed2f
Left panel is now working.
ellisonbg Jul 19, 2011
1579023
Improving the scrolling model.
ellisonbg Jul 19, 2011
c6ab30b
Initial draft of panel section and the cell section working.
ellisonbg Jul 20, 2011
a7ef503
Minor fixes to fonts and spacing.
ellisonbg Jul 20, 2011
71e8168
Controls in cell section have a solid layout.
ellisonbg Jul 20, 2011
0376908
Help section implemented and working.
ellisonbg Jul 20, 2011
e4683b7
Minors fixes and initial work on save widget.
ellisonbg Jul 21, 2011
67aa594
Work on save widget, kernel status widget and notebook section.
ellisonbg Jul 22, 2011
f1b3d4a
Fixing execution related things.
ellisonbg Jul 22, 2011
0c51946
Updating font-sizing to use the YUI protocol.
ellisonbg Jul 23, 2011
d8294f0
Prevent shift-enter from propagating and performing default.
ellisonbg Jul 23, 2011
00dc27f
Colors now working in tracebacks and the pager.
ellisonbg Jul 23, 2011
5829983
Added complete method of JS kernel object.
ellisonbg Jul 26, 2011
dad53c3
Autocompletion working with CTRL-SPACE.
ellisonbg Jul 26, 2011
6a242ba
CTRL-ENTER now runs a cell in "terminal mode"
ellisonbg Jul 27, 2011
b1f1dde
Removing default input prompt number.
ellisonbg Jul 27, 2011
68687d2
Adding nbformat subpackage.
ellisonbg Jul 27, 2011
4b71ab3
Notebook now uses tab for autocompletion.
ellisonbg Jul 27, 2011
c88117a
Fixes to terminal mode execution (ctrl-enter).
ellisonbg Jul 27, 2011
fbddd43
Hacks to prevent FLOUC (flash of unformatted content).
ellisonbg Jul 27, 2011
27379eb
Fixing minor resize bug on the Mac.
ellisonbg Jul 27, 2011
8012152
Adding Cell.grow back to fix bug.
ellisonbg Jul 28, 2011
f3a5072
Initial draft of more formal notebook format.
ellisonbg Jul 28, 2011
4b0e672
Updates to basic notebook format.
ellisonbg Jul 29, 2011
1cc83a7
support html representations in the notebook frontend
minrk Jul 29, 2011
0251893
Full versioning added to nbformat.
ellisonbg Jul 29, 2011
a65c2d3
Merge branch 'repr_html' of https://github.com/minrk/ipython into min…
ellisonbg Jul 29, 2011
c292a9c
Added lib/display.py for extra display related things.
ellisonbg Jul 29, 2011
4c2aebb
update add_packages for reorganized nbformat
minrk Jul 30, 2011
540b3f1
Fixing setupbase.py for nbformat package.
ellisonbg Aug 1, 2011
65666c0
Massive work on the notebook document format.
ellisonbg Aug 4, 2011
d77eb2c
Merge branch 'htmlnotebook' of github.com:ipython/ipython into htmlno…
ellisonbg Aug 4, 2011
1699c90
Implemented basic notebook browser and fixed numerous bugs.
ellisonbg Aug 5, 2011
b0243db
Implemented delete functionality in nb browser.
ellisonbg Aug 5, 2011
53c7ec7
File upload/import working from notebook browser.
ellisonbg Aug 6, 2011
8f4eb62
Improvements to file uploaded, mime types and .py reader.
ellisonbg Aug 7, 2011
03eb23c
Adding kernel/notebook associations.
ellisonbg Aug 7, 2011
708c73e
Fixed subtle bug in kernel restarting.
ellisonbg Aug 7, 2011
7640e54
Using beforeunload to save at exit and kill the kernel.
ellisonbg Aug 7, 2011
2a85499
Added saving and loading of output of all types.
ellisonbg Aug 8, 2011
b0e516c
Starting to rename text cell to html cell.
ellisonbg Aug 8, 2011
653f157
New HTMl cell working with CodeMirror editing.
ellisonbg Aug 8, 2011
981bc0c
Updating CodeMirror to v 2.12.
ellisonbg Aug 8, 2011
3896ff1
Fixing HTML cell syntax highlighting.
ellisonbg Aug 8, 2011
f5f6198
Starting work on a Markdown cell.
ellisonbg Aug 9, 2011
fbce942
Refactoring of text/markdown/rst/html cells.
ellisonbg Aug 9, 2011
978f742
Reordering Export button and renaming Export->Export As
ellisonbg Aug 9, 2011
a85c3e7
Markdown cells are now saved and restored in notebooks.
ellisonbg Aug 9, 2011
4fb6f61
Implemented smart autoindenting.
ellisonbg Aug 9, 2011
8bee5f8
Fixed text cell rendering bug.
ellisonbg Aug 9, 2011
db81ec2
Updates to the css style of rendered html text cells.
ellisonbg Aug 9, 2011
89e253a
Minor fixes to config system for notebook.
ellisonbg Aug 9, 2011
ddb901b
Adding minor help strings for keyboard shortcuts.
ellisonbg Aug 10, 2011
fd892df
Merge branch 'master' into htmlnotebook
ellisonbg Aug 10, 2011
53df0ac
Updating notebook configuration.
ellisonbg Aug 10, 2011
46fc646
Created new notebook magic that can export/convert notebooks.
ellisonbg Aug 10, 2011
1bcb722
Adding initial documentation on the notebook.
ellisonbg Aug 11, 2011
b633a93
Reducing/adjusting the padding of cells to make the notebook more
ellisonbg Aug 11, 2011
b84d895
Updates to the display system.
ellisonbg Aug 11, 2011
08ef328
Finishing display system work.
ellisonbg Aug 11, 2011
eaf692f
Autoindentation fixed and enabled by default.
ellisonbg Aug 11, 2011
1de26e1
%loadpy works in the notebook and bug with inline plotting fixed.
ellisonbg Aug 11, 2011
b85982d
Fixing padding of output cells.
ellisonbg Aug 11, 2011
1d01468
Added note about imports in IPython.__init__.
ellisonbg Aug 11, 2011
1c4a699
Added collapsed field to the code cell.
ellisonbg Aug 11, 2011
31ac0f3
HTML/Markdown cells no longer saved their rendered output.
ellisonbg Aug 11, 2011
40d4a55
Adding time delay to show the notebook saving more clearly.
ellisonbg Aug 11, 2011
7debcc4
New .py notebook format implemented.
ellisonbg Aug 12, 2011
3669962
Adding tracebacks, evalue and etype to the nbformat and notebook.
ellisonbg Aug 13, 2011
df0ed78
HTML output cells are now styled with the rendered_html class.
ellisonbg Aug 13, 2011
453bf75
Disabling auto-save at exit.
ellisonbg Aug 13, 2011
31e9da5
Clear all output is implemented.
ellisonbg Aug 13, 2011
5bad195
Major refactor of kernel connection management in the notebook.
ellisonbg Aug 15, 2011
cc6010e
Merge branch 'master' into htmlnotebook
ellisonbg Aug 15, 2011
f5c5121
Fixing bug that caused plots to not be saved.
ellisonbg Aug 15, 2011
d1499b6
Autotry additional ports if 8888 if already in use.
ellisonbg Aug 15, 2011
1786348
Browser window title follows the name of the notebook.
ellisonbg Aug 15, 2011
fb55a88
Added a notebook dirty flag that is used when exiting page.
ellisonbg Aug 15, 2011
a86896d
Notebook id removed from the notebook format.
ellisonbg Aug 15, 2011
bee9c06
Updating notebook examples to current format.
ellisonbg Aug 15, 2011
feaba3c
Fixing latex rendering bug.
ellisonbg Aug 15, 2011
49fa32f
A single tab-completion match is now automatically selected.
ellisonbg Aug 15, 2011
2d7e32b
Fixing tab completion edge cases.
ellisonbg Aug 15, 2011
95590c1
Adding additional whitespace at botton of notebook for TAB comp.
ellisonbg Aug 15, 2011
54eeb77
Code cell gets focused after "To Code" is triggered.
ellisonbg Aug 15, 2011
09a90c4
Export works with filenames having spaces.
ellisonbg Aug 15, 2011
50206b2
I like ClearAll better than Clr All.
ellisonbg Aug 15, 2011
baf6e69
Pager is not activated if the pager text is empty.
ellisonbg Aug 15, 2011
b796f24
Date is properly removed from JSON reply before WebSocket forward.
ellisonbg Aug 15, 2011
a1dcaf6
Kernel/notebook mapping is removed when a kernel dies.
ellisonbg Aug 15, 2011
856b17f
WebSocket url is now passed to browser when a kernel is started.
ellisonbg Aug 16, 2011
56475d6
Removing old CodeMirror version.
ellisonbg Aug 16, 2011
bedc0f7
Fixing two minor things for review.
ellisonbg Aug 16, 2011
f6078d0
Stripping notebook server flags from kernel's argv.
ellisonbg Aug 16, 2011
3ec3b24
Reworking parallel examples as notebooks.
ellisonbg Aug 16, 2011
a968795
Renaming and moving around parallel examples.
ellisonbg Aug 16, 2011
2eae784
More file renaming in parallel examples.
ellisonbg Aug 16, 2011
18ad520
Updating RMT parallel example.
ellisonbg Aug 16, 2011
567f1c3
Implement static publishing of HTML notebook.
stefanv Aug 17, 2011
1e86624
htmlnotebook: Suppress cell boundary when publishing.
stefanv Aug 17, 2011
2c580e7
Don't scroll to bottom when last cell is selected.
ellisonbg Aug 17, 2011
a661b7c
More review changes.
ellisonbg Aug 17, 2011
2e45b3a
Finish removing ipython-notebook.
ellisonbg Aug 17, 2011
bf61e42
Adding code to handle MozWebSocket for FF 6.
ellisonbg Aug 17, 2011
719e65a
Better WebSocket detection added.
ellisonbg Aug 17, 2011
486e84f
Better alert message if no WebSockets are detected.
ellisonbg Aug 17, 2011
eb895bf
Removed HTMLCell from UI and added better placeholder logic.
ellisonbg Aug 17, 2011
968e3fe
Refactor static printing.
stefanv Aug 18, 2011
7421012
Modifying CodeMirror focus hack to work better.
ellisonbg Aug 18, 2011
7777bdd
Fixing parallel options pricing example.
ellisonbg Aug 18, 2011
d5b4ff0
Merge branch 'htmlnotebook_publish' of https://github.com/stefanv/ipy…
ellisonbg Aug 18, 2011
f4c8372
Changing notebook uuid algorithm to preserver across sessions.
ellisonbg Aug 19, 2011
a2b246f
Allow period characters in notebook names.
stefanv Aug 19, 2011
0e2ee7f
Move glob to global level import.
stefanv Aug 19, 2011
898a609
Adding page break logic to the print css.
ellisonbg Aug 19, 2011
d33fac5
Merge branch 'stefanv-htmlnotebook_publish' into htmlnotebook
ellisonbg Aug 19, 2011
a82fa5d
Merge branch 'htmlnotebook_list_notebooks' of https://github.com/stef…
ellisonbg Aug 19, 2011
cb5364f
Double clicking on the end space will insert a new cell.
ellisonbg Aug 19, 2011
bdb89a7
Better tabindex support.
ellisonbg Aug 19, 2011
507621d
Save button becomes Rename when the notebook name changes.
ellisonbg Aug 19, 2011
1e2b197
Help links work on Firefox.
ellisonbg Aug 19, 2011
6d3001f
Fixing logic for rename behavior.
ellisonbg Aug 19, 2011
cc19c96
Making JSON the default .ipynb format.
ellisonbg Aug 19, 2011
1cfbe5d
Converting notebooks to JSON format.
ellisonbg Aug 19, 2011
33e3025
Notebook upload handles filenames with periods.
ellisonbg Aug 19, 2011
d919e2e
Implemented metadata for notebook format.
ellisonbg Aug 19, 2011
68889f9
Changing CodeMirror-scroll to overflow-y: hidden.
ellisonbg Aug 19, 2011
8013d52
Cell collapse/expand is not called "Toggle".
ellisonbg Aug 19, 2011
b1af148
Reorganize the L panel buttons.
ellisonbg Aug 19, 2011
bc7865e
Fixing bug in new metadata implementation.
ellisonbg Aug 19, 2011
9748902
All output types are not indented.
ellisonbg Aug 20, 2011
54111d3
Adjusting width of prompt area.
ellisonbg Aug 20, 2011
b5134ae
Right-align prompts to remove spurious whitespace.
fperez Aug 20, 2011
d11e8eb
Adding keyboard shortcuts.
ellisonbg Aug 20, 2011
7e2eee1
Adding keyboard shortcut help dialog.
ellisonbg Aug 20, 2011
4a3930a
Fixing console.log messages related to keyboard shortcuts.
ellisonbg Aug 20, 2011
14ae374
Changing prev/next keyboard shortcut to use p/n.
ellisonbg Aug 20, 2011
5dc0439
Fixing XML notebook reader.
ellisonbg Aug 20, 2011
c5f13bc
Align colons in help dialog.
stefanv Aug 20, 2011
4408742
Merge pull request #713 from stefanv/htmlnotebook_help_dialog
ellisonbg Aug 20, 2011
ff2b547
Add utility function for installing mathjax for offline use
minrk Aug 20, 2011
89aca0b
update notebook template to prefer offline mathjax
minrk Aug 20, 2011
d6a97e9
Add code highlighting to markdown cells.
stefanv Aug 21, 2011
e591917
Add prettify license.
stefanv Aug 21, 2011
88fabb9
Try to match CodeMirror theme.
stefanv Aug 21, 2011
9460984
Merge pull request #717 from stefanv/htmlnotebook_highlight_markdown
fperez Aug 21, 2011
9600e07
Fix above/below keybinding mismatch and rename api to use above/below
fperez Aug 22, 2011
de11baf
underline keyboard shortcut letter on buttons
minrk Aug 22, 2011
2213211
Merge branch 'mathjax' of https://github.com/minrk/ipython into minrk…
ellisonbg Aug 22, 2011
0bfb0fb
Adding information about MathJax to notebook install docs.
ellisonbg Aug 22, 2011
876e689
Temporary fix for placeholder related CM bug.
ellisonbg Aug 23, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions IPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
from .config.loader import Config
from .core import release
from .core.application import Application
# Todo: Should these be imported here? We need to rethink what is imported in
# this module.
#from .core.display import (
# display, display_pretty, display_html, display_latex,
# display_png, display_jpeg, display_svg, display_json,
# display_javascript, HTML, SVG, Math, Image, JSON,
# Javascript, Pretty
#)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that instead, we have a top-level 'display' module that simply imports the things we want to expose (possibly including core and lib).

In general, I think we should follow a pattern where things meant for public use should be at most one module deep:

from IPython.foo import bar, baz

even if these top-level modules are mostly just pass-throughs that load from deeper parts of the hierarchy. But these will be the ones we consider public, and things deeper in are more subject to change. That way we only have to explain to people in normal docs and instructions these top-level namespaces, leaving the rest as 'an implementation detail'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you think all of the user facing stuff (not just the display stuff) should go into a single module? Right now there is IPython.embed and we will definitely have more and more user facing code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we just remove these for now from the merge, since the organization of the public api is really a separate issue from the notebook code, and we make sure that in the next month or two when the dust on the notebook settles, we set up a time to discuss the public api with a clear head. I don't think there's major hurry in getting that right, so as long as we do it before too long (say a few months, in the 0.12-0.13 timeframe), we'll be OK. And we can calmly review all the pieces we want exposed, and think about the cleanest way to do so...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

from .frontend.terminal.embed import embed
from .core.error import TryNext
from .core.interactiveshell import InteractiveShell
Expand Down
287 changes: 265 additions & 22 deletions IPython/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
# Imports
#-----------------------------------------------------------------------------

from .displaypub import (
publish_pretty, publish_html,
publish_latex, publish_svg,
publish_png, publish_json,
publish_javascript, publish_jpeg
)

#-----------------------------------------------------------------------------
# Main functions
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -53,78 +60,314 @@ def display(*objs, **kwargs):
publish('IPython.core.display.display', format_dict)


def display_pretty(*objs):
def display_pretty(*objs, **kwargs):
"""Display the pretty (default) representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
The Python objects to display, or if raw=True raw text data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
display(*objs, include=['text/plain'])
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_pretty(obj)
else:
display(*objs, include=['text/plain'])


def display_html(*objs):
def display_html(*objs, **kwargs):
"""Display the HTML representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
"""
display(*objs, include=['text/plain','text/html'])
The Python objects to display, or if raw=True raw HTML data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_html(obj)
else:
display(*objs, include=['text/plain','text/html'])


def display_svg(*objs):
def display_svg(*objs, **kwargs):
"""Display the SVG representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
The Python objects to display, or if raw=True raw svg data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
display(*objs, include=['text/plain','image/svg+xml'])
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_svg(obj)
else:
display(*objs, include=['text/plain','image/svg+xml'])


def display_png(*objs):
def display_png(*objs, **kwargs):
"""Display the PNG representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
The Python objects to display, or if raw=True raw png data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
display(*objs, include=['text/plain','image/png'])
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_png(obj)
else:
display(*objs, include=['text/plain','image/png'])


def display_jpeg(*objs, **kwargs):
"""Display the JPEG representation of an object.

def display_latex(*objs):
Parameters
----------
objs : tuple of objects
The Python objects to display, or if raw=True raw JPEG data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_jpeg(obj)
else:
display(*objs, include=['text/plain','image/jpeg'])


def display_latex(*objs, **kwargs):
"""Display the LaTeX representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
The Python objects to display, or if raw=True raw latex data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
display(*objs, include=['text/plain','text/latex'])
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_latex(obj)
else:
display(*objs, include=['text/plain','text/latex'])


def display_json(*objs):
def display_json(*objs, **kwargs):
"""Display the JSON representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
The Python objects to display, or if raw=True raw json data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
display(*objs, include=['text/plain','application/json'])
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_json(obj)
else:
display(*objs, include=['text/plain','application/json'])


def display_javascript(*objs):
def display_javascript(*objs, **kwargs):
"""Display the Javascript representation of an object.

Parameters
----------
objs : tuple of objects
The Python objects to display.
The Python objects to display, or if raw=True raw javascript data to
display.
raw : bool
Are the data objects raw data or Python objects that need to be
formatted before display? [default: False]
"""
display(*objs, include=['text/plain','application/javascript'])
raw = kwargs.pop('raw',False)
if raw:
for obj in objs:
publish_javascript(obj)
else:
display(*objs, include=['text/plain','application/javascript'])

#-----------------------------------------------------------------------------
# Smart classes
#-----------------------------------------------------------------------------


class DisplayObject(object):
"""An object that wraps data to be displayed."""

_read_flags = 'r'

def __init__(self, data=None, url=None, filename=None):
"""Create a display object given raw data.

When this object is returned by an expression or passed to the
display function, it will result in the data being displayed
in the frontend. The MIME type of the data should match the
subclasses used, so the Png subclass should be used for 'image/png'
data. If the data is a URL, the data will first be downloaded
and then displayed. If

Parameters
----------
data : unicode, str or bytes
The raw data or a URL to download the data from.
url : unicode
A URL to download the data from.
filename : unicode
Path to a local file to load the data from.
"""
if data is not None and data.startswith('http'):
self.url = data
self.filename = None
self.data = None
else:
self.data = data
self.url = url
self.filename = None if filename is None else unicode(filename)
self.reload()

def reload(self):
"""Reload the raw data from file or URL."""
if self.filename is not None:
with open(self.filename, self._read_flags) as f:
self.data = f.read()
elif self.url is not None:
try:
import urllib2
response = urllib2.urlopen(self.url)
self.data = response.read()
except:
self.data = None

class Pretty(DisplayObject):

def _repr_pretty_(self):
return self.data


class HTML(DisplayObject):

def _repr_html_(self):
return self.data


class Math(DisplayObject):

def _repr_latex_(self):
return self.data


class SVG(DisplayObject):

def _repr_svg_(self):
return self.data


class JSON(DisplayObject):

def _repr_json_(self):
return self.data


class Javascript(DisplayObject):

def _repr_javascript_(self):
return self.data


class Image(DisplayObject):

_read_flags = 'rb'

def __init__(self, data=None, url=None, filename=None, format=u'png', embed=False):
"""Create a display an PNG/JPEG image given raw data.

When this object is returned by an expression or passed to the
display function, it will result in the image being displayed
in the frontend.

Parameters
----------
data : unicode, str or bytes
The raw data or a URL to download the data from.
url : unicode
A URL to download the data from.
filename : unicode
Path to a local file to load the data from.
format : unicode
The format of the image data (png/jpeg/jpg). If a filename or URL is given
for format will be inferred from the filename extension.
embed : bool
Should the image data be embedded in the notebook using a data URI (True)
or be loaded using an <img> tag. Set this to True if you want the image
to be viewable later with no internet connection. If a filename is given
embed is always set to True.
"""
if filename is not None:
ext = self._find_ext(filename)
elif url is not None:
ext = self._find_ext(url)
elif data.startswith('http'):
ext = self._find_ext(data)
else:
ext = None
if ext is not None:
if ext == u'jpg' or ext == u'jpeg':
format = u'jpeg'
if ext == u'png':
format = u'png'
self.format = unicode(format).lower()
self.embed = True if filename is not None else embed
super(Image, self).__init__(data=data, url=url, filename=filename)

def reload(self):
"""Reload the raw data from file or URL."""
if self.embed:
super(Image,self).reload()

def _repr_html_(self):
if not self.embed:
return u'<img src="%s" />' % self.url

def _repr_png_(self):
if self.embed and self.format == u'png':
return self.data

def _repr_jpeg_(self):
if self.embed and (self.format == u'jpeg' or self.format == u'jpg'):
return self.data

def _find_ext(self, s):
return unicode(s.split('.')[-1].lower())
Loading