View

View is the central class in Gaphas. It shows your diagram and allows you to interact with it.

class gaphas.view.GtkView(model: Model | None = None, selection: Selection = None)[source]

GTK+ widget for rendering a gaphas.view.model.Model to a screen. The view uses Tools to handle events and Painters to draw. Both are configurable.

The widget already contains adjustment objects (hadjustment, vadjustment) to be used for scrollbars.

This view registers itself on the model, so it will receive update events.

property matrix: gaphas.matrix.Matrix

Model root to view transformation matrix.

get_matrix_i2v(item: gaphas.item.Item) gaphas.matrix.Matrix[source]

Get Item to View matrix for item.

get_matrix_v2i(item: gaphas.item.Item) gaphas.matrix.Matrix[source]

Get View to Item matrix for item.

property model: Model | None

The model.

property painter: gaphas.painter.painter.Painter

Painter for drawing the view.

property bounding_box_painter: gaphas.painter.painter.ItemPainterType

Special painter for calculating item bounding boxes.

property selection: gaphas.selection.Selection

Selected, focused and hovered items.

property bounding_box: gaphas.geometry.Rectangle

The bounding box of the complete view, relative to the view port.

property hadjustment: gi.overrides.Gtk.Adjustment

Gtk adjustment object for use with a scrollbar.

property vadjustment: gi.overrides.Gtk.Adjustment

Gtk adjustment object for use with a scrollbar.

clamp_item(item)[source]

Update adjustments so the item is located inside the view port.

add_controller(*controllers: gi.repository.Gtk.EventController) None[source]

Add a controller.

A convenience method, so you have a place to store the event controllers. Events controllers are linked to a widget (in GTK3) on creation time, so calling this method is not necessary.

remove_controller(controller: gi.repository.Gtk.EventController) bool[source]

Remove a controller.

The event controller’s propagation phase is set to Gtk.PropagationPhase.NONE to ensure it’s not invoked anymore.

NB. The controller is only really removed from the widget when it’s destroyed!

This is a Gtk3 limitation.

remove_all_controllers() None[source]

Remove all registered controllers.

zoom(factor: float) None[source]

Zoom in/out by factor factor.

get_items_in_rectangle(rect: Tuple[float, float, float, float], contain: bool = False) Iterable[gaphas.item.Item][source]

Return the items in the rectangle ‘rect’ (in view coordinates).

Items are automatically sorted in model’s processing order.

get_item_bounding_box(item: gaphas.item.Item) gaphas.geometry.Rectangle[source]

Get the bounding box for the item, in view coordinates.

request_update(items: Iterable[gaphas.item.Item], removed_items: Iterable[gaphas.item.Item] = ()) None[source]

Request update for items.

update() None[source]

Update view status according to the items updated in the model.

all_dirty_items() set[gaphas.item.Item][source]

Return all dirty items, clearing the marked items.

update_bounding_box(items: Collection[gaphas.item.Item]) None[source]

Update the bounding boxes of the model items for this view, in model coordinates.

do_realize() None[source]

realize(self)

do_unrealize() None[source]

unrealize(self)

do_configure_event(event: gi.overrides.Gdk.EventConfigure) bool[source]

configure_event(self, event:Gdk.EventConfigure) -> bool

do_draw(cr: cairo.Context, width: int = 0, height: int = 0) bool[source]

draw(self, cr:cairo.Context) -> bool