#
#		Python GUI - Views - Generic
#

from Properties import overridable_property
from Geometry import add_pt, sub_pt, rect_sized
from Containers import Container
from ViewBases import ViewBase

default_size = (100, 100)

class View(ViewBase, Container):
    """A View is a 2D drawing area having its own coordinate
    system and clipping area, with support for scrolling."""

    #
    #		Construction and destruction
    #

    def __init__(self, **kwds):
        Container.__init__(self, **kwds)
        ViewBase.__init__(self)
    
    def destroy(self):
        ViewBase.destroy(self)
        Container.destroy(self)
    
    #
    #		Other methods
    #

    def viewed_rect(self):
        """Return the rectangle in local coordinates bounding the currently
        visible part of the extent."""
        return rect_sized((0, 0), self.size)
    
    def with_canvas(self, proc):
        """Call the procedure with a canvas suitable for drawing in this
        view. The canvas is only valid for the duration of the call, and
        should not be retained beyond it."""
        raise NotImplementedError
    
    def update(self):
        """Redraw invalidated regions immediately, without waiting for a
        return to the event loop."""
        raise NotImplementedError

    #
    #		Callbacks
    #

    def draw(self, canvas, rect):
        """Called when the view needs to be drawn. The rect is the bounding
        rectangle of the region needing to be drawn. The default implementation
        does nothing."""
        pass

