#
#		Python GUI - Images - Mac
#

from Carbon import QuickDraw, Qd, Qdoffs, Qt
from Carbon.File import FSSpec
from Carbon.Files import fsRdPerm
from Geometry import rect_size
from GImages import Image as GImage
from MacGWorlds import MacGWorld

class Image(MacGWorld, GImage):

    def _init_from_file(self, file):
        refnum = Qt.OpenMovieFile(FSSpec(file), fsRdPerm)
        try:
            movie = Qt.NewMovieFromFile(refnum, 0, 0)[0]
            bounds = Qd.GetRegionBounds(movie.GetMovieBoundsRgn())
            gworld = self._mac_init_gworld(bounds)
            pict = movie.GetMoviePict(0)
            try:
                old_port, old_dev = self._mac_set_gworld()
                Qd.DrawPicture(pict, bounds)
            finally:
                Qdoffs.SetGWorld(old_port, old_dev)
        finally:
            Qt.CloseMovieFile(refnum)


Qt.EnterMovies()
