Beispiel #1
0
def display(segments: Iterable[Segment], text: str) -> None:
    """Render segments to Jupyter."""
    from IPython.display import display as ipython_display

    html = _render_segments(segments)
    jupyter_renderable = JupyterRenderable(html, text)
    ipython_display(jupyter_renderable)
Beispiel #2
0
    def imgcat(self, line=''):
        '''%imgcat magic, equivalent to imgcat(<expression>).

        Usage: %imgcat <expression>
        '''
        if not line:
            ipython_display(Markdown("Usage: `%imgcat [python code]`"))
            return

        if os.path.isfile(line):
            with open(line, mode='rb') as fp:
                ret = fp.read()
        else:
            global_ns = self.shell.user_global_ns
            local_ns = self.shell.user_ns

            ret = eval(line, global_ns, local_ns)  # pylint: disable=eval-used

        if IS_NOTEBOOK:
            from .imgcat import to_content_buf
            buf = io.BytesIO(to_content_buf(ret))
            im = PIL.Image.open(buf)
            ipython_display(im)
            buf.close()
        else:
            from .imgcat import imgcat
            imgcat(ret)
Beispiel #3
0
def display(value):
    if inside_ipython():
        from IPython.display import display as ipython_display, HTML
        if isinstance(value, str):
            ipython_display(HTML(rst_to_html(value)))
        else:
            ipython_display(value)
    else:
        print(value)
Beispiel #4
0
def display(widget):
    """
    Open up a new browser window and display widget in a jupyter notebook output cell
    :param widget: the widget to display
    :return:
    """
    _check_started()
    jupyter_singleton.singleton_app.open_singleton()
    ipython_display(widget)
Beispiel #5
0
def display(value):
    if inside_ipython():
        from IPython.display import display as ipython_display, HTML
        if isinstance(value, str):
            ipython_display(HTML(rst_to_html(value)))
        else:
            ipython_display(value)
    else:
        print(value)
Beispiel #6
0
def display(segments: Iterable[Segment], text: str) -> None:
    """Render segments to Jupyter."""
    html = _render_segments(segments)
    jupyter_renderable = JupyterRenderable(html, text)
    try:
        from IPython.display import display as ipython_display

        ipython_display(jupyter_renderable)
    except ModuleNotFoundError:
        # Handle the case where the Console has force_jupyter=True,
        # but IPython is not installed.
        pass
Beispiel #7
0
 def __enter__(self):
     self.reset()
     if self._displays is None:
         self._displays = [
             ipython_display(self, display_id=True)
             if _in_zmq_interactive_shell()
             else FileDisplay(self._position)]
     return self
Beispiel #8
0
 def notebook(self):
     """ Display SVG in Jupyther notebook. """
     try:
         # Import IPython display for notebook
         from IPython.display import SVG as ipython_display
         # Display in notebook
         return ipython_display(self.string)
     except ImportError:
         raise Warning(""" IPython not installed. """)
Beispiel #9
0
def display(*args, **kwargs):
    if in_ipynb():
        try:
            from IPython.display import display as ipython_display
            return ipython_display(*args, **kwargs)
        except:

            warnings.warn("ERROR loading display from IPython")
            pass
Beispiel #10
0
def _create_display(obj: object, position: Tuple[int, int]):
    """Create an updateable display object.

    Args:
        obj: Initial object to display.
        position: Tuple specifying position of display within
            a sequence of displays with first entry corresponding to the
            zero-indexed position and the second entry the total number of
            displays.

    Returns:
        Object with `update` method to update displayed content.
    """
    if _in_zmq_interactive_shell():
        return ipython_display(obj, display_id=True)
    else:
        return FileDisplay(position)
Beispiel #11
0
 def show_image(self, image, **options):
     ipython_display(image)
     return 1
Beispiel #12
0
def run(constructor):
    """Run the given IDOM elemen definition as a Jupyter Widget.

    This function is meant to be similarly to ``idom.run``.
    """
    return ipython_display(LayoutWidget(constructor()))
Beispiel #13
0
 def selective_plot(self, what: Any):
     that = what() if callable(what) else what
     if isinstance(that, bokeh.plotting.Figure):
         bokeh.plotting.show(that)
     else:
         ipython_display(that)
Beispiel #14
0
 def display(self):
     ipython_display(self)
     return self
Beispiel #15
0
 def display(text):
     ipython_display(HTML(text))