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