/Mac/Demo/quicktime/MovieInWindow.py

http://unladen-swallow.googlecode.com/ · Python · 70 lines · 38 code · 15 blank · 17 comment · 6 complexity · 59545ab383ca19b7553be063accddf60 MD5 · raw file

  1. """MovieInWindow converted to python
  2. Jack Jansen, CWI, December 1995
  3. """
  4. from Carbon import Qt
  5. from Carbon import QuickTime
  6. from Carbon import Qd
  7. from Carbon import QuickDraw
  8. from Carbon import Evt
  9. from Carbon import Events
  10. from Carbon import Win
  11. from Carbon import Windows
  12. from Carbon import File
  13. import EasyDialogs
  14. import sys
  15. import os
  16. def main():
  17. # skip the toolbox initializations, already done
  18. # XXXX Should use gestalt here to check for quicktime version
  19. Qt.EnterMovies()
  20. # Get the movie file
  21. if len(sys.argv) > 1:
  22. filename = sys.argv[1]
  23. else:
  24. filename = EasyDialogs.AskFileForOpen() # Was: QuickTime.MovieFileType
  25. if not filename:
  26. sys.exit(0)
  27. # Open the window
  28. bounds = (175, 75, 175+160, 75+120)
  29. theWindow = Win.NewCWindow(bounds, os.path.split(filename)[1], 1, 0, -1, 0, 0)
  30. Qd.SetPort(theWindow)
  31. # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
  32. playMovieInWindow(theWindow, filename, theWindow.GetWindowPort().GetPortBounds())
  33. def playMovieInWindow(theWindow, theFile, movieBox):
  34. """Play a movie in a window"""
  35. # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil);
  36. # Get the movie
  37. theMovie = loadMovie(theFile)
  38. # Set where we want it
  39. theMovie.SetMovieBox(movieBox)
  40. # Start at the beginning
  41. theMovie.GoToBeginningOfMovie()
  42. # Give a little time to preroll
  43. theMovie.MoviesTask(0)
  44. # Start playing
  45. theMovie.StartMovie()
  46. while not theMovie.IsMovieDone() and not Evt.Button():
  47. theMovie.MoviesTask(0)
  48. def loadMovie(theFile):
  49. """Load a movie given an fsspec. Return the movie object"""
  50. movieResRef = Qt.OpenMovieFile(theFile, 1)
  51. movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
  52. return movie
  53. if __name__ == '__main__':
  54. main()