Exemple #1
0
    def render_snapshot(self):
        """
        Method rendering and displaying a snasphot of the widget.

        This can be useful to save a version of the widget that can actually
        be seen in a static rendition of your notebook (when using nbconvert,
        for instance, or when reading the notebook on GitHub).

        Returns:
            Ipython.display.HTML: the snasphot as a data url in an img tag.
        """

        out = Output()
        out.append_stdout(
            "Rendering snapshot from widget (are you sure the widget is currently displayed?)..."
        )

        def on_update(change):
            if change.new is None:
                return

            out.clear_output()

            with out:
                display(Image(url=change.new))

            self.unobserve(on_update, "snapshot")

        self.observe(on_update, "snapshot")
        self.send({"msg": "render_snapshot"})

        return out
Exemple #2
0
 def _cb(pts):
     if pts_callback:
         pts_callback(pts, rej, box)
     else:
         out = Output()
         box.children = tuple(list(box.children) + [out])
         out.append_stdout(pts)
def test_append_stdout():
    output = Output()

    # Try appending a message to stdout.
    output.append_stdout("snakes!")
    expected = (_make_stream_output("snakes!", "stdout"),)
    assert output.outputs == expected, repr(output.outputs)

    # Try appending a second message.
    output.append_stdout("more snakes!")
    expected += (_make_stream_output("more snakes!", "stdout"),)
    assert output.outputs == expected, repr(output.outputs)
def test_append_stdout():
    output = Output()

    # Try appending a message to stdout.
    output.append_stdout("snakes!")
    expected = (_make_stream_output("snakes!", "stdout"), )
    assert output.outputs == expected, repr(output.outputs)

    # Try appending a second message.
    output.append_stdout("more snakes!")
    expected += (_make_stream_output("more snakes!", "stdout"), )
    assert output.outputs == expected, repr(output.outputs)