| 32 | |
| 33 | |
| 34 | class DisplayFormatter(Configurable): |
| 35 | |
| 36 | active_types = List(Unicode(), |
| 37 | help="""List of currently active mime-types to display. |
| 38 | You can use this to set a white-list for formats to display. |
| 39 | |
| 40 | Most users will not need to change this value. |
| 41 | """).tag(config=True) |
| 42 | |
| 43 | @default('active_types') |
| 44 | def _active_types_default(self): |
| 45 | return self.format_types |
| 46 | |
| 47 | @observe('active_types') |
| 48 | def _active_types_changed(self, change): |
| 49 | for key, formatter in self.formatters.items(): |
| 50 | if key in change['new']: |
| 51 | formatter.enabled = True |
| 52 | else: |
| 53 | formatter.enabled = False |
| 54 | |
| 55 | ipython_display_formatter = ForwardDeclaredInstance('FormatterABC') |
| 56 | @default('ipython_display_formatter') |
| 57 | def _default_formatter(self): |
| 58 | return IPythonDisplayFormatter(parent=self) |
| 59 | |
| 60 | mimebundle_formatter = ForwardDeclaredInstance('FormatterABC') |
| 61 | @default('mimebundle_formatter') |
| 62 | def _default_mime_formatter(self): |
| 63 | return MimeBundleFormatter(parent=self) |
| 64 | |
| 65 | # A dict of formatter whose keys are format types (MIME types) and whose |
| 66 | # values are subclasses of BaseFormatter. |
| 67 | formatters = Dict() |
| 68 | @default('formatters') |
| 69 | def _formatters_default(self): |
| 70 | """Activate the default formatters.""" |
| 71 | formatter_classes = [ |
| 72 | PlainTextFormatter, |
| 73 | HTMLFormatter, |
| 74 | MarkdownFormatter, |
| 75 | SVGFormatter, |
| 76 | PNGFormatter, |
| 77 | PDFFormatter, |
| 78 | JPEGFormatter, |
| 79 | LatexFormatter, |
| 80 | JSONFormatter, |
| 81 | JavascriptFormatter |
| 82 | ] |
| 83 | d = {} |
| 84 | for cls in formatter_classes: |
| 85 | f = cls(parent=self) |
| 86 | d[f.format_type] = f |
| 87 | return d |
| 88 | |
| 89 | def format(self, obj, include=None, exclude=None): |
| 90 | """Return a format data dict for an object. |
| 91 |
no outgoing calls
no test coverage detected