gws.base.printer.worker

Print job worker.

Source code: gws.base.printer.worker

Module Contents

class gws.base.printer.worker.Object(root: gws.Root, user: gws.User, job: gws.Job | None, request: gws.PrintRequest)

Bases: gws.base.job.worker.Object

Print job worker.

Executes a print request and stores the result in the job.

contentPath: str

Path of the rendered output.

page_number = 0
printer: gws.Printer

Printer, for template requests.

project: gws.Project

Project of the request.

request
template: gws.Template

Template to render.

tri: gws.TemplateRenderInput

Template render input.

notify(event, details=None)

Handle a render progress event and update the job.

Parameters:
  • event – Event name: begin_plane, finalize_print or page_break.

  • details – Event details.

Raises:

gws.JobTerminated – If the job is no longer running.

prepare()

Prepare the template render input.

Resolves the project and the template, determines the output format, CRS and DPI, prepares the maps and sets the number of job steps. For template requests, the DPI is limited by the printer quality levels; for map requests, a temporary map template of the requested size is created.

Raises:

gws.Error – If the output format is invalid.

prepare_map(tri: gws.TemplateRenderInput, mp: gws.PrintMap) → gws.MapRenderInput

Convert a print map from the request to a map render input.

Parses the styles sent by the client (untrusted), converts the planes and resolves the visible layers. Planes that cannot be prepared are skipped.

Parameters:
  • tri – Template render input.

  • mp – Print map.

Returns:

The map render input.

prepare_map_plane(n, plane: gws.PrintPlane, style_dct) → gws.MapRenderInputPlane | None

Convert a print plane to a render plane.

Parameters:
  • n – Plane index, used in log messages.

  • plane – Print plane.

  • style_dct – Styles by CSS selector.

Returns:

The render plane, or None if the plane is fully transparent or cannot be prepared (layer not found or not renderable, invalid image, no features).

Raises:

gws.Error – If the plane type is invalid.

classmethod run(root: gws.Root, job: gws.Job)

Run a print job, called by the job manager.

Parameters:
  • root – Root object.

  • job – Job, with the path of the pickled request in its payload.

work()

Prepare and render the print, set contentPath and mark the job complete.

Raises:

gws.Error – If the request is invalid.