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