ScreenshotCapture
Screenshot capture utilities for Slicer views.
Captures screenshots of slice views, 3D views, layouts, and widgets. Screenshots can be organized into groups (subdirectories) or saved in flat mode with all screenshots in a single folder. Descriptions are stored in a manifest file.
Classes
- class ScreenshotInfo
Information about a captured screenshot.
Methods:
- to_dict()
Convert to dictionary for JSON serialization.
- class ScreenshotGroup
A group of screenshots (stored in a subdirectory or logically grouped).
Methods:
- next_number()
Get the next screenshot number and increment counter.
- class ScreenshotCapture
Capture screenshots with auto-numbering.
Can operate in two modes: - Flat mode (default): All screenshots go in one folder with global numbering.
Group names are stored in manifest only, not as folders.
Grouped mode: Screenshots organized into subdirectories per group.
- Usage (flat mode):
capture = ScreenshotCapture(base_folder=Path(“./screenshots”), flat_mode=True)
# Set test name (for manifest organization) capture.set_group(“workflow_basic”)
# Take screenshots (global auto-numbering) info = capture.screenshot(“[setup] Initial state”) # -> 001.png info = capture.screenshot(“[paint] After painting”) # -> 002.png
# Change test capture.set_group(“algorithm_watershed”) info = capture.screenshot(“[setup] Watershed ready”) # -> 003.png
# Save manifest with all descriptions capture.save_manifest()
Methods:
- __init__()
Initialize screenshot capture.
- set_base_folder()
Set the base folder for screenshots.
- set_group()
Set the current screenshot group (creates if needed).
- new_group()
Create a new screenshot group and make it current.
- current_group()
Get the current screenshot group.
- screenshot()
Take a screenshot of the current layout (auto-numbered).
- capture_layout()
Capture screenshot of the entire Slicer layout.
- capture_slice_view()
Capture screenshot of a specific slice view.
- capture_layout_with_3d()
Capture both layout and 3D view as separate files.
- capture_3d_view()
Capture screenshot of the 3D view.
- capture_widget()
Capture screenshot of a specific Qt widget.
- save_manifest()
Save manifest with all screenshot descriptions.
- update_description()
Update the description for a screenshot.
- get_all_screenshots()
Get all screenshots taken.
- get_group_screenshots()
Get screenshots for a specific group.
- get_screenshots_by_tags()
Get screenshots matching specified doc_tags.
- get_doc_screenshots()
Get all screenshots that have doc_tags (for documentation generation).
Functions
- to_dict()
Convert to dictionary for JSON serialization.
- next_number()
Get the next screenshot number and increment counter.
- set_base_folder()
Set the base folder for screenshots.
- set_group()
Set the current screenshot group (creates if needed).
In flat mode, the group name is for manifest organization only. In grouped mode, creates a subdirectory.
- Args:
- name: Group name (used as subdirectory name in grouped mode,
or just for manifest organization in flat mode).
- Returns:
The ScreenshotGroup object.
- new_group()
Create a new screenshot group and make it current.
- Args:
name: Group name.
- Returns:
The new ScreenshotGroup object.
- current_group()
Get the current screenshot group.
- screenshot()
Take a screenshot of the current layout (auto-numbered).
- Args:
description: Description of what the screenshot shows. doc_tags: Tags for documentation filtering (e.g., [“algorithm”, “watershed”]).
Screenshots with doc_tags are included in auto-generated documentation.
- Returns:
ScreenshotInfo with path and metadata.
- capture_layout()
Capture screenshot of the entire Slicer layout.
- Args:
description: Human-readable description. doc_tags: Tags for documentation filtering (e.g., [“algorithm”, “watershed”]).
- Returns:
ScreenshotInfo with path and metadata.
- capture_slice_view()
Capture screenshot of a specific slice view.
- Args:
view: View name (“Red”, “Yellow”, “Green”). description: Human-readable description. doc_tags: Tags for documentation filtering.
- Returns:
ScreenshotInfo with path and metadata.
- capture_layout_with_3d()
Capture both layout and 3D view as separate files.
This method captures the entire layout screenshot first, then attempts to capture a dedicated 3D view screenshot. This ensures 3D visualization is always captured for review.
- Args:
description: Human-readable description for the screenshots. doc_tags: Tags for documentation filtering.
- Returns:
Tuple of (layout_info, three_d_info). three_d_info is None if no 3D view is available in the current layout.
- capture_3d_view()
Capture screenshot of the 3D view.
- Args:
description: Human-readable description. view_node_index: Index of 3D view node (default 0 for first). doc_tags: Tags for documentation filtering.
- Returns:
ScreenshotInfo with path and metadata.
- capture_widget()
Capture screenshot of a specific Qt widget.
- Args:
widget: Qt widget to capture. description: Human-readable description. doc_tags: Tags for documentation filtering.
- Returns:
ScreenshotInfo with path and metadata.
- save_manifest()
Save manifest with all screenshot descriptions.
In flat mode, shows all screenshots in order with their test group. In grouped mode, organizes by group subdirectory.
- Returns:
Path to the manifest file.
- update_description()
Update the description for a screenshot.
- Args:
group: Group name. number: Screenshot number within the group. description: New description.
- Returns:
True if found and updated, False otherwise.
- get_all_screenshots()
Get all screenshots taken.
- get_group_screenshots()
Get screenshots for a specific group.
- get_screenshots_by_tags()
Get screenshots matching specified doc_tags.
- Args:
tags: Tags to match. match_all: If True, screenshot must have ALL tags. If False (default),
screenshot must have ANY of the tags.
- Returns:
List of matching ScreenshotInfo objects.
- get_doc_screenshots()
Get all screenshots that have doc_tags (for documentation generation).