vpype_viewer#

This module implements a flexible, GPU-accelerated viewer for interactive and offscreen rendering of vpype.Document instances. It includes a Qt-based interactive backend as well as a Pillow-based offscreen rendering backend.

Functions

render_image

Render a vpype.Document instance as a Pillow PIL.Image.Image.

show

Show a viewer for the provided vpype.Document instance.

Classes

Engine(view_mode, show_pen_up, show_points, ...)

OpenGL-based rendering engine for vpype.Document.

ImageRenderer(size)

Viewer engine wrapper class to render to a PIL.Image.Image instance.

QtViewer([document, view_mode, show_pen_up, ...])

Full-featured, stand-alone viewer suitable for displaying a vpype.Document to a user.

UnitType(value[, names, module, qualname, ...])

Type of unit to use for display purposes.

ViewMode(value[, names, module, qualname, ...])

View mode enum.

Functions#

render_image(document: Document, size: tuple[int, int] = (512, 512), view_mode: ViewMode = ViewMode.PREVIEW, show_pen_up: bool = False, show_points: bool = False, default_pen_width: float = 1.1, default_pen_opacity: float = 0.8, override_pen_width: bool = False, override_pen_opacity: bool = False, show_ruler: bool = False, pixel_factor: float = 1.0, unit_type: UnitType = UnitType.METRIC, scale: float | None = None, origin: tuple[float, float] | None = None) Image#

Render a vpype.Document instance as a Pillow PIL.Image.Image.

By default, the document is scaled and offset to entirely fit in the image. This behaviour can be overridden using the scale and offset arguments.

Parameters:
  • document (Document) -- document to render

  • size (tuple[int, int]) -- output image size

  • view_mode (ViewMode) -- ViewMode to use

  • show_pen_up (bool) -- render pen-up trajectories

  • show_points (bool) -- render points

  • default_pen_width (float) -- pen width (ViewMode.PREVIEW only)

  • default_pen_opacity (float) -- pen opacity (ViewMode.PREVIEW only)

  • override_pen_width (bool) -- override pen width property (ViewMode.PREVIEW only)

  • override_pen_opacity (bool) -- override pen opacity property (ViewMode.PREVIEW only)

  • show_ruler (bool) -- display the rulers

  • pixel_factor (float) -- pixel factor (HiDPI screen support)

  • unit_type (UnitType) -- type of unit to use for the ruler

  • scale (float | None) -- manually set scale

  • origin (tuple[float, float] | None) -- manually set origin

Returns:

the rendered image

Return type:

PIL.Image.Image

show(document: Document, view_mode: ViewMode = ViewMode.PREVIEW, show_pen_up: bool = False, show_points: bool = False, argv=None) int#

Show a viewer for the provided vpype.Document instance.

This function returns when the user close the window.

Parameters:
  • document (Document) -- the document to display

  • view_mode (ViewMode) -- view mode

  • show_pen_up (bool) -- render pen-up trajectories

  • show_points (bool) -- render points

  • argv -- argument passed to Qt

Returns:

exit status returned by Qt

Return type:

int