#
#		Python GUI - Pixmaps - Cocoa
#

from Foundation import NSSize
from AppKit import NSImage, NSCachedImageRep
from Canvases import Canvas
from GPixmaps import Pixmap as GPixmap

class Pixmap(GPixmap):
    #  _ns_rep   NSCachedImageRep

    def __init__(self, width, height):
        GPixmap.__init__(self)
        ns_size = NSSize(width, height)
        ns_image = NSImage.alloc().initWithSize_(ns_size)
        ns_rep = NSCachedImageRep.alloc().initWithSize_depth_separate_alpha_(
            ns_size, 0, True, True)
        ns_image.addRepresentation_(ns_rep)
        self._init_with_ns_image(ns_image, flipped = False)
        self._ns_rep = ns_rep
    
    def with_canvas(self, proc):
        canvas = Canvas()
        ns_image = self._ns_image
        ns_image.lockFocus()
        try:
            proc(canvas)
        finally:
            ns_image.unlockFocus()
