##// END OF EJS Templates
Misc updates the display system....
Brian Granger -
Show More
@@ -449,6 +449,10 b' class HTMLFormatter(BaseFormatter):'
449 objects, define a :meth:`_repr_html_` method or use the :meth:`for_type`
449 objects, define a :meth:`_repr_html_` method or use the :meth:`for_type`
450 or :meth:`for_type_by_name` methods to register functions that handle
450 or :meth:`for_type_by_name` methods to register functions that handle
451 this.
451 this.
452
453 The return value of this formatter should be a valid HTML snippet that
454 could be injected into an existing DOM. It should *not* include the
455 ```<html>`` or ```<body>`` tags.
452 """
456 """
453 format_type = Str('text/html')
457 format_type = Str('text/html')
454
458
@@ -462,6 +466,10 b' class SVGFormatter(BaseFormatter):'
462 objects, define a :meth:`_repr_svg_` method or use the :meth:`for_type`
466 objects, define a :meth:`_repr_svg_` method or use the :meth:`for_type`
463 or :meth:`for_type_by_name` methods to register functions that handle
467 or :meth:`for_type_by_name` methods to register functions that handle
464 this.
468 this.
469
470 The return value of this formatter should be valid SVG enclosed in
471 ```<svg>``` tags, that could be injected into an existing DOM. It should
472 *not* include the ```<html>`` or ```<body>`` tags.
465 """
473 """
466 format_type = Str('image/svg+xml')
474 format_type = Str('image/svg+xml')
467
475
@@ -476,7 +484,8 b' class PNGFormatter(BaseFormatter):'
476 or :meth:`for_type_by_name` methods to register functions that handle
484 or :meth:`for_type_by_name` methods to register functions that handle
477 this.
485 this.
478
486
479 The raw data should be the base64 encoded raw png data.
487 The return value of this formatter should be raw PNG data, *not*
488 base64 encoded.
480 """
489 """
481 format_type = Str('image/png')
490 format_type = Str('image/png')
482
491
@@ -490,6 +499,9 b' class LatexFormatter(BaseFormatter):'
490 objects, define a :meth:`_repr_latex_` method or use the :meth:`for_type`
499 objects, define a :meth:`_repr_latex_` method or use the :meth:`for_type`
491 or :meth:`for_type_by_name` methods to register functions that handle
500 or :meth:`for_type_by_name` methods to register functions that handle
492 this.
501 this.
502
503 The return value of this formatter should be a valid LaTeX equation,
504 enclosed in either ```$``` or ```$$```.
493 """
505 """
494 format_type = Str('text/latex')
506 format_type = Str('text/latex')
495
507
@@ -503,6 +515,8 b' class JSONFormatter(BaseFormatter):'
503 your objects, define a :meth:`_repr_json_` method or use the :meth:`for_type`
515 your objects, define a :meth:`_repr_json_` method or use the :meth:`for_type`
504 or :meth:`for_type_by_name` methods to register functions that handle
516 or :meth:`for_type_by_name` methods to register functions that handle
505 this.
517 this.
518
519 The return value of this formatter should be a valid JSON string.
506 """
520 """
507 format_type = Str('application/json')
521 format_type = Str('application/json')
508
522
@@ -516,6 +530,9 b' class JavascriptFormatter(BaseFormatter):'
516 your objects, define a :meth:`_repr_javascript_` method or use the
530 your objects, define a :meth:`_repr_javascript_` method or use the
517 :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
531 :meth:`for_type` or :meth:`for_type_by_name` methods to register functions
518 that handle this.
532 that handle this.
533
534 The return value of this formatter should be valid Javascript code and
535 should *not* be enclosed in ```<script>``` tags.
519 """
536 """
520 format_type = Str('application/javascript')
537 format_type = Str('application/javascript')
521
538
@@ -45,7 +45,7 b' def print_png(o):'
45 # them with suitable subs.
45 # them with suitable subs.
46 s = s.replace('\\operatorname','')
46 s = s.replace('\\operatorname','')
47 s = s.replace('\\overline', '\\bar')
47 s = s.replace('\\overline', '\\bar')
48 png = latex_to_png(s, encode=True)
48 png = latex_to_png(s)
49 return png
49 return png
50
50
51 _loaded = False
51 _loaded = False
@@ -25,7 +25,7 b' from base64 import encodestring'
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26
26
27
27
28 def latex_to_png(s, encode=True):
28 def latex_to_png(s, encode=False):
29 """Render a LaTeX string to PNG using matplotlib.mathtext.
29 """Render a LaTeX string to PNG using matplotlib.mathtext.
30
30
31 Parameters
31 Parameters
@@ -16,6 +16,7 b' machinery. This should thus be thought of as scaffolding.'
16 from __future__ import print_function
16 from __future__ import print_function
17
17
18 # Stdlib
18 # Stdlib
19 from base64 import encodestring
19 import inspect
20 import inspect
20 import os
21 import os
21
22
@@ -67,6 +68,9 b' class ZMQDisplayHook(DisplayHook):'
67 self.msg['content']['execution_count'] = self.prompt_count
68 self.msg['content']['execution_count'] = self.prompt_count
68
69
69 def write_format_data(self, format_dict):
70 def write_format_data(self, format_dict):
71 pngdata = format_dict.get('image/png')
72 if pngdata is not None:
73 format_dict['image/png'] = encodestring(pngdata)
70 self.msg['content']['data'] = format_dict
74 self.msg['content']['data'] = format_dict
71
75
72 def finish_displayhook(self):
76 def finish_displayhook(self):
@@ -1,9 +1,10 b''
1 """Code that shows off the IPython display logic.
1 """Code that shows off the IPython display logic.
2 """
2 """
3
3
4 from IPython.lib.latextools import latex_to_png
4 from IPython.core.display import (
5 from IPython.core.display import (
5 display, display_pretty, display_html,
6 display, display_pretty, display_html,
6 display_svg, display_json
7 display_svg, display_json, display_png
7 )
8 )
8
9
9 class Circle(object):
10 class Circle(object):
@@ -22,3 +23,5 b' class Circle(object):'
22 <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
23 <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
23 </svg>"""
24 </svg>"""
24
25
26 def _repr_png_(self):
27 return latex_to_png('$\circle$')
General Comments 0
You need to be logged in to leave comments. Login now