Example #1
0
def test_screenshot(qtbot):
    "Test taking a screenshot"
    viewer = Viewer()
    view = viewer.window.qt_viewer
    qtbot.addWidget(view)

    np.random.seed(0)
    # Add image
    data = np.random.random((10, 15))
    viewer.add_image(data)

    # Add labels
    data = np.random.randint(20, size=(10, 15))
    viewer.add_labels(data)

    # Add points
    data = 20 * np.random.random((10, 2))
    viewer.add_points(data)

    # Add vectors
    data = 20 * np.random.random((10, 2, 2))
    viewer.add_vectors(data)

    # Add shapes
    data = 20 * np.random.random((10, 4, 2))
    viewer.add_shapes(data)

    # Take screenshot
    screenshot = viewer.screenshot()
    assert screenshot.ndim == 3

    # Close the viewer
    viewer.window.close()
Example #2
0
 def from_viewer(cls, viewer: Viewer, steps=15, ease=Easing.LINEAR):
     """Create a KeyFrame from a viewer instance."""
     return cls(
         viewer_state=ViewerState.from_viewer(viewer),
         thumbnail=make_thumbnail(viewer.screenshot(canvas_only=True)),
         steps=steps,
         ease=ease,
     )