class View(Container, ViewBase, Printable)

Class View is a general-purpose component for displaying 2D graphics and handling mouse and keyboard input. It also provides special support for being an observer of one or more Models.

This page documents properties and methods concerned with drawing. See ViewBase for information about input handling and model observation.

Abstract methods

draw(canvas, update_rect)
Called when some or all of the view needs to be drawn. The canvas parameter is an object of class Canvas upon which the drawing should be done. The update_rect is the rectangle in the view's coordinate system that needs drawing.

You can use the update_rect to improve efficiency by only drawing parts of the view that lie within it, although this is optional. Drawing will be clipped to the update_rect in any case.

The printing property of the canvas can be used to determine whether to draw features, such as selection highlighting, that should only appear on the screen and not on a printed page.

Note: The canvas is only valid for the duration of this call and should not be retained beyond it. To draw into the view at other times, use the with_canvas method.

resized((dw, dh))
Called whenever the size of the view changes as a result of the user resizing the containing window.

container_resized((dw, dh))
Called whenever the view's container changes size as a result of the user resizing the containing window. The default implementation of this method adjusts the position and size of this component according to the settings of its resizing attributes.

Methods

viewed_rect()
Returns the viewed rectangle, i.e. the rectangle in local coordinates that is currently visible in the view.

invalidate()
Marks the whole viewed rectangle as needing to be redrawn.
 
invalidate_rect(rect)
Mark the given rectangle, in local coordinates, as needing to be redrawn.
update()
Causes invalidated areas to be redrawn immediately, without waiting for a return to the event loop.

with_canvas(function)
The function should be a callable object expecting one parameter. The function is called with a Canvas instance for drawing in the view. The canvas is only valid for the duration of the call and should not be retained beyond it.
 
local_to_global(p)
Transforms the given point from the view's local coordinate system to screen coordinates.

global_to_local(p)
Transforms the given point from screen coordinates to the view's local coordinate system.

local_to_container(p)
Transforms the given point from the view's local coordinate system to its container's local coordinate system.

container_to_local(p)
Transforms the given point from the view's container's local coordinate system to the view's local coordinate system.

---