home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Tools / IDE / Wquicktime.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  2.7 KB  |  120 lines

  1. import os
  2. import Qd
  3. import Win
  4. import Qt, QuickTime
  5. import W
  6. import macfs
  7. import Evt, Events
  8.  
  9. _moviesinitialized = 0
  10.  
  11. def EnterMovies():
  12.     global _moviesinitialized
  13.     if not _moviesinitialized:
  14.         Qt.EnterMovies()
  15.         _moviesinitialized = 1
  16.  
  17. class Movie(W.Widget):
  18.     
  19.     def __init__(self, possize):
  20.         EnterMovies()
  21.         self.movie = None
  22.         self.running = 0
  23.         W.Widget.__init__(self, possize)
  24.     
  25.     def adjust(self, oldbounds):
  26.         self.SetPort()
  27.         Win.InvalRect(oldbounds)
  28.         Win.InvalRect(self._bounds)
  29.         self.calcmoviebox()
  30.     
  31.     def set(self, path_or_fss, start = 0):
  32.         self.SetPort()
  33.         if self.movie:
  34.             #Win.InvalRect(self.movie.GetMovieBox())
  35.             Qd.PaintRect(self.movie.GetMovieBox())
  36.         if type(path_or_fss) == type(''):
  37.             path = path_or_fss
  38.             fss = macfs.FSSpec(path)
  39.         else:
  40.             path = path_or_fss.as_pathname()
  41.             fss = path_or_fss
  42.         self.movietitle = os.path.basename(path)
  43.         movieResRef = Qt.OpenMovieFile(fss, 1)
  44.         self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
  45.         self.moviebox = self.movie.GetMovieBox()
  46.         self.calcmoviebox()
  47.         Qd.ObscureCursor()    # XXX does this work at all?
  48.         self.movie.GoToBeginningOfMovie()
  49.         if start:
  50.             self.movie.StartMovie()
  51.             self.running = 1
  52.         else:
  53.             self.running = 0
  54.             self.movie.MoviesTask(0)
  55.     
  56.     def get(self):
  57.         return self.movie
  58.     
  59.     def getmovietitle(self):
  60.         return self.movietitle
  61.     
  62.     def start(self):
  63.         if self.movie:
  64.             Qd.ObscureCursor()
  65.             self.movie.StartMovie()
  66.             self.running = 1
  67.     
  68.     def stop(self):
  69.         if self.movie:
  70.             self.movie.StopMovie()
  71.             self.running = 0
  72.     
  73.     def rewind(self):
  74.         if self.movie:
  75.             self.movie.GoToBeginningOfMovie()
  76.     
  77.     def calcmoviebox(self):
  78.         if not self.movie:
  79.             return
  80.         ml, mt, mr, mb = self.moviebox
  81.         wl, wt, wr, wb = widgetbox = self._bounds
  82.         mheight = mb - mt
  83.         mwidth = mr - ml
  84.         wheight = wb - wt
  85.         wwidth = wr - wl
  86.         if (mheight * 2 < wheight) and (mwidth * 2 < wwidth):
  87.             scale = 2
  88.         elif mheight > wheight or mwidth > wwidth:
  89.             scale = min(float(wheight) / mheight, float(wwidth) / mwidth)
  90.         else:
  91.             scale = 1
  92.         mwidth, mheight = mwidth * scale, mheight * scale
  93.         ml, mt = wl + (wwidth - mwidth) / 2, wt + (wheight - mheight) / 2
  94.         mr, mb = ml + mwidth, mt + mheight
  95.         self.movie.SetMovieBox((ml, mt, mr, mb))
  96.     
  97.     def idle(self, *args):
  98.         if self.movie:
  99.             if not self.movie.IsMovieDone() and self.running:
  100.                 Qd.ObscureCursor()
  101.                 while 1:
  102.                     self.movie.MoviesTask(0)
  103.                     gotone, event = Evt.EventAvail(Events.everyEvent)
  104.                     if gotone or self.movie.IsMovieDone():
  105.                         break
  106.             elif self.running:
  107.                 box = self.movie.GetMovieBox()
  108.                 self.SetPort()
  109.                 Win.InvalRect(box)
  110.                 self.movie = None
  111.                 self.running = 0
  112.     
  113.     def draw(self, visRgn = None):
  114.         if self._visible:
  115.             Qd.PaintRect(self._bounds)
  116.             if self.movie:
  117.                 self.movie.UpdateMovie()
  118.                 self.movie.MoviesTask(0)
  119.  
  120.