View

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

class gaphas.view.GtkView(*args: Any, **kwargs: Any)[source]

GTK widget for rendering a gaphas.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: Matrix

Model root to view transformation matrix.

get_matrix_i2v(item: Item) Matrix[source]

Get Item to View matrix for item.

get_matrix_v2i(item: Item) Matrix[source]

Get View to Item matrix for item.

property model: Model | None

The model.

property painter: Painter

Painter for drawing the view.

property bounding_box_painter: ItemPainterType

Special painter for calculating item bounding boxes.

property selection: Selection

Selected, focused and hovered items.

property bounding_box: Rectangle

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

property hadjustment: gi.repository.Gtk.Adjustment

Gtk adjustment object for use with a scrollbar.

property vadjustment: gi.repository.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.

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

Remove a controller.

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[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: Item) Rectangle[source]

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

request_update(items: Iterable[Item], removed_items: Iterable[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[Item][source]

Return all dirty items, clearing the marked items.

update_bounding_box(items: Collection[Item]) None[source]

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