GooCanvas.Canvas

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.Scrollable Gtk.Scrollable GObject.GInterface->Gtk.Scrollable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned GooCanvas.Canvas GooCanvas.Canvas Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Container->GooCanvas.Canvas Gtk.Scrollable->GooCanvas.Canvas Gtk.Widget->Gtk.Container

Subclasses:

None

Methods

Inherited:

Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Scrollable (9)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

create_path (commands, cr)

class

marshal_BOOLEAN__BOXED (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)

class

marshal_BOOLEAN__DOUBLE_DOUBLE_BOOLEAN_OBJECT (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)

class

marshal_BOOLEAN__OBJECT_BOXED (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)

class

marshal_VOID__INT_INT (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)

class

marshal_VOID__OBJECT_OBJECT (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)

class

new ()

class

parse_path_data (path_data)

convert_bounds_to_item_space (item, bounds)

convert_from_item_space (item, x, y)

convert_from_pixels (x, y)

convert_to_item_space (item, x, y)

convert_to_pixels (x, y)

convert_units_from_pixels (x, y)

convert_units_to_pixels (x, y)

create_cairo_context ()

create_item (model)

get_bounds ()

get_default_line_width ()

get_item (model)

get_item_at (x, y, is_pointer_event)

get_items_at (x, y, is_pointer_event)

get_items_in_area (area, inside_area, allow_overlaps, include_containers)

get_root_item ()

get_root_item_model ()

get_scale ()

get_static_root_item ()

get_static_root_item_model ()

grab_focus (item)

keyboard_grab (item, owner_events, time)

keyboard_ungrab (item, time)

pointer_grab (item, event_mask, cursor, time)

pointer_ungrab (item, time)

register_widget_item (witem)

render (cr, bounds, scale)

request_item_redraw (bounds, is_static)

request_redraw (bounds)

request_update ()

scroll_to (left, top)

set_bounds (left, top, right, bottom)

set_root_item (item)

set_root_item_model (model)

set_scale (scale)

set_static_root_item (item)

set_static_root_item_model (model)

unregister_item (model)

unregister_widget_item (witem)

update ()

Virtual Methods

Inherited:

Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Scrollable (1)

do_create_item (model)

do_item_created (item, model)

Properties

Inherited:

Gtk.Container (3), Gtk.Widget (39), Gtk.Scrollable (4)

Name

Type

Flags

Short Description

anchor

GooCanvas.CanvasAnchorType

r/w

Where to place the canvas when it is smaller than the widget’s allocated area

automatic-bounds

bool

r/w

If the bounds are automatically calculated based on the bounds of all the items in the canvas

background-color

str

w

The color to use for the canvas background

background-color-gdk-rgba

Gdk.RGBA

w

The color to use for the canvas background, specified as a Gdk.RGBA

background-color-rgb

int

w

The color to use for the canvas background, specified as a 24-bit integer value, 0xRRGGBB

bounds-from-origin

bool

r/w

If the automatic bounds are calculated from the origin

bounds-padding

float

r/w

The padding added to the automatic bounds

clear-background

bool

r/w

If the background is cleared before the canvas is painted

integer-layout

bool

r/w

If all item layout is done to the nearest integer

redraw-when-scrolled

bool

r/w

If the canvas is completely redrawn when scrolled, to reduce the flicker of static items. Note that since GTK+ 3.0 the canvas is always redrawn when scrolled, so this option has no effect.

resolution-x

float

r/w

The horizontal resolution of the display, in dots per inch

resolution-y

float

r/w

The vertical resolution of the display, in dots per inch

scale

float

r/w

The magnification factor of the canvas

scale-x

float

r/w

The horizontal magnification factor of the canvas

scale-y

float

r/w

The vertical magnification factor of the canvas

units

Gtk.Unit

r/w

The units to use for the canvas

x1

float

r/w

The x coordinate of the left edge of the canvas bounds, in canvas units

x2

float

r/w

The x coordinate of the right edge of the canvas bounds, in canvas units

y1

float

r/w

The y coordinate of the top edge of the canvas bounds, in canvas units

y2

float

r/w

The y coordinate of the bottom edge of the canvas bounds, in canvas units

Style Properties

Inherited:

Gtk.Widget (17)

Signals

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Short Description

item-created

This is emitted when a new canvas item is created, in model/view mode.

Fields

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Type

Access

Description

anchor

GooCanvas.CanvasAnchorType

r

automatic_bounds

int

r

before_initial_draw

int

r

bounds

GooCanvas.CanvasBounds

r

bounds_from_origin

int

r

bounds_padding

float

r

canvas_window

Gdk.Window

r

canvas_x_offset

int

r

canvas_y_offset

int

r

clear_background

int

r

container

Gtk.Container

r

crossing_event

Gdk.EventCrossing

r

device_to_pixels_x

float

r

device_to_pixels_y

float

r

focused_item

GooCanvas.CanvasItem

r

freeze_count

int

r

hadjustment

Gtk.Adjustment

r

hscroll_policy

int

r

idle_id

int

r

integer_layout

int

r

keyboard_grab_item

GooCanvas.CanvasItem

r

model_to_item

{object: object}

r

need_entire_subtree_update

int

r

need_update

int

r

pointer_grab_button

int

r

pointer_grab_initial_item

GooCanvas.CanvasItem

r

pointer_grab_item

GooCanvas.CanvasItem

r

pointer_item

GooCanvas.CanvasItem

r

redraw_when_scrolled

int

r

resolution_x

float

r

resolution_y

float

r

root_item

GooCanvas.CanvasItem

r

root_item_model

GooCanvas.CanvasItemModel

r

scale

float

r

scale_x

float

r

scale_y

float

r

tmp_window

Gdk.Window

r

units

Gtk.Unit

r

vadjustment

Gtk.Adjustment

r

vscroll_policy

int

r

widget_items

[object]

r

Class Details

class GooCanvas.Canvas(**kwargs)
Bases:

Gtk.Container, Gtk.Scrollable

Abstract:

No

Structure:

GooCanvas.CanvasClass

GooCanvas.Canvas is the main widget containing a number of canvas items.

Here is a GooCanvas.simple example:

<informalexample><programlisting> &num;include &lt;goocanvas.h&gt;

static bool on_rect_button_press (GooCanvas.CanvasItem *view, GooCanvas.CanvasItem *target, Gdk.EventButton *event, object data);

int main (int argc, str *argv[]) { Gtk.Widget *window, *scrolled_win, *canvas; GooCanvas.CanvasItem *root, *rect_item, *text_item;

/&ast; Initialize GTK+. &ast;/ Gtk.init (&amp;argc, &amp;argv);

/&ast; Create the window and widgets. &ast;/ window = Gtk.Window.new (Gtk.WindowType.TOPLEVEL); Gtk.Window.set_default_size (GTK_WINDOW (window), 640, 600); Gtk.Widget.show (window); g_signal_connect (window, “delete_event”, G_CALLBACK (on_delete_event), None);

scrolled_win = Gtk.ScrolledWindow.new (None, None); Gtk.ScrolledWindow.set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), Gtk.ShadowType.IN); Gtk.Widget.show (scrolled_win); Gtk.Container.add (GTK_CONTAINER (window), scrolled_win);

canvas = GooCanvas.Canvas.new&nbsp;(); Gtk.Widget.set_size_request (canvas, 600, 450); GooCanvas.Canvas.set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000); Gtk.Widget.show (canvas); Gtk.Container.add (GTK_CONTAINER (scrolled_win), canvas);

root = GooCanvas.Canvas.get_root_item (GOO_CANVAS (canvas));

/&ast; Add a few GooCanvas.simple items. &ast;/ rect_item = goo_canvas_rect_new (root, 100, 100, 400, 400, “line-width”, 10.0, “radius-x”, 20.0, “radius-y”, 10.0, “stroke-color”, “yellow”, “fill-color”, “red”, None);

text_item = goo_canvas_text_new (root, “Hello World”, 300, 300, -1, GooCanvas.CanvasAnchorType.CENTER, “font”, “Sans 24”, None); GooCanvas.CanvasItem.rotate (text_item, 45, 300, 300);

/&ast; Connect a signal handler for the rectangle item. &ast;/ g_signal_connect (rect_item, “button_press_event”, G_CALLBACK (on_rect_button_press), None);

/&ast; Pass control to the GTK+ main event loop. &ast;/ Gtk.main&nbsp;();

return 0; }

/&ast; This handles button presses in item views. We simply output a message to the console. &ast;/ static bool on_rect_button_press (GooCanvas.CanvasItem *item, GooCanvas.CanvasItem *target, Gdk.EventButton *event, object data) { g_print (“rect item received button press event\n”); return True; }

</programlisting></informalexample>

A GooCanvas.Canvas widget is usually placed inside a Gtk.ScrolledWindow widget and can be scrolled with the scrollbar or with the scroll wheel on a mouse. To disable mouse wheel scrolling, do this: <informalexample><programlisting> g_signal_connect (canvas, “scroll-event”, G_CALLBACK (Gtk.true), None); </programlisting></informalexample>

classmethod create_path(commands, cr)
Parameters:

Creates the path specified by the given GooCanvas.CanvasPathCommand array.

classmethod marshal_BOOLEAN__BOXED(closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)
Parameters:
classmethod marshal_BOOLEAN__DOUBLE_DOUBLE_BOOLEAN_OBJECT(closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)
Parameters:
classmethod marshal_BOOLEAN__OBJECT_BOXED(closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)
Parameters:
classmethod marshal_VOID__INT_INT(closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)
Parameters:
classmethod marshal_VOID__OBJECT_OBJECT(closure, return_value, n_param_values, param_values, invocation_hint, marshal_data)
Parameters:
classmethod new()
Returns:

a new GooCanvas.Canvas widget.

Return type:

Gtk.Widget

Creates a new GooCanvas.Canvas widget.

A GooCanvas.CanvasGroup is created automatically as the root item of the canvas, though this can be overriden with GooCanvas.Canvas.set_root_item() or GooCanvas.Canvas.set_root_item_model().

classmethod parse_path_data(path_data)
Parameters:

path_data (str) –

the sequence of path commands, specified as a string using the same syntax as in the `Scalable

Vector Graphics (SVG) <http://www.w3.org/Graphics/SVG/>`__ path element.

Returns:

a GLib.Array of GooCanvas.CanvasPathCommand elements.

Return type:

[GooCanvas.CanvasPathCommand]

Parses the given SVG path specification string.

convert_bounds_to_item_space(item, bounds)
Parameters:

Converts the given bounds in the canvas coordinate space to a bounding box in item space. This is useful in the item paint() methods to convert the bounds to be painted to the item’s coordinate space.

convert_from_item_space(item, x, y)
Parameters:
Returns:

x:

a pointer to the x coordinate to convert.

y:

a pointer to the y coordinate to convert.

Return type:

(x: float, y: float)

Converts a coordinate from the given item’s coordinate space to the canvas coordinate space, applying all transformation matrices including the item’s own transformation matrix, if it has one.

convert_from_pixels(x, y)
Parameters:
  • x (float) – a pointer to the x coordinate to convert.

  • y (float) – a pointer to the y coordinate to convert.

Returns:

x:

a pointer to the x coordinate to convert.

y:

a pointer to the y coordinate to convert.

Return type:

(x: float, y: float)

Converts a coordinate from pixels to the canvas coordinate space.

The pixel coordinate space specifies pixels from the top-left of the entire canvas window, according to the current scale setting. See GooCanvas.Canvas.set_scale().

The canvas coordinate space is specified in the call to GooCanvas.Canvas.set_bounds().

convert_to_item_space(item, x, y)
Parameters:
Returns:

x:

a pointer to the x coordinate to convert.

y:

a pointer to the y coordinate to convert.

Return type:

(x: float, y: float)

Converts a coordinate from the canvas coordinate space to the given item’s coordinate space, applying all transformation matrices including the item’s own transformation matrix, if it has one.

convert_to_pixels(x, y)
Parameters:
  • x (float) – a pointer to the x coordinate to convert.

  • y (float) – a pointer to the y coordinate to convert.

Returns:

x:

a pointer to the x coordinate to convert.

y:

a pointer to the y coordinate to convert.

Return type:

(x: float, y: float)

Converts a coordinate from the canvas coordinate space to pixels.

The canvas coordinate space is specified in the call to GooCanvas.Canvas.set_bounds().

The pixel coordinate space specifies pixels from the top-left of the entire canvas window, according to the current scale setting. See GooCanvas.Canvas.set_scale().

convert_units_from_pixels(x, y)
Parameters:
  • x (float) – a pointer to the x coordinate to convert.

  • y (float) – a pointer to the y coordinate to convert.

Returns:

x:

a pointer to the x coordinate to convert.

y:

a pointer to the y coordinate to convert.

Return type:

(x: float, y: float)

Converts a coordinate from pixels to the canvas’s units, ignoring scaling and ignoring the coordinate space specified in the call to GooCanvas.Canvas.set_bounds().

New in version 2.0.1.

convert_units_to_pixels(x, y)
Parameters:
  • x (float) – a pointer to the x coordinate to convert.

  • y (float) – a pointer to the y coordinate to convert.

Returns:

x:

a pointer to the x coordinate to convert.

y:

a pointer to the y coordinate to convert.

Return type:

(x: float, y: float)

Converts a coordinate from the canvas’s units to pixels, ignoring scaling and ignoring the coordinate space specified in the call to GooCanvas.Canvas.set_bounds().

New in version 2.0.1.

create_cairo_context()
Returns:

a new cairo context. It should be freed with cairo_destroy().

Return type:

cairo.Context

Creates a cairo context, initialized with the default canvas settings. Note that this context should not be used for drawing. It should only be used for calculating bounds of items.

create_item(model)
Parameters:

model (GooCanvas.CanvasItemModel) – the item model to create a canvas item for.

Returns:

a new canvas item.

Return type:

GooCanvas.CanvasItem

This function is only intended to be used when implementing new canvas items, typically container items such as GooCanvas.CanvasGroup.

It creates a new canvas item for the given item model, and recursively creates items for any children.

It uses the create_item() virtual method if it has been set. Subclasses of GooCanvas.Canvas can define this method if they want to use custom views for items.

It emits the GooCanvas.Canvas ::item-created signal after creating the view, so application code can connect signal handlers to the new view if desired.

get_bounds()
Returns:

left:

a pointer to a float to return the left edge, or None.

top:

a pointer to a float to return the top edge, or None.

right:

a pointer to a float to return the right edge, or None.

bottom:

a pointer to a float to return the bottom edge, or None.

Return type:

(left: float, top: float, right: float, bottom: float)

Gets the bounds of the canvas, in canvas units.

By default, canvas units are pixels, though the GooCanvas.Canvas :units property can be used to change the units to points, inches or millimeters.

get_default_line_width()
Returns:

the default line width of the canvas.

Return type:

float

Gets the default line width, which depends on the current units setting.

get_item(model)
Parameters:

model (GooCanvas.CanvasItemModel) – a GooCanvas.CanvasItemModel.

Returns:

the canvas item corresponding to the given GooCanvas.CanvasItemModel, or None if no canvas item has been created for it yet.

Return type:

GooCanvas.CanvasItem

Gets the canvas item associated with the given GooCanvas.CanvasItemModel. This is only useful when GooCanvas.Canvas.set_root_item_model() has been used to set a model for the canvas.

For GooCanvas.simple applications you can use GooCanvas.Canvas.get_item() to set up signal handlers for your items, e.g.

item = goo_canvas_get_item (GOO_CANVAS (canvas), my_item);
g_signal_connect (item, "button_press_event",
                  (GtkSignalFunc) on_my_item_button_press, NULL);

More complex applications may want to use the GooCanvas.Canvas ::item-created signal to hook up their signal handlers.

get_item_at(x, y, is_pointer_event)
Parameters:
  • x (float) – the x coordinate of the point.

  • y (float) – the y coordinate of the point

  • is_pointer_event (bool) – True if the “pointer-events” property of items should be used to determine which parts of the item are tested.

Returns:

the item found at the given point, or None if no item was found.

Return type:

GooCanvas.CanvasItem

Gets the item at the given point.

get_items_at(x, y, is_pointer_event)
Parameters:
  • x (float) – the x coordinate of the point.

  • y (float) – the y coordinate of the point

  • is_pointer_event (bool) – True if the “pointer-events” property of items should be used to determine which parts of the item are tested.

Returns:

a list of items found at the given point, with the top item at the start of the list, or None if no items were found. The list must be freed with g_list_free().

Return type:

[GooCanvas.CanvasItem]

Gets all items at the given point.

get_items_in_area(area, inside_area, allow_overlaps, include_containers)
Parameters:
  • area (GooCanvas.CanvasBounds) – the area to compare with each item’s bounds.

  • inside_area (bool) – True if items inside area should be returned, or False if items outside area should be returned.

  • allow_overlaps (bool) – True if items which are partly inside and partly outside should be returned.

  • include_containers (bool) – True if containers should be checked as well as normal items.

Returns:

a list of items in the given area, or None if no items are found. The list should be freed with g_list_free().

Return type:

[GooCanvas.CanvasItem]

Gets a list of items inside or outside a given area.

get_root_item()
Returns:

the root item, or None if there is no root item.

Return type:

GooCanvas.CanvasItem

Gets the root item of the canvas, usually a GooCanvas.CanvasGroup.

get_root_item_model()
Returns:

the root item model, or None if there is no root item model.

Return type:

GooCanvas.CanvasItemModel

Gets the root item model of the canvas.

get_scale()
Returns:

the current scale setting.

Return type:

float

Gets the current scale of the canvas.

The scale specifies the magnification factor of the canvas, e.g. if an item has a width of 2 pixels and the scale is set to 3, it will be displayed with a width of 2 x 3 = 6 pixels.

get_static_root_item()
Returns:

the static root item, or None.

Return type:

GooCanvas.CanvasItem

Gets the static root item of the canvas.

Static items are exactly the same as ordinary canvas items, except that they do not move or change size when the canvas is scrolled or the scale changes.

Static items are added to the static root item in exactly the same way that ordinary items are added to the root item.

get_static_root_item_model()
Returns:

the static root item model, or None.

Return type:

GooCanvas.CanvasItemModel

Gets the static root item model of the canvas.

Static item models are exactly the same as ordinary item models, except that the corresponding items do not move or change size when the canvas is scrolled or the scale changes.

Static items models are added to the static root item model in exactly the same way that ordinary item models are added to the root item model.

grab_focus(item)
Parameters:

item (GooCanvas.CanvasItem) – the item to grab the focus.

Grabs the keyboard focus for the given item.

keyboard_grab(item, owner_events, time)
Parameters:
  • item (GooCanvas.CanvasItem) – the item to grab the keyboard for.

  • owner_events (bool) – True if keyboard events for this application will be reported normally, or False if all keyboard events will be reported with respect to the grab item.

  • time (int) – the time of the event that lead to the keyboard grab. This should come from the relevant Gdk.Event.

Returns:

Gdk.GrabStatus.SUCCESS if the grab succeeded.

Return type:

Gdk.GrabStatus

Attempts to grab the keyboard for the given item.

keyboard_ungrab(item, time)
Parameters:
  • item (GooCanvas.CanvasItem) – the item that has the keyboard grab.

  • time (int) – the time of the event that lead to the keyboard ungrab. This should come from the relevant Gdk.Event.

Ungrabs the keyboard, if the given item has the keyboard grab.

pointer_grab(item, event_mask, cursor, time)
Parameters:
  • item (GooCanvas.CanvasItem) – the item to grab the pointer for.

  • event_mask (Gdk.EventMask) – the events to receive during the grab.

  • cursor (Gdk.Cursor) – the cursor to display during the grab, or None.

  • time (int) – the time of the event that lead to the pointer grab. This should come from the relevant Gdk.Event.

Returns:

Gdk.GrabStatus.SUCCESS if the grab succeeded.

Return type:

Gdk.GrabStatus

Attempts to grab the pointer for the given item.

pointer_ungrab(item, time)
Parameters:
  • item (GooCanvas.CanvasItem) – the item that has the grab.

  • time (int) – the time of the event that lead to the pointer ungrab. This should come from the relevant Gdk.Event.

Ungrabs the pointer, if the given item has the pointer grab.

register_widget_item(witem)
Parameters:

witem (GooCanvas.CanvasWidget) – a GooCanvas.CanvasWidget item.

This function should only be used by GooCanvas.CanvasWidget and subclass implementations.

It registers a widget item with the canvas, so that the canvas can do the necessary actions to move and resize the widget as needed.

render(cr, bounds, scale)
Parameters:

Renders all or part of a canvas to the given cairo context.

This example code could be used in a Gtk.PrintOperation Gtk.PrintOperation ::draw-page callback to print each page in a multi-page document (assuming the pages appear one after the other vertically in the canvas). Note the call to cairo.Context.translate() to translate the output to the correct position on the printed page.

<informalexample><programlisting> GooCanvas.CanvasBounds bounds; bounds.x1 = 0; bounds.x2 = A4_PAGE_WIDTH; bounds.y1 = A4_PAGE_HEIGHT * page_num; bounds.y2 = A4_PAGE_HEIGHT * (page_num + 1);

cr = Gtk.PrintContext.get_cairo_context (print_context); cairo.Context.translate (cr, 0, -A4_PAGE_HEIGHT * page_num); GooCanvas.Canvas.render (GOO_CANVAS (canvas), cr, &bounds, 0.0); </programlisting></informalexample>

request_item_redraw(bounds, is_static)
Parameters:

This function is only intended to be used by subclasses of GooCanvas.Canvas or GooCanvas.CanvasItem implementations.

Requests that the given bounds be redrawn. If is_static is True the bounds are assumed to be in the static item coordinate space, otherwise they are assumed to be in the canvas coordinate space.

If is_static is False this function behaves the same as GooCanvas.Canvas.request_redraw().

request_redraw(bounds)
Parameters:

bounds (GooCanvas.CanvasBounds) – the bounds to redraw, in device space.

This function is only intended to be used by subclasses of GooCanvas.Canvas or GooCanvas.CanvasItem implementations.

Requests that the given bounds be redrawn. The bounds must be in the canvas coordinate space.

request_update()

This function is only intended to be used by subclasses of GooCanvas.Canvas or GooCanvas.CanvasItem implementations.

It schedules an update of the GooCanvas.Canvas. This will be performed in the idle loop, after all pending events have been handled, but before the canvas has been repainted.

scroll_to(left, top)
Parameters:
  • left (float) – the x coordinate to scroll to.

  • top (float) – the y coordinate to scroll to.

Scrolls the canvas, placing the given point as close to the top-left of the view as possible.

set_bounds(left, top, right, bottom)
Parameters:
  • left (float) – the left edge.

  • top (float) – the top edge.

  • right (float) – the right edge.

  • bottom (float) – the bottom edge.

Sets the bounds of the GooCanvas.Canvas, in canvas units.

By default, canvas units are pixels, though the GooCanvas.Canvas :units property can be used to change the units to points, inches or millimeters.

set_root_item(item)
Parameters:

item (GooCanvas.CanvasItem) – the root canvas item.

Sets the root item of the canvas. Any existing canvas items are removed.

set_root_item_model(model)
Parameters:

model (GooCanvas.CanvasItemModel) – a GooCanvas.CanvasItemModel.

Sets the root item model of the canvas.

A hierarchy of canvas items will be created, corresponding to the hierarchy of items in the model. Any current canvas items will be removed.

set_scale(scale)
Parameters:

scale (float) – the new scale setting.

Sets the scale of the canvas.

The scale specifies the magnification factor of the canvas, e.g. if an item has a width of 2 pixels and the scale is set to 3, it will be displayed with a width of 2 x 3 = 6 pixels.

set_static_root_item(item)
Parameters:

item (GooCanvas.CanvasItem) – the static root item.

Sets the static root item. Any existing static items are removed.

Static items are exactly the same as ordinary canvas items, except that they do not move or change size when the canvas is scrolled or the scale changes.

Static items are added to the static root item in exactly the same way that ordinary items are added to the root item.

set_static_root_item_model(model)
Parameters:

model (GooCanvas.CanvasItemModel) – the static root item model.

Sets the static root item model. Any existing static item models are removed.

Static item models are exactly the same as ordinary item models, except that the corresponding items do not move or change size when the canvas is scrolled or the scale changes.

Static items models are added to the static root item model in exactly the same way that ordinary item models are added to the root item model.

unregister_item(model)
Parameters:

model (GooCanvas.CanvasItemModel) – the item model whose canvas item is being finalized.

This function is only intended to be used when implementing new canvas items.

It should be called in the finalize method of GooCanvas.CanvasItem objects, to remove the canvas item from the GooCanvas.Canvas's hash table.

unregister_widget_item(witem)
Parameters:

witem (GooCanvas.CanvasWidget) – a GooCanvas.CanvasWidget item.

This function should only be used by GooCanvas.CanvasWidget and subclass implementations.

It unregisters a widget item from the canvas, when the item is no longer in the canvas.

update()

This function is only intended to be used by subclasses of GooCanvas.Canvas or GooCanvas.CanvasItem implementations.

It updates any items that need updating.

If the bounds of items change, they will request a redraw of the old and new bounds so the display is updated correctly.

do_create_item(model) virtual
Parameters:

model (GooCanvas.CanvasItemModel) – the item model to create a canvas item for.

Returns:

a new canvas item.

Return type:

GooCanvas.CanvasItem

This function is only intended to be used when implementing new canvas items, typically container items such as GooCanvas.CanvasGroup.

It creates a new canvas item for the given item model, and recursively creates items for any children.

It uses the create_item() virtual method if it has been set. Subclasses of GooCanvas.Canvas can define this method if they want to use custom views for items.

It emits the GooCanvas.Canvas ::item-created signal after creating the view, so application code can connect signal handlers to the new view if desired.

do_item_created(item, model) virtual
Parameters:

Signal Details

GooCanvas.Canvas.signals.item_created(canvas, item, model)
Signal Name:

item-created

Flags:

RUN_LAST

Parameters:

This is emitted when a new canvas item is created, in model/view mode.

Applications can set up signal handlers for the new items here.

Property Details

GooCanvas.Canvas.props.anchor
Name:

anchor

Type:

GooCanvas.CanvasAnchorType

Default Value:

GooCanvas.CanvasAnchorType.NORTH_WEST

Flags:

READABLE, WRITABLE

Where to place the canvas when it is smaller than the widget’s allocated area

GooCanvas.Canvas.props.automatic_bounds
Name:

automatic-bounds

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

If the bounds are automatically calculated based on the bounds of all the items in the canvas

GooCanvas.Canvas.props.background_color
Name:

background-color

Type:

str

Default Value:

None

Flags:

WRITABLE

The color to use for the canvas background

GooCanvas.Canvas.props.background_color_gdk_rgba
Name:

background-color-gdk-rgba

Type:

Gdk.RGBA

Default Value:

None

Flags:

WRITABLE

The color to use for the canvas background, specified as a Gdk.RGBA.

New in version 2.0.1.

GooCanvas.Canvas.props.background_color_rgb
Name:

background-color-rgb

Type:

int

Default Value:

0

Flags:

WRITABLE

The color to use for the canvas background, specified as a 24-bit integer value, 0xRRGGBB

GooCanvas.Canvas.props.bounds_from_origin
Name:

bounds-from-origin

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

If the automatic bounds are calculated from the origin

GooCanvas.Canvas.props.bounds_padding
Name:

bounds-padding

Type:

float

Default Value:

0.0

Flags:

READABLE, WRITABLE

The padding added to the automatic bounds

GooCanvas.Canvas.props.clear_background
Name:

clear-background

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

If the background is cleared before the canvas is painted

GooCanvas.Canvas.props.integer_layout
Name:

integer-layout

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

If all item layout is done to the nearest integer

GooCanvas.Canvas.props.redraw_when_scrolled
Name:

redraw-when-scrolled

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

If the canvas is completely redrawn when scrolled, to reduce the flicker of static items. Note that since GTK+ 3.0 the canvas is always redrawn when scrolled, so this option has no effect.

GooCanvas.Canvas.props.resolution_x
Name:

resolution-x

Type:

float

Default Value:

96.0

Flags:

READABLE, WRITABLE

The horizontal resolution of the display, in dots per inch

GooCanvas.Canvas.props.resolution_y
Name:

resolution-y

Type:

float

Default Value:

96.0

Flags:

READABLE, WRITABLE

The vertical resolution of the display, in dots per inch

GooCanvas.Canvas.props.scale
Name:

scale

Type:

float

Default Value:

1.0

Flags:

READABLE, WRITABLE

The magnification factor of the canvas

GooCanvas.Canvas.props.scale_x
Name:

scale-x

Type:

float

Default Value:

1.0

Flags:

READABLE, WRITABLE

The horizontal magnification factor of the canvas

GooCanvas.Canvas.props.scale_y
Name:

scale-y

Type:

float

Default Value:

1.0

Flags:

READABLE, WRITABLE

The vertical magnification factor of the canvas

GooCanvas.Canvas.props.units
Name:

units

Type:

Gtk.Unit

Default Value:

Gtk.Unit.NONE

Flags:

READABLE, WRITABLE

The units to use for the canvas

GooCanvas.Canvas.props.x1
Name:

x1

Type:

float

Default Value:

0.0

Flags:

READABLE, WRITABLE

The x coordinate of the left edge of the canvas bounds, in canvas units

GooCanvas.Canvas.props.x2
Name:

x2

Type:

float

Default Value:

1000.0

Flags:

READABLE, WRITABLE

The x coordinate of the right edge of the canvas bounds, in canvas units

GooCanvas.Canvas.props.y1
Name:

y1

Type:

float

Default Value:

0.0

Flags:

READABLE, WRITABLE

The y coordinate of the top edge of the canvas bounds, in canvas units

GooCanvas.Canvas.props.y2
Name:

y2

Type:

float

Default Value:

1000.0

Flags:

READABLE, WRITABLE

The y coordinate of the bottom edge of the canvas bounds, in canvas units