Painters - Gaphas

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# Painters

Painters are used to draw the view.

## Protocols

Each painter adheres to the `Painter` protocol.

class gaphas.painter.Painter(*args, **kwargs)

  Painter interface.

  paint(items: Collection[Item], cairo: cairo.Context) → None

    Do the paint action (called from the View).

Some painters, such as `FreeHandPainter` and `BoundingBoxPainter`, require a special painter protocol:

class gaphas.painter.painter.ItemPainterType(*args, **kwargs)
  paint_item(item: Item, cairo: cairo.Context) → None

    Draw a single item.

  paint(items: Collection[Item], cairo: cairo.Context) → None

    Do the paint action (called from the View).

## Default implementations

class gaphas.painter.PainterChain

  Chain up a set of painters.

  append(painter: Painter) → PainterChain

    Add a painter to the list of painters.

  prepend(painter: Painter) → PainterChain

    Add a painter to the beginning of the list of painters.

class gaphas.painter.ItemPainter(selection: Selection | None = None)

class gaphas.painter.HandlePainter(view: GtkView)

  Draw handles of items that are marked as selected in the view.

class gaphas.painter.FreeHandPainter(item_painter: ItemPainterType, sloppiness: float = 0.5)

  This painter is a wrapper for an Item painter. The Cairo context is modified to allow for a sloppy, hand written drawing style.

  Range [0..2.0] gives acceptable results.

  - Draftsman: 0.0

  - Artist: 0.25

  - Cartoonist: 0.5

  - Child: 1.0

  - Drunk: 2.0

## Rubberband tool

A special painter is used to display rubberband selection. This painter shares some state with the rubberband tool.

class gaphas.tool.rubberband.RubberbandPainter(rubberband_state: RubberbandState)

  The rubberband painter should be used in conjunction with the rubberband tool.

  `RubberbandState` should be shared between the two.