class View(Frame, ViewBase)

Class View is an abstract base class providing a general-purpose component for displaying 2D graphics and handling mouse and keyboard input. It supports scrolling (so it can be used as a client of a ScrollFrame), and 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.

Properties

extent
Rectangle in local coordinates defining the limits of scrolling.

scroll_offset
Tuple (dx, dy) representing the difference in local coordinates between the top left corner of the view's bounds and the top left corner of the extent. Assigning to this property will cause the view to scroll. The value is clamped to the allowable scrolling range, as determined by the current bounds and extent.

line_scroll_amount
Tuple (dh, dv) representing the size of a "line" in each direction for scrolling purposes.

Abstract methods

draw(canvas)
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 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.

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.
 
set_cursor(name)
Sets the appearance that the mouse pointer will have when it is within this object. The name is a string which identifies a cursor in some way yet to be determined. [NOT YET IMPLEMENTED]

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.

scroll_by(dx, dy)
Scrolls the view by the given horizontal and vertical amounts, within the limits defined by the extent.

scroll_line_left()
scroll_line_right()
scroll_line_up()
scroll_line_down()
Scrolls the view by one line in the specified direction, as determined by the line_scroll_amount property.

scroll_page_left()
scroll_page_right()
scroll_page_up()
scroll_page_down()
Scrolls the view by one page in the specified direction. The size of a page is equal to the size of the viewed rectangle minus the line_scroll_amount.
---