Painters

Painters are used to draw the view.

Protocols

Each painter adheres to the Painter protocol.

class gaphas.painter.Painter(*args, **kwds)[source]

Painter interface.

paint(items: Collection[gaphas.item.Item], cairo: gaphas.types.CairoContext)None[source]

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, **kwds)[source]
paint_item(item: gaphas.item.Item, cairo: gaphas.types.CairoContext)None[source]

Draw a single item.

paint(items: Collection[gaphas.item.Item], cairo: gaphas.types.CairoContext)None[source]

Do the paint action (called from the View).

Default implementations

class gaphas.painter.PainterChain[source]

Chain up a set of painters.

append(painter: gaphas.painter.painter.Painter)gaphas.painter.chain.PainterChain[source]

Add a painter to the list of painters.

prepend(painter: gaphas.painter.painter.Painter)gaphas.painter.chain.PainterChain[source]

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

class gaphas.painter.ItemPainter(selection: Optional[gaphas.view.selection.Selection] = None)[source]
class gaphas.painter.HandlePainter(view: GtkView)[source]

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

class gaphas.painter.BoundingBoxPainter(item_painter: gaphas.painter.painter.ItemPainterType)[source]

This specific case of an ItemPainter is used to calculate the bounding boxes (in cairo device coordinates) for the items.

Deprecated since 3.2: Bounding boxes are calculated in the View directly. This class is not a pass-through for the provided item_painter.

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

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: gaphas.tool.rubberband.RubberbandState)[source]

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

RubberbandState should be shared between the two.