#
#		Python GUI - Pixmaps - Mac
#

from Carbon import Qd, Qdoffs
from Canvases import Canvas
from GPixmaps import Pixmap as GPixmap
from MacGWorlds import MacGWorld

class Pixmap(MacGWorld, GPixmap):

    def __init__(self, width, height):
        self._mac_init_gworld((0, 0, width, height))
    
    def with_canvas(self, proc):
        old_port, old_dev = self._mac_set_gworld()
        try:
            clip = Qd.NewRgn()
            Qd.RectRgn(clip, self.bounds)
            canvas = Canvas(clip)
            canvas.initgraphics()
            proc(canvas)
        finally:
            Qdoffs.SetGWorld(old_port, old_dev)
